Struct Attribute

Source
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

Source

pub fn create() -> AttributeCreateBuilder<NoName>

Source

pub fn update() -> AttributeUpdateBuilder

Source

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
Hide additional 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 Clone for Attribute

Source§

fn clone(&self) -> Attribute

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Attribute

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Attribute

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for Attribute

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> ErasedDestructor for T
where T: 'static,