// StockAvailable : cleaned & fixed save()
git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@9414 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
1 parent
39f37e465f
commit
6e2827418f
1 file changed
+21
-17
@@ -103,7 +103,6 @@ class StockAvailableCore extends ObjectModel
|
|||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity
|
* For a given id_product, synchronizes StockAvailable::quantity with Stock::usable_quantity
|
||||||
*
|
*
|
||||||
@@ -156,11 +155,11 @@ class StockAvailableCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
$query = array(
|
$query = array(
|
||||||
'table' => 'stock_available',
|
'table' => 'stock_available',
|
||||||
'data' => array('quantity' => $total_quantity),
|
'data' => array('quantity' => $total_quantity),
|
||||||
'type' => 'UPDATE',
|
'type' => 'UPDATE',
|
||||||
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
|
'where' => 'id_product = '.(int)$id_product.' AND id_product_attribute = 0 AND id_shop = '.(int)$id_shop
|
||||||
);
|
);
|
||||||
|
|
||||||
// saves quantities
|
// saves quantities
|
||||||
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
|
Db::getInstance()->autoExecute($query['table'], $query['data'], $query['type'], $query['where']);
|
||||||
@@ -181,11 +180,11 @@ class StockAvailableCore extends ObjectModel
|
|||||||
|
|
||||||
Db::getInstance()->autoExecute(
|
Db::getInstance()->autoExecute(
|
||||||
'stock_available',
|
'stock_available',
|
||||||
array('depends_on_stock' => (boolean)$depends_on_stock),
|
array('depends_on_stock' => (bool)$depends_on_stock),
|
||||||
'UPDATE',
|
'UPDATE',
|
||||||
'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop
|
'id_product = '.(int)$id_product.' AND id_shop = '.(int)$id_shop
|
||||||
);
|
);
|
||||||
if($depends_on_stock)
|
if ($depends_on_stock)
|
||||||
StockAvailable::synchronize($id_product);
|
StockAvailable::synchronize($id_product);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -215,6 +214,7 @@ class StockAvailableCore extends ObjectModel
|
|||||||
* @param int $id_product
|
* @param int $id_product
|
||||||
* @param int $id_product_attribute
|
* @param int $id_product_attribute
|
||||||
* @param int $id_shop
|
* @param int $id_shop
|
||||||
|
* @return int
|
||||||
*/
|
*/
|
||||||
public static function getStockAvailableForProduct($id_product, $id_product_attribute = null, $id_shop = null)
|
public static function getStockAvailableForProduct($id_product, $id_product_attribute = null, $id_shop = null)
|
||||||
{
|
{
|
||||||
@@ -231,30 +231,34 @@ class StockAvailableCore extends ObjectModel
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* After saving a quantity available, upgrade the total_quantity_available
|
* Upgrades total_quantity_available after having saved
|
||||||
|
* @see ObjectModel::save()
|
||||||
*/
|
*/
|
||||||
public function save($nullValues = false, $autodate = true)
|
public function save($null_values = false, $autodate = true)
|
||||||
{
|
{
|
||||||
if (!parent::save($nullValues, $autodate))
|
if (!parent::save($null_values, $autodate))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ($this->id_product_attribute = 0)
|
if ($this->id_product_attribute == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
$id_stock_available = StockAvailable::getIdStockAvailable($this->id_product, 0, $this->id_shop);
|
$id_stock_available = StockAvailable::getIdStockAvailable($this->id_product, 0, $this->id_shop);
|
||||||
|
|
||||||
$total_quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('SELECT sum(quantity) FROM '._DB_PREFIX_.'stock_available
|
$total_quantity = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
|
||||||
|
SELECT SUM(quantity)
|
||||||
|
FROM '._DB_PREFIX_.'stock_available
|
||||||
WHERE id_product = '.(int)$this->id_product.' AND id_shop = '.(int)$this->id_shop.' AND id_product_attribute <> 0');
|
WHERE id_product = '.(int)$this->id_product.' AND id_shop = '.(int)$this->id_shop.' AND id_product_attribute <> 0');
|
||||||
|
|
||||||
if (!$id_stock_available)
|
if (!$id_stock_available)
|
||||||
{
|
{
|
||||||
return (int)Db::getInstance()->execute('INSERT '._DB_PREFIX_.'stock_available
|
return (int)Db::getInstance()->execute('
|
||||||
SET id_product = '.(int)$this->id_product.', id_product_attribute = 0, id_shop = '.(int)$this->id_shop.'
|
INSERT '._DB_PREFIX_.'stock_available
|
||||||
quantity = '.(int)$total_quantity);
|
SET id_product = '.(int)$this->id_product.', id_product_attribute = 0, id_shop = '.(int)$this->id_shop.', quantity = '.(int)$total_quantity);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (int)Db::getInstance()->execute('UPDATE '._DB_PREFIX_.'stock_available
|
return (int)Db::getInstance()->execute('
|
||||||
|
UPDATE '._DB_PREFIX_.'stock_available
|
||||||
SET quantity = '.(int)$total_quantity.'
|
SET quantity = '.(int)$total_quantity.'
|
||||||
WHERE id_stock_available = '.(int)$id_stock_available);
|
WHERE id_stock_available = '.(int)$id_stock_available);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user