From 0d0f43f7830525241cd3cd3e44c19d0a54a44e79 Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 21 Dec 2011 14:24:34 +0000 Subject: [PATCH] // Orders : fixed stock (available quantity & Stock) git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@11491 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Cart.php | 2 +- classes/order/OrderHistory.php | 12 +++++------- classes/stock/StockAvailable.php | 1 - classes/stock/StockManager.php | 7 ++++--- controllers/admin/AdminWarehousesController.php | 3 ++- 5 files changed, 12 insertions(+), 13 deletions(-) diff --git a/classes/Cart.php b/classes/Cart.php index 32f6f7b3b..7bd843b38 100644 --- a/classes/Cart.php +++ b/classes/Cart.php @@ -1362,7 +1362,7 @@ class CartCore extends ObjectModel if ($stock_management_active && (int)$product['advanced_stock_management'] == 1) { $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute'], $this->id_shop); - if (count($warehouse_list) == 0) + if (count($warehouse_list) == 0) $warehouse_list = Warehouse::getProductWarehouseList($product['id_product'], $product['id_product_attribute']); // Does the product is in stock ? // If yes, get only warehouse where the product is in stock diff --git a/classes/order/OrderHistory.php b/classes/order/OrderHistory.php index 61657a52f..016c73f31 100644 --- a/classes/order/OrderHistory.php +++ b/classes/order/OrderHistory.php @@ -85,8 +85,6 @@ class OrderHistoryCore extends ObjectModel && $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 @@ -95,7 +93,8 @@ class OrderHistoryCore extends ObjectModel { ProductSale::removeProductSale($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 ($newOS->id == Configuration::get('PS_OS_ERROR') || $newOS->id == Configuration::get('PS_OS_CANCELED')) + StockAvailable::updateQuantity($product['product_id'], $product['product_attribute_id'], (int)$product['product_quantity'], $order->id_shop); } if ((!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') || (int)$product['advanced_stock_management'] != 1) @@ -113,8 +112,7 @@ class OrderHistoryCore extends ObjectModel && $oldOrderStatus instanceof OrderState && $oldOrderStatus->shipped == 0 && Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') - && (int)$product['advanced_stock_management'] == 1 - ) + && (int)$product['advanced_stock_management'] == 1) { $manager = StockManagerFactory::getManager(); $warehouse = new Warehouse($product['id_warehouse']); @@ -142,12 +140,12 @@ class OrderHistoryCore extends ObjectModel ) { $manager = StockManagerFactory::getManager(); - $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['cart_quantity']); + $mvts = StockMvt::getNegativeStockMvts($order->id, $product['product_id'], $product['product_attribute_id'], $product['product_quantity']); foreach ($mvts as $mvt) { $manager->addProduct( $product['product_id'], - $product['id_product_attribute'], + $product['product_attribute_id'], new Warehouse($mvt['id_warehouse']), $mvt['physical_quantity'], null, diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index e261eb25b..a0a06d09b 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -140,7 +140,6 @@ class StockAvailableCore extends ObjectModel foreach ($ids_product_attribute as $id_product_attribute) { $quantity = $manager->getProductRealQuantities($id_product, $id_product_attribute, $warehouses, true); - $query = array( 'table' => _DB_PREFIX_.'stock_available', 'data' => array('quantity' => $quantity), diff --git a/classes/stock/StockManager.php b/classes/stock/StockManager.php index c8118cd64..e05b0eb79 100644 --- a/classes/stock/StockManager.php +++ b/classes/stock/StockManager.php @@ -465,9 +465,10 @@ class StockManagerCore implements StockManagerInterface $query->leftJoin('order_history', 'oh', 'oh.id_order = o.id_order AND oh.date_add = o.date_upd'); $query->leftJoin('order_state', 'os', 'os.id_order_state = oh.id_order_state'); $query->where('os.shipped != 1'); - $query->where('o.valid = 1'); - // @FIXME: Once part-shipping is done, remove the comment on the line below. - // $query->where('o.id_warehouse IN (0, '.implode(', ', $ids_warehouse).')'); + $query->where('o.valid = 1 OR (os.id_order_state != '.(int)Configuration::get('PS_OS_ERROR').' + AND os.id_order_state != '.(int)Configuration::get('PS_OS_CANCELED').')'); + //if (count($ids_warehouse)) + //$query->where('od.id_warehouse IN('.implode(', ', $ids_warehouse).')'); $client_orders_qty = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query); // Gets supply_orders_qty diff --git a/controllers/admin/AdminWarehousesController.php b/controllers/admin/AdminWarehousesController.php index 277c0374e..be6265413 100644 --- a/controllers/admin/AdminWarehousesController.php +++ b/controllers/admin/AdminWarehousesController.php @@ -165,7 +165,8 @@ class AdminWarehousesControllerCore extends AdminController 'size' => 40, 'maxlength' => 45, 'required' => true, - 'desc' => $this->l('Name of this warehouse') + 'desc' => $this->l('Name of this warehouse'), + 'hint' => $this->l('Invalid characters:').' 0-9!<>,;?=+()@#"�{}_$%:', ), array( 'type' => 'text',