Struct ProductVariation

Source
pub struct ProductVariation {
Show 39 fields pub id: i32, pub date_created: NaiveDateTime, pub date_created_gmt: NaiveDateTime, pub date_modified: NaiveDateTime, pub date_modified_gmt: NaiveDateTime, pub description: String, pub permalink: String, pub sku: String, pub price: String, pub regular_price: String, pub sale_price: String, pub date_on_sale_from: Option<NaiveDateTime>, pub date_on_sale_from_gmt: Option<NaiveDateTime>, pub date_on_sale_to: Option<NaiveDateTime>, pub date_on_sale_to_gmt: Option<NaiveDateTime>, pub on_sale: bool, pub status: ProductStatus, pub purchasable: bool, pub is_virtual: bool, pub downloadable: bool, pub downloads: Vec<Download>, pub download_limit: i32, pub download_expiry: i32, pub tax_status: TaxStatus, pub tax_class: String, pub manage_stock: ManageStock, pub stock_quantity: Option<i32>, pub stock_status: StockStatus, pub backorders: BackordersStatus, pub backorders_allowed: bool, pub backordered: bool, pub weight: String, pub dimensions: Dimensions, pub shipping_class: String, pub shipping_class_id: i32, pub image: Option<ProductImage>, pub attributes: Vec<ProductDefaultAttribute>, pub menu_order: i32, pub meta_data: Vec<MetaData>,
}

Fields§

§id: i32

Unique identifier for the resource.

§date_created: NaiveDateTime

The date the variation was created, in the site’s timezone.

§date_created_gmt: NaiveDateTime

The date the variation was created, as GMT.

§date_modified: NaiveDateTime

The date the variation was last modified, in the site’s timezone.

§date_modified_gmt: NaiveDateTime

The date the variation was last modified, as GMT.

§description: String

Variation description.

§permalink: String

Variation URL.

§sku: String

Unique identifier.

§price: String

Current variation price.

§regular_price: String

Variation regular price.

§sale_price: String

Variation sale price.

§date_on_sale_from: Option<NaiveDateTime>

Start date of sale price, in the site’s timezone.

§date_on_sale_from_gmt: Option<NaiveDateTime>

Start date of sale price, as GMT.

§date_on_sale_to: Option<NaiveDateTime>

End date of sale price, in the site’s timezone.

§date_on_sale_to_gmt: Option<NaiveDateTime>

End date of sale price, as GMT.

§on_sale: bool

Shows if the variation is on sale. READ-ONLY

§status: ProductStatus

Variation status. Options: draft, pending, private and publish. Default is publish.

§purchasable: bool

Shows if the variation can be bought.

§is_virtual: bool

If the variation is virtual. Default is false.

§downloadable: bool

If the variation is downloadable. Default is false.

§downloads: Vec<Download>

List of downloadable files.

§download_limit: i32

Number of times downloadable files can be downloaded after purchase. Default is -1.

§download_expiry: i32

Number of days until access to downloadable files expires. Default is -1.

§tax_status: TaxStatus

Tax status. Options: taxable, shipping and none. Default is taxable.

§tax_class: String

Tax class.

§manage_stock: ManageStock

Stock management at variation level. Default is false.

§stock_quantity: Option<i32>

Stock quantity.

§stock_status: StockStatus

Controls the stock status of the product. Options: instock, outofstock, onbackorder. Default is instock.

§backorders: BackordersStatus

If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no.

§backorders_allowed: bool

Shows if backorders are allowed.

§backordered: bool

Shows if the variation is on backordered.

§weight: String

Variation weight.

§dimensions: Dimensions

Variation dimensions. See Product variation - Dimensions properties

§shipping_class: String

Shipping class slug.

§shipping_class_id: i32

Shipping class ID.

§image: Option<ProductImage>

Variation image data.

§attributes: Vec<ProductDefaultAttribute>

List of attributes.

§menu_order: i32

Menu order, used to custom sort products.

§meta_data: Vec<MetaData>

Meta data.

Implementations§

Source§

impl ProductVariation

Source

pub fn builder() -> ProductVariationModifyBuilder

Examples found in repository?
examples/variation.rs (line 59)
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 ProductVariation

Source§

fn clone(&self) -> ProductVariation

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 ProductVariation

Source§

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

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

impl<'de> Deserialize<'de> for ProductVariation

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 ProductVariation

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,