diff --git a/classes/Pack.php b/classes/Pack.php index 1e8691fb8..25989122a 100644 --- a/classes/Pack.php +++ b/classes/Pack.php @@ -78,7 +78,8 @@ class PackCore extends Product $arrayResult = array(); foreach ($result AS $row) { - $p = new Product($row['id_product_item'], false, (int)($id_lang)); + $p = new Product($row['id_product_item'], false, $id_lang); + $p->loadStockData(); $p->pack_quantity = $row['quantity']; $arrayResult[] = $p; } diff --git a/classes/Product.php b/classes/Product.php index cb1944a1f..02c556d20 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -391,12 +391,9 @@ class ProductCore extends ObjectModel $this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0); if ($this->id) $this->tags = Tag::getProductTags((int)$this->id); - } - // By default, the product quantity correspond to the available quantity to sell in the current shop - $this->quantity = StockAvailable::getQuantityAvailableByProduct($id_product, 0); - $this->out_of_stock = StockAvailable::outOfStock($this->id); - $this->depends_on_stock = StockAvailable::dependsOnStock($this->id); + $this->loadStockData(); + } if ($this->id_category_default) $this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang); @@ -4729,4 +4726,15 @@ class ProductCore extends ObjectModel return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } + + /** + * Fill the variables used for stock management + */ + public function loadStockData() + { + // By default, the product quantity correspond to the available quantity to sell in the current shop + $this->quantity = StockAvailable::getQuantityAvailableByProduct($this->id, 0); + $this->out_of_stock = StockAvailable::outOfStock($this->id); + $this->depends_on_stock = StockAvailable::dependsOnStock($this->id); + } } diff --git a/controllers/admin/AdminAttributeGeneratorController.php b/controllers/admin/AdminAttributeGeneratorController.php index de7cdbebe..e664f2169 100644 --- a/controllers/admin/AdminAttributeGeneratorController.php +++ b/controllers/admin/AdminAttributeGeneratorController.php @@ -79,6 +79,7 @@ class AdminAttributeGeneratorControllerCore extends AdminController public function postProcess() { $this->product = new Product((int)Tools::getValue('id_product')); + $this->product->loadStockData(); if (isset($_POST['generate'])) { diff --git a/controllers/admin/AdminImportController.php b/controllers/admin/AdminImportController.php index 6934d00ea..a5429dd2d 100644 --- a/controllers/admin/AdminImportController.php +++ b/controllers/admin/AdminImportController.php @@ -924,6 +924,7 @@ class AdminImportControllerCore extends AdminController if (array_key_exists('id', $info) && (int)$info['id'] && Product::existsInDatabase((int)$info['id'], 'product')) { $product = new Product((int)$info['id']); + $product->loadStockData(); $category_data = Product::getProductCategories((int)$product->id); foreach ($category_data as $tmp) $product->category[] = $tmp; diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index 813c24a69..279896fd9 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -1022,6 +1022,21 @@ class AdminProductsControllerCore extends AdminController $this->display = 'list'; } + /** + * Override parent to add stock data to object + * We don't want to make a "full" product load because of side effects to prices + * + * @param boolean $opt Return an empty object if load fail + * @return object + */ + protected function loadObject($opt = false) + { + $result = parent::loadObject($opt); + if ($result) + $this->object->loadStockData(); + return $result; + } + /** * postProcess handle every checks before saving products information *