pub struct Attribute {
pub id: i32,
pub name: String,
pub slug: String,
pub attribute_type: AttributeType,
pub order_by: AttributeSortOrder,
pub has_archives: bool,
}
Expand description
Product attribute properties
Fields§
§id: i32
Unique identifier for the resource.
name: String
Attribute name.
slug: String
An alphanumeric identifier for the resource unique to its type.
attribute_type: AttributeType
Type of attribute. By default, only select is supported.
order_by: AttributeSortOrder
Default sort order. Options: menu_order, name, name_num and id. Default is menu_order.
has_archives: bool
Enable/Disable attribute archives. Default is false.
Implementations§
Source§impl Attribute
impl Attribute
pub fn create() -> AttributeCreateBuilder<NoName>
pub fn update() -> AttributeUpdateBuilder
Sourcepub fn builder() -> AttributeDTOBuilder<NoName, NoOptions>
pub fn builder() -> AttributeDTOBuilder<NoName, NoOptions>
Examples found in repository?
examples/product.rs (line 20)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let config = Config::new("woo.toml")?;
let client = ApiClient::new(&config)?;
let start = std::time::Instant::now();
let products = client.list_all::<Product>().await?;
info!(
"Got {} products in {} seconds",
products.len(),
start.elapsed().as_secs()
);
let random_id = products.first().map(|p| p.id).unwrap_or_default();
let retrieved = client.retrieve::<Product>(random_id).await?;
info!("Retrieved product has sku: {}", retrieved.sku);
let attribute = Attribute::builder()
.name("Test Attribute")
.option("Best")
.visible()
.build();
let new_product = Product::builder()
.name("Test Product For Example")
.featured()
.short_description("The most professional description")
.sku("product for test 42")
.regular_price("6969")
.manage_stock()
.stock_quantity(42)
.weight("50")
.dimensions("4", "3", "2")
.shipping_class("large")
.images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
.attribute(attribute)
.build();
let batch_create = vec![new_product.clone()];
let created: Product = client.create(new_product).await?;
info!("Create product {} with id: {}", created.name, created.id);
let update = Product::builder().unfeatured().build();
let updated: Product = client.update(created.id, update).await?;
info!(
"Update product {}, new feature is {}",
updated.name, updated.featured
);
let deleted: Product = client.delete(updated.id).await?;
info!("Product {} deleted", deleted.name);
let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
let batch_update = Product::builder().id(id).unfeatured().build();
let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
let _deleted: Product = client.delete(id).await?;
Ok(())
}
More examples
examples/variation.rs (line 34)
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
async fn main() -> Result<()> {
tracing_subscriber::fmt::init();
let config = Config::new("woo.toml")?;
let client = ApiClient::new(&config)?;
let products = client.list_all::<Product>().await?;
let random_variable_id = products
.iter()
.find(|p| !p.variations.is_empty())
.map(|p| p.id)
.unwrap_or_default();
let variations = client
.list_all_subentities::<ProductVariation>(random_variable_id)
.await?;
info!(
"Got {} variations for product with id: {random_variable_id}",
variations.len()
);
let retrieved_variation: ProductVariation = client
.retrieve_subentity(
random_variable_id,
variations.first().map(|v| v.id).unwrap_or_default(),
)
.await?;
info!("Retrieved variation has sku: {}", retrieved_variation.sku);
let attribute = Attribute::builder()
.name("Test Attribute")
.option("Best")
.option("Test")
.variation()
.visible()
.build();
let new_variable_product = Product::builder()
.name("Test Product For Example")
.product_type(ProductType::Variable)
.featured()
.short_description("The most professional description")
.sku("product for test 42")
.regular_price("6969")
.manage_stock()
.stock_quantity(42)
.weight("50")
.dimensions("4", "3", "2")
.shipping_class("large")
.images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
.attribute(attribute)
.build();
let created: Product = client.create(new_variable_product).await?;
info!("Create product {} with id: {}", created.name, created.id);
let variation = ProductVariation::builder()
.sku(format!("{} Best", created.sku))
.regular_price("6969")
.manage_stock()
.stock_quantity(96)
.weight("52")
.dimensions("5", "4", "3")
.attribute(None, "Test Attribute", "Best")
.build();
let batch_create_variation = vec![variation.clone()];
let created_variation: ProductVariation =
client.create_subentity(created.id, variation).await?;
info!(
"Variation {} created with price: {}",
created_variation.sku, created_variation.price
);
let update = ProductVariation::builder().regular_price("7000").build();
let updated_variation: ProductVariation = client
.update_subentity(created.id, created_variation.id, update)
.await?;
info!(
"Variation {} updated with price: {}",
updated_variation.sku, updated_variation.price
);
let deleted_variation: ProductVariation = client
.delete_subentity(created.id, updated_variation.id)
.await?;
info!("Variation {} deleted", deleted_variation.sku);
let batch_created_variation: Vec<ProductVariation> = client
.batch_create_subentity(created.id, batch_create_variation)
.await?;
let bcv_id = batch_created_variation
.first()
.map(|v| v.id)
.unwrap_or_default();
let batch_update_variation = vec![ProductVariation::builder()
.id(bcv_id)
.regular_price("777")
.build()];
let _batch_updated_variation: Vec<ProductVariation> = client
.batch_update_subentity(created.id, batch_update_variation)
.await?;
let _batch_deleted_variation: Vec<ProductVariation> = client
.batch_delete_subentity(created.id, vec![bcv_id])
.await?;
let deleted: Product = client.delete(created.id).await?;
info!("Product {} deleted", deleted.name);
Ok(())
}
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Attribute
impl<'de> Deserialize<'de> for Attribute
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Attribute
impl RefUnwindSafe for Attribute
impl Send for Attribute
impl Sync for Attribute
impl Unpin for Attribute
impl UnwindSafe for Attribute
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more