// Fixed stock_available when ordering products
This commit is contained in:
@@ -131,7 +131,7 @@ class OrderDetailCore extends ObjectModel
|
||||
|
||||
/** @var float $tax_rate **/
|
||||
public $tax_rate;
|
||||
|
||||
|
||||
/** @var int Id warehouse */
|
||||
public $id_warehouse;
|
||||
|
||||
@@ -364,8 +364,13 @@ class OrderDetailCore extends ObjectModel
|
||||
{
|
||||
if ($id_order_state != Configuration::get('PS_OS_CANCELED') && $id_order_state != Configuration::get('PS_OS_ERROR'))
|
||||
{
|
||||
if (StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']))
|
||||
$update_quantity = true;
|
||||
if (!StockAvailable::dependsOnStock($product['id_product']))
|
||||
$update_quantity = StockAvailable::updateQuantity($product['id_product'], $product['id_product_attribute'], -(int)$product['cart_quantity']);
|
||||
|
||||
if ($update_quantity)
|
||||
$product['stock_quantity'] -= $product['cart_quantity'];
|
||||
|
||||
if ($product['stock_quantity'] < 0 && Configuration::get('PS_STOCK_MANAGEMENT'))
|
||||
$this->outOfStock = true;
|
||||
Product::updateDefaultAttribute($product['id_product']);
|
||||
|
||||
@@ -109,7 +109,8 @@ class OrderHistoryCore extends ObjectModel
|
||||
ProductSale::addProductSale($product['product_id'], $product['product_quantity']);
|
||||
// @since 1.5.0 - Stock Management
|
||||
if (!Pack::isPack($product['product_id']) &&
|
||||
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')))
|
||||
($old_os->id == Configuration::get('PS_OS_ERROR') || $old_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
||||
!StockAvailable::dependsOnStock($product['id_product']))
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop);
|
||||
}
|
||||
// if becoming unlogable => removes sale
|
||||
@@ -119,12 +120,14 @@ class OrderHistoryCore extends ObjectModel
|
||||
|
||||
// @since 1.5.0 - Stock Management
|
||||
if (!Pack::isPack($product['product_id']) &&
|
||||
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')))
|
||||
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
||||
!StockAvailable::dependsOnStock($product['id_product']))
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||
}
|
||||
// if waiting for payment => payment error/canceled
|
||||
else if (!$new_os->logable && !$old_os->logable &&
|
||||
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')))
|
||||
($new_os->id == Configuration::get('PS_OS_ERROR') || $new_os->id == Configuration::get('PS_OS_CANCELED')) &&
|
||||
!StockAvailable::dependsOnStock($product['id_product']))
|
||||
StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop);
|
||||
// @since 1.5.0 : if the order is being shipped and this products uses the advanced stock management :
|
||||
// decrements the physical stock using $id_warehouse
|
||||
@@ -176,7 +179,8 @@ class OrderHistoryCore extends ObjectModel
|
||||
true
|
||||
);
|
||||
}
|
||||
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop);
|
||||
if (!StockAvailable::dependsOnStock($product['id_product']))
|
||||
StockAvailable::updateQuantity($pack_product->id, 0, (int)$pack_product->pack_quantity * $product['product_quantity'], $order->id_shop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user