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.
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.
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.
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, used to custom sort products.
meta_data: Vec<MetaData>
Meta data.
Implementations§
Source§impl Product
impl Product
Sourcepub fn builder() -> ProductModifyBuilder
pub fn builder() -> ProductModifyBuilder
Examples found in repository?
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
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}