From d2d314665f8ee5d95550ac9dbc3e5bb2f2332e3a Mon Sep 17 00:00:00 2001 From: bMancone Date: Wed, 28 Mar 2012 10:07:57 +0000 Subject: [PATCH] // normalize --- classes/stock/Stock.php | 13 +++++++++---- classes/stock/StockMvt.php | 12 +++++++++++- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/classes/stock/Stock.php b/classes/stock/Stock.php index 4ca808403..5ed4fdf32 100644 --- a/classes/stock/Stock.php +++ b/classes/stock/Stock.php @@ -113,11 +113,12 @@ class StockCore extends ObjectModel } /** - * Try to get reference, ean13 and upc information on current product - * and store it in stock for stock_mvt integrity and history use + * Gets reference, ean13 and upc of the current product + * Stores it in stock for stock_mvt integrity and history purposes */ protected function getProductInformations() { + // if combinations if ((int)$this->id_product_attribute > 0) { $query = new DbQuery(); @@ -125,15 +126,19 @@ class StockCore extends ObjectModel $query->from('product_attribute'); $query->where('id_product = '.(int)$this->id_product); $query->where('id_product_attribute = '.(int)$this->id_product_attribute); + $rows = Db::getInstance()->executeS($query); - foreach (Db::getInstance()->executeS($query) as $row) + if (!is_array($rows)) + return; + + foreach ($rows as $row) { $this->reference = $row['reference']; $this->ean13 = $row['ean13']; $this->upc = $row['upc']; } } - else + else // else, simple product { $product = new Product((int)$this->id_product); if (Validate::isLoadedObject($product)) diff --git a/classes/stock/StockMvt.php b/classes/stock/StockMvt.php index 52975c1a8..ce7c555fc 100644 --- a/classes/stock/StockMvt.php +++ b/classes/stock/StockMvt.php @@ -164,10 +164,12 @@ class StockMvtCore extends ObjectModel /** * @deprecated since 1.5.0 * - * This method no longer exists, and have no equivalent because the missing movements have to be handled by inventories. + * This method no longer exists. + * There is no equivalent or replacement, considering that this should be handled by inventories. */ public static function addMissingMvt($id_employee) { + // display that this method is deprecated Tools::displayAsDeprecated(); } @@ -188,6 +190,7 @@ class StockMvtCore extends ObjectModel $movements = array(); $quantity_total = 0; + // preps query $query = new DbQuery(); $query->select('sm.*, s.id_warehouse'); $query->from('stock_mvt', 'sm'); @@ -195,11 +198,18 @@ class StockMvtCore extends ObjectModel $query->where('sm.sign = -1'); $query->where('sm.id_order = '.(int)$id_order); $query->where('s.id_product = '.(int)$id_product.' AND s.id_product_attribute = '.(int)$id_product_attribute); + + // if filer by warehouse if (!is_null($id_warehouse)) $query->where('s.id_warehouse = '.(int)$id_warehouse); + + // orders the movements by date $query->orderBy('date_add DESC'); + // gets the result $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($query); + + // fills the movements array while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($res)) { if ($quantity_total >= $quantity)