Struct Product

Source
pub struct Product {
Show 65 fields pub id: i32, pub name: String, pub slug: String, pub permalink: String, pub date_created: NaiveDateTime, pub date_created_gmt: NaiveDateTime, pub date_modified: NaiveDateTime, pub date_modified_gmt: NaiveDateTime, pub product_type: ProductType, pub status: ProductStatus, pub featured: bool, pub catalog_visibility: CatalogVisibility, pub description: String, pub short_description: 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 price_html: String, pub on_sale: bool, pub purchasable: bool, pub total_sales: i32, pub is_virtual: bool, pub downloadable: bool, pub downloads: Vec<Download>, pub download_limit: i32, pub download_expiry: i32, pub external_url: String, pub button_text: String, pub tax_status: TaxStatus, pub tax_class: String, pub manage_stock: bool, pub stock_quantity: Option<i32>, pub stock_status: StockStatus, pub backorders: BackordersStatus, pub backorders_allowed: bool, pub backordered: bool, pub sold_individually: bool, pub weight: String, pub dimensions: Dimensions, pub shipping_required: bool, pub shipping_taxable: bool, pub shipping_class: String, pub shipping_class_id: i32, pub reviews_allowed: bool, pub average_rating: String, pub rating_count: i32, pub related_ids: Vec<i32>, pub upsell_ids: Vec<i32>, pub cross_sell_ids: Vec<i32>, pub parent_id: i32, pub purchase_note: String, pub categories: Vec<ProductCategory>, pub tags: Vec<ProductTag>, pub images: Vec<ProductImage>, pub attributes: Vec<ProductAttribute>, pub default_attributes: Vec<ProductDefaultAttribute>, pub variations: Vec<i32>, pub grouped_products: Vec<i32>, pub menu_order: i32, pub meta_data: Vec<MetaData>,
}

Fields§

§id: i32

Unique identifier for the resource.

§name: String

Product name.

§slug: String

Product slug.

§permalink: String

Product URL.

§date_created: NaiveDateTime

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

§date_created_gmt: NaiveDateTime

The date the product was created, as GMT.

§date_modified: NaiveDateTime

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

§date_modified_gmt: NaiveDateTime

The date the product was last modified, as GMT.

§product_type: ProductType

Product type, Options: simple, grouped, external and variable. Default is simple.

§status: ProductStatus

Product status (post status). Options: draft, pending, private and publish. Default is publish.

§featured: bool

Featured product. Default is false.

§catalog_visibility: CatalogVisibility

Catalog visibility. Options: visible, catalog, search and hidden. Default is visible.

§description: String

Product description.

§short_description: String

Product short description.

§sku: String

Unique identifier.

§price: String

Current product price.

§regular_price: String

Product regular price.

§sale_price: String

Product 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.

§price_html: String

Price formatted in HTML.

§on_sale: bool

Shows if the product is on sale.

§purchasable: bool

Shows if the product can be bought.

§total_sales: i32

Amount of sales.

§is_virtual: bool

If the product is virtual. Default is false.

§downloadable: bool

If the product is downloadable. Default is false.

§downloads: Vec<Download>

List of downloadable files. See Product - Downloads properties

§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.

§external_url: String

Product external URL. Only for external products.

§button_text: String

Product external button text. Only for external products.

§tax_status: TaxStatus

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

§tax_class: String

Tax class.

§manage_stock: bool

Stock management at product 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 product is on backordered.

§sold_individually: bool

Allow one item to be bought in a single order. Default is false.

§weight: String

Product weight.

§dimensions: Dimensions

Product dimensions.

§shipping_required: bool

Shows if the product need to be shipped.

§shipping_taxable: bool

Shows whether or not the product shipping is taxable.READ-ONLY

§shipping_class: String

Shipping class slug.

§shipping_class_id: i32

Shipping class ID.

§reviews_allowed: bool

Allow reviews. Default is true.

§average_rating: String

Reviews average rating.

§rating_count: i32

Amount of reviews that the product have.

§related_ids: Vec<i32>

List of related products IDs.

§upsell_ids: Vec<i32>

List of up-sell products IDs.

§cross_sell_ids: Vec<i32>

List of cross-sell products IDs.

§parent_id: i32

Product parent ID.

§purchase_note: String

Optional note to send the customer after purchase.

§categories: Vec<ProductCategory>

List of categories.

§tags: Vec<ProductTag>

List of tags.

§images: Vec<ProductImage>

List of images.

§attributes: Vec<ProductAttribute>

List of attributes.

§default_attributes: Vec<ProductDefaultAttribute>

Defaults variation attributes.

§variations: Vec<i32>

List of variations IDs.

§grouped_products: Vec<i32>

List of grouped products ID.

§menu_order: i32

Menu order, used to custom sort products.

§meta_data: Vec<MetaData>

Meta data.

Implementations§

Source§

impl Product

Source

pub fn builder() -> ProductModifyBuilder

Examples found in repository?
examples/product.rs (line 25)
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
Hide additional examples
examples/variation.rs (line 41)
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 Clone for Product

Source§

fn clone(&self) -> Product

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 Product

Source§

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

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

impl<'de> Deserialize<'de> for Product

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 Product

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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>,