From df463cad79a91a782de97751a4c76e64aa7ba900 Mon Sep 17 00:00:00 2001 From: bMancone Date: Mon, 12 Dec 2011 10:54:59 +0000 Subject: [PATCH] // StockInstantState: fixed bug on names. AdminOrders: fixed bug on return --- controllers/admin/AdminOrdersController.php | 8 ++++---- .../AdminStockInstantStateController.php | 19 +++++++++++++++---- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/controllers/admin/AdminOrdersController.php b/controllers/admin/AdminOrdersController.php index b82185fa5..f4d1a6ec7 100755 --- a/controllers/admin/AdminOrdersController.php +++ b/controllers/admin/AdminOrdersController.php @@ -434,15 +434,15 @@ class AdminOrdersControllerCore extends AdminController // Reinject product if (!$order->hasBeenDelivered() OR ($order->hasBeenDelivered() AND Tools::isSubmit('reinjectQuantities'))) { - $reinjectable_quantity = (int)$qty_cancel_product->product_quantity - (int)$qty_cancel_product->product_quantity_reinjected; + $reinjectable_quantity = (int)$order_detail->product_quantity - (int)$order_detail->product_quantity_reinjected; $quantity_to_reinject = $qty_cancel_product > $reinjectable_quantity ? $reinjectable_quantity : $qty_cancel_product; // @since 1.5.0 : Advanced Stock Management - $product_to_inject = new Product($qty_cancel_product->product_id, false, $this->context->language->id, $order->id_shop); - if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $qty_cancel_product->id_warehouse != 0) + $product_to_inject = new Product($order_detail->product_id, false, $this->context->language->id, $order->id_shop); + if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && $order_detail->id_warehouse != 0) { $id_supplier = $product_to_inject->id_supplier; - $price = ProductSupplier::getProductPrice($id_supplier, $qty_cancel_product->product_id, $order_detail->product_attribute_id); + $price = ProductSupplier::getProductPrice($id_supplier, $order_detail->product_id, $order_detail->product_attribute_id); $price_te = $price['price_te']; $id_currency = $price['id_currency']; $warehouse = new Warehouse($id_warehouse); diff --git a/controllers/admin/AdminStockInstantStateController.php b/controllers/admin/AdminStockInstantStateController.php index 36b7df378..1f43c2e95 100644 --- a/controllers/admin/AdminStockInstantStateController.php +++ b/controllers/admin/AdminStockInstantStateController.php @@ -115,9 +115,6 @@ class AdminStockInstantStateControllerCore extends AdminController // query $this->_select = ' IFNULL(CONCAT(pl.name, \' : \', GROUP_CONCAT(DISTINCT agl.`name`, \' - \', al.name SEPARATOR \', \')),pl.name) as name, - SUM(a.physical_quantity) as physical_quantity, - SUM(a.usable_quantity) as usable_quantity, - SUM(a.price_te * a.physical_quantity) as valuation, w.id_currency'; $this->_group = 'GROUP BY a.id_product, a.id_product_attribute'; @@ -125,7 +122,7 @@ class AdminStockInstantStateControllerCore extends AdminController $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'warehouse` w ON (w.id_warehouse = a.id_warehouse)'; $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON ( a.id_product = pl.id_product - AND pl.id_lang = '.(int)$this->context->language->id.$this->context->shop->addSqlRestrictionOnLang('pl').' + AND pl.id_lang = '.(int)$this->context->language->id.' )'; $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = a.id_product_attribute)'; $this->_join .= ' LEFT JOIN `'._DB_PREFIX_.'attribute` atr ON (atr.id_attribute = pac.id_attribute)'; @@ -192,6 +189,18 @@ class AdminStockInstantStateControllerCore extends AdminController // gets stock manager $manager = StockManagerFactory::getManager(); + // gets quantities and valuation + $query = new DbQuery(); + $query->select('SUM(physical_quantity) as physical_quantity'); + $query->select('SUM(usable_quantity) as usable_quantity'); + $query->select('SUM(price_te * physical_quantity) as valuation'); + $query->from('stock'); + $query->where('id_product = '.(int)$item['id_product'].' AND id_product_attribute = '.(int)$item['id_product_attribute']); + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query); + + $item['physical_quantity'] = $res['physical_quantity']; + $item['usable_quantity'] = $res['usable_quantity']; + // gets real_quantity depending on the warehouse $item['real_quantity'] = $manager->getProductRealQuantities($item['id_product'], $item['id_product_attribute'], @@ -201,6 +210,8 @@ class AdminStockInstantStateControllerCore extends AdminController // removes the valuation if the filter corresponds to 'all warehouses' if ($this->getCurrentCoverageWarehouse() == -1) $item['valuation'] = 'N/A'; + else + $item['valuation'] = $res['valuation']; } }