ClassicPress / classic-commerce

A simple but powerful e-commerce platform built for ClassicPress. Forked from WooCommerce and compatible with many Woo extensions.
https://classiccommerce.cc/
GNU General Public License v3.0
52 stars 15 forks source link

Wrong WC_Data_Store in function wc_update_product_stock() #319

Closed magenta-cuda closed 3 years ago

magenta-cuda commented 3 years ago

https://github.com/ClassicPress-plugins/classic-commerce/blob/10650f8347d4307b8b02ccdc76195e544cb50e51/includes/wc-stock-functions.php#L36

I think that line should be:

$data_store = WC_Data_Store::load( 'product-' . $product->get_type() );

The problem with the ClassicCommerce implementation is that if you have implemented your own product (as a subclass of WC_Product) with its own datastore (as a subclass of WC_Product_Data_Store_CPT) wc_update_product_stock() will not call the update_product_stock() of your datastore.

function wc_update_product_stock( $product, $stock_quantity = null, $operation = 'set', $updating = false ) {
    ...
    $data_store = WC_Data_Store::load( 'product' );
    ...
    $new_stock = $data_store->update_product_stock( $product_id_with_stock, $stock_quantity, $operation );
    ...
}