diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 038ea8a2a..61657a52f 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -80,15 +80,17 @@ class OrderHistoryCore extends ObjectModel foreach ($order->getProductsDetail() as $product) { /* If becoming logable => adding sale */ - if ($newOS->logable - && $oldOrderStatus instanceof OrderHistory - && $oldOrderStatus->logable) + if ($newOS->logable + && !($oldOrderStatus instanceof OrderState + && $oldOrderStatus->logable)) { ProductSale::addProductSale($product['product_id'], $product['product_quantity']); + // @since 1.5.0 + StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop); } /* If becoming unlogable => removing sale */ - else if (!$newOS->logable - && $oldOrderStatus instanceof OrderHistory + else if (!$newOS->logable + && $oldOrderStatus instanceof OrderState && $oldOrderStatus->logable) { ProductSale::removeProductSale($product['product_id'], $product['product_quantity']); @@ -99,7 +101,7 @@ class OrderHistoryCore extends ObjectModel if ((!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') || (int)$product['advanced_stock_management'] != 1) && !$isValidated && $newOS->logable - && $oldOrderStatus instanceof OrderHistory + && $oldOrderStatus instanceof OrderState && $oldOrderStatus->id == Configuration::get('PS_OS_ERROR') ) StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop); @@ -108,7 +110,7 @@ class OrderHistoryCore extends ObjectModel // The product is removed from the physical stock. $id_warehouse is needed // @TODO Checks $id_warehouse else if ($newOS->shipped == 1 - && $oldOrderStatus instanceof OrderHistory + && $oldOrderStatus instanceof OrderState && $oldOrderStatus->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1 @@ -133,7 +135,7 @@ class OrderHistoryCore extends ObjectModel StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], -(int)$product['product_quantity'], $order->id_shop); } else if ($newOS->shipped == 0 - && $oldOrderStatus instanceof OrderHistory + && $oldOrderStatus instanceof OrderState && $oldOrderStatus->shipped == 1 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int)$product['advanced_stock_management'] == 1