From f581544632b215f68c6728a7f460bb22f71909a3 Mon Sep 17 00:00:00 2001 From: rGaillard Date: Mon, 25 Jun 2012 14:46:03 +0000 Subject: [PATCH] [-] BO: Fix bugs with stock management --- classes/Product.php | 5 +++++ classes/stock/StockAvailable.php | 16 +++++++++------- controllers/admin/AdminProductsController.php | 2 +- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/classes/Product.php b/classes/Product.php index cc2efe748..eb9f81a9b 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -4810,6 +4810,11 @@ class ProductCore extends ObjectModel $this->quantity = StockAvailable::getQuantityAvailableByProduct($this->id, 0); $this->out_of_stock = StockAvailable::outOfStock($this->id); $this->depends_on_stock = StockAvailable::dependsOnStock($this->id); + if (Context::getContext()->shop->getContext() == Shop::CONTEXT_GROUP && Context::getContext()->shop->getContextShopGroup()->share_stock == 1) + + $this->advanced_stock_management = Db::getInstance()->getValue('SELECT `advanced_stock_management` + FROM '._DB_PREFIX_.'product_shop + WHERE id_product='.(int)$this->id.Shop::addSqlRestriction()); } /** diff --git a/classes/stock/StockAvailable.php b/classes/stock/StockAvailable.php index f86995c04..2d58f89ea 100644 --- a/classes/stock/StockAvailable.php +++ b/classes/stock/StockAvailable.php @@ -217,11 +217,8 @@ class StockAvailableCore extends ObjectModel */ public static function setProductDependsOnStock($id_product, $depends_on_stock = true, $id_shop = null, $id_product_attribute = 0) { - if ($id_shop === null) - $id_shop = Context::getContext()->shop->id; - - $existing_id = StockAvailable::getStockAvailableIdByProductId((int)$id_product, (int)$id_product_attribute, (int)$id_shop); + $existing_id = StockAvailable::getStockAvailableIdByProductId((int)$id_product, (int)$id_product_attribute, $id_shop); if ($existing_id > 0) { Db::getInstance()->update('stock_available', array( @@ -638,10 +635,15 @@ class StockAvailableCore extends ObjectModel // if there is no $id_shop, gets the context one // get shop group too - if ($id_shop === null) + if ($id_shop === null) { - $id_shop = $context->shop->id; - $shop_group = $context->shop->getGroup(); + if (Shop::getContext() == Shop::CONTEXT_GROUP) + $shop_group = Shop::getContextShopGroup(); + else + { + $shop_group = $context->shop->getGroup(); + $id_shop = $context->shop->id; + } } else { diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 26b0bd77e..88b1c26f3 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -3799,7 +3799,7 @@ class AdminProductsControllerCore extends AdminController if (!Tools::getValue('actionQty')) return Tools::jsonEncode(array('error' => $this->l('Undefined action'))); - $product = new Product((int)Tools::getValue('id_product')); + $product = new Product((int)Tools::getValue('id_product'), true); switch (Tools::getValue('actionQty')) { case 'depends_on_stock':