rust_woocommerce/models/
product_variations.rs

1use crate::controllers::product_variations::ProductVariationModifyBuilder;
2
3use super::{
4    products::{
5        BackordersStatus, Dimensions, Download, ProductDefaultAttribute, ProductImage,
6        ProductStatus, StockStatus, TaxStatus,
7    },
8    MetaData,
9};
10use crate::controllers::Entity;
11use chrono::NaiveDateTime;
12use serde::{Deserialize, Serialize};
13
14#[derive(Debug, Clone, Serialize, Deserialize)]
15pub struct ProductVariation {
16    /// Unique identifier for the resource.
17    pub id: i32,
18    /// The date the variation was created, in the site's timezone.
19    pub date_created: NaiveDateTime,
20    /// The date the variation was created, as GMT.
21    pub date_created_gmt: NaiveDateTime,
22    /// The date the variation was last modified, in the site's timezone.
23    pub date_modified: NaiveDateTime,
24    /// The date the variation was last modified, as GMT.
25    pub date_modified_gmt: NaiveDateTime,
26    /// Variation description.
27    pub description: String,
28    /// Variation URL.
29    pub permalink: String,
30    /// Unique identifier.
31    pub sku: String,
32    /// Current variation price.
33    pub price: String,
34    /// Variation regular price.
35    pub regular_price: String,
36    /// Variation sale price.
37    pub sale_price: String,
38    /// Start date of sale price, in the site's timezone.
39    pub date_on_sale_from: Option<NaiveDateTime>,
40    /// Start date of sale price, as GMT.
41    pub date_on_sale_from_gmt: Option<NaiveDateTime>,
42    /// End date of sale price, in the site's timezone.
43    pub date_on_sale_to: Option<NaiveDateTime>,
44    /// End date of sale price, as GMT.
45    pub date_on_sale_to_gmt: Option<NaiveDateTime>,
46    /// Shows if the variation is on sale. READ-ONLY
47    pub on_sale: bool,
48    /// Variation status. Options: draft, pending, private and publish. Default is publish.
49    pub status: ProductStatus,
50    /// Shows if the variation can be bought.
51    pub purchasable: bool,
52    /// If the variation is virtual. Default is false.
53    #[serde(rename = "virtual")]
54    pub is_virtual: bool,
55    /// If the variation is downloadable. Default is false.
56    pub downloadable: bool,
57    /// List of downloadable files.
58    pub downloads: Vec<Download>,
59    /// Number of times downloadable files can be downloaded after purchase. Default is -1.
60    pub download_limit: i32,
61    /// Number of days until access to downloadable files expires. Default is -1.
62    pub download_expiry: i32,
63    /// Tax status. Options: taxable, shipping and none. Default is taxable.
64    pub tax_status: TaxStatus,
65    /// Tax class.
66    pub tax_class: String,
67    /// Stock management at variation level. Default is false.
68    pub manage_stock: ManageStock,
69    /// Stock quantity.
70    pub stock_quantity: Option<i32>,
71    /// Controls the stock status of the product. Options: instock, outofstock, onbackorder. Default is instock.
72    pub stock_status: StockStatus,
73    /// If managing stock, this controls if backorders are allowed. Options: no, notify and yes. Default is no.
74    pub backorders: BackordersStatus,
75    /// Shows if backorders are allowed.
76    pub backorders_allowed: bool,
77    /// Shows if the variation is on backordered.
78    pub backordered: bool,
79    /// Variation weight.
80    pub weight: String,
81    /// Variation dimensions. See Product variation - Dimensions properties
82    pub dimensions: Dimensions,
83    /// Shipping class slug.
84    pub shipping_class: String,
85    /// Shipping class ID.
86    pub shipping_class_id: i32,
87    /// Variation image data.
88    pub image: Option<ProductImage>,
89    /// List of attributes.
90    pub attributes: Vec<ProductDefaultAttribute>,
91    /// Menu order, used to custom sort products.
92    pub menu_order: i32,
93    /// Meta data.
94    pub meta_data: Vec<MetaData>,
95}
96
97impl Entity for ProductVariation {
98    fn endpoint() -> String {
99        String::new()
100    }
101
102    fn child_endpoint(parent_id: i32) -> String {
103        format!("products/{parent_id}/variations/")
104    }
105}
106impl ProductVariation {
107    pub fn builder() -> ProductVariationModifyBuilder {
108        ProductVariationModifyBuilder::default()
109    }
110}
111#[derive(Debug, Clone, Serialize, Deserialize)]
112#[serde(untagged)]
113pub enum ManageStock {
114    Bool(bool),
115    Parent(String),
116}