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)
6async fn main() -> Result<()> {
7 tracing_subscriber::fmt::init();
8 let config = Config::new("woo.toml")?;
9 let client = ApiClient::new(&config)?;
10 let start = std::time::Instant::now();
11 let products = client.list_all::<Product>().await?;
12 info!(
13 "Got {} products in {} seconds",
14 products.len(),
15 start.elapsed().as_secs()
16 );
17 let random_id = products.first().map(|p| p.id).unwrap_or_default();
18 let retrieved = client.retrieve::<Product>(random_id).await?;
19 info!("Retrieved product has sku: {}", retrieved.sku);
20 let attribute = Attribute::builder()
21 .name("Test Attribute")
22 .option("Best")
23 .visible()
24 .build();
25 let new_product = Product::builder()
26 .name("Test Product For Example")
27 .featured()
28 .short_description("The most professional description")
29 .sku("product for test 42")
30 .regular_price("6969")
31 .manage_stock()
32 .stock_quantity(42)
33 .weight("50")
34 .dimensions("4", "3", "2")
35 .shipping_class("large")
36 .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
37 .attribute(attribute)
38 .build();
39 let batch_create = vec![new_product.clone()];
40 let created: Product = client.create(new_product).await?;
41 info!("Create product {} with id: {}", created.name, created.id);
42 let update = Product::builder().unfeatured().build();
43 let updated: Product = client.update(created.id, update).await?;
44 info!(
45 "Update product {}, new feature is {}",
46 updated.name, updated.featured
47 );
48 let deleted: Product = client.delete(updated.id).await?;
49 info!("Product {} deleted", deleted.name);
50 let batch_created: Vec<Product> = client.batch_create(batch_create).await?;
51 let id = batch_created.first().ok_or(anyhow!("Error"))?.id;
52 let batch_update = Product::builder().id(id).unfeatured().build();
53 let _batch_updated: Vec<Product> = client.batch_update(vec![batch_update]).await?;
54 let _deleted: Product = client.delete(id).await?;
55 Ok(())
56}
More examples
examples/variation.rs (line 34)
10async fn main() -> Result<()> {
11 tracing_subscriber::fmt::init();
12 let config = Config::new("woo.toml")?;
13 let client = ApiClient::new(&config)?;
14 let products = client.list_all::<Product>().await?;
15 let random_variable_id = products
16 .iter()
17 .find(|p| !p.variations.is_empty())
18 .map(|p| p.id)
19 .unwrap_or_default();
20 let variations = client
21 .list_all_subentities::<ProductVariation>(random_variable_id)
22 .await?;
23 info!(
24 "Got {} variations for product with id: {random_variable_id}",
25 variations.len()
26 );
27 let retrieved_variation: ProductVariation = client
28 .retrieve_subentity(
29 random_variable_id,
30 variations.first().map(|v| v.id).unwrap_or_default(),
31 )
32 .await?;
33 info!("Retrieved variation has sku: {}", retrieved_variation.sku);
34 let attribute = Attribute::builder()
35 .name("Test Attribute")
36 .option("Best")
37 .option("Test")
38 .variation()
39 .visible()
40 .build();
41 let new_variable_product = Product::builder()
42 .name("Test Product For Example")
43 .product_type(ProductType::Variable)
44 .featured()
45 .short_description("The most professional description")
46 .sku("product for test 42")
47 .regular_price("6969")
48 .manage_stock()
49 .stock_quantity(42)
50 .weight("50")
51 .dimensions("4", "3", "2")
52 .shipping_class("large")
53 .images("https://cs14.pikabu.ru/post_img/2021/06/27/7/1624794514137159585.jpg")
54 .attribute(attribute)
55 .build();
56 let created: Product = client.create(new_variable_product).await?;
57 info!("Create product {} with id: {}", created.name, created.id);
58
59 let variation = ProductVariation::builder()
60 .sku(format!("{} Best", created.sku))
61 .regular_price("6969")
62 .manage_stock()
63 .stock_quantity(96)
64 .weight("52")
65 .dimensions("5", "4", "3")
66 .attribute(None, "Test Attribute", "Best")
67 .build();
68 let batch_create_variation = vec![variation.clone()];
69 let created_variation: ProductVariation =
70 client.create_subentity(created.id, variation).await?;
71 info!(
72 "Variation {} created with price: {}",
73 created_variation.sku, created_variation.price
74 );
75 let update = ProductVariation::builder().regular_price("7000").build();
76 let updated_variation: ProductVariation = client
77 .update_subentity(created.id, created_variation.id, update)
78 .await?;
79 info!(
80 "Variation {} updated with price: {}",
81 updated_variation.sku, updated_variation.price
82 );
83 let deleted_variation: ProductVariation = client
84 .delete_subentity(created.id, updated_variation.id)
85 .await?;
86 info!("Variation {} deleted", deleted_variation.sku);
87 let batch_created_variation: Vec<ProductVariation> = client
88 .batch_create_subentity(created.id, batch_create_variation)
89 .await?;
90 let bcv_id = batch_created_variation
91 .first()
92 .map(|v| v.id)
93 .unwrap_or_default();
94 let batch_update_variation = vec![ProductVariation::builder()
95 .id(bcv_id)
96 .regular_price("777")
97 .build()];
98 let _batch_updated_variation: Vec<ProductVariation> = client
99 .batch_update_subentity(created.id, batch_update_variation)
100 .await?;
101 let _batch_deleted_variation: Vec<ProductVariation> = client
102 .batch_delete_subentity(created.id, vec![bcv_id])
103 .await?;
104 let deleted: Product = client.delete(created.id).await?;
105 info!("Product {} deleted", deleted.name);
106 Ok(())
107}
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