// Refactoring of shop class with new context Part 2

This commit is contained in:
rMalie
2011-07-13 12:52:09 +00:00
parent 375607f8a5
commit 8981b6aaee
21 changed files with 189 additions and 193 deletions
+20 -12
View File
@@ -2079,17 +2079,22 @@ class ProductCore extends ObjectModel
*
* @since 1.5.0
* @param int $quantity
* @param int $id_product_attribute
* @param bool $update
* @param Context $context
*/
public function setStock($quantity, $id_product_attribute = 0, $update = false)
public function setStock($quantity, $id_product_attribute = 0, $update = false, $context = null)
{
if (!$this->id)
return ;
$shop = Context::getContext()->shop->getID();
if (!$context)
$context = Context::getContext();
$shop = $context->shop;
// For retrocompatibility
$id_product_attribute = (int)$id_product_attribute;
$quantity = (int)$quantity;
if (Shop::getInstance($shop)->isDefaultShop())
if ($shop->isDefaultShop())
{
if ($id_product_attribute)
{
@@ -2111,7 +2116,7 @@ class ProductCore extends ObjectModel
// Change stock quantity on product attribute
if ($id_product_attribute)
{
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop))
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID()))
{
$sql = 'UPDATE '._DB_PREFIX_.'stock
SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).'
@@ -2122,14 +2127,14 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => $id_product_attribute,
'id_shop' => $shop,
'id_group_shop' => Shop::getGroupFromShop($shop),
'id_shop' => $shop->getID(),
'id_group_shop' => $shop->getGroupID(),
'quantity' => $quantity,
), 'INSERT');
}
// Change stock quantity on product
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop))
if ($id_stock = Stock::getStockId($this->id, $id_product_attribute, $shop->getID()))
{
$sql = 'UPDATE '._DB_PREFIX_.'stock
SET quantity = '.(($update) ? 'quantity + '. $quantity : $quantity).'
@@ -2140,8 +2145,8 @@ class ProductCore extends ObjectModel
Db::getInstance()->autoExecute(_DB_PREFIX_.'stock', array(
'id_product' => $this->id,
'id_product_attribute' => 0,
'id_shop' => $shop,
'id_group_shop' => Shop::getGroupFromShop($shop),
'id_shop' => $shop->getID(),
'id_group_shop' => $shop->getGroupID(),
'quantity' => $quantity,
), 'INSERT');
}
@@ -2150,19 +2155,22 @@ class ProductCore extends ObjectModel
* Get the stock quantity of current product
*
* @since 1.5.0
* @param int $id_product_attribute
* @param Context $context
* @return int
*/
public function getStock($id_product_attribute = 0)
public function getStock($id_product_attribute = 0, $context = null)
{
if (!$this->id)
return 0;
if (!$context)
$context = Context::getContext();
$shop = Context::getContext()->shop->getID();
$sql = 'SELECT quantity
FROM '._DB_PREFIX_.'stock
WHERE id_product = '.$this->id.'
AND id_product_attribute = '.(int)$id_product_attribute
.Shop::sqlSharedStock('', $shop);
.Shop::sqlSharedStock();
return (int)Db::getInstance()->getValue($sql);
}