[*] FO : Set cache for StockAvailable::getQuantityAvailableByProduct
This commit is contained in:
@@ -53,6 +53,8 @@ class StockAvailableCore extends ObjectModel
|
|||||||
/** @var bool determine if a product is out of stock - it was previously in Product class */
|
/** @var bool determine if a product is out of stock - it was previously in Product class */
|
||||||
public $out_of_stock = false;
|
public $out_of_stock = false;
|
||||||
|
|
||||||
|
protected static $cache_quantity_available;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ObjectModel::$definition
|
* @see ObjectModel::$definition
|
||||||
*/
|
*/
|
||||||
@@ -343,18 +345,23 @@ class StockAvailableCore extends ObjectModel
|
|||||||
if ($id_product_attribute === null)
|
if ($id_product_attribute === null)
|
||||||
$id_product_attribute = 0;
|
$id_product_attribute = 0;
|
||||||
|
|
||||||
$query = new DbQuery();
|
$key = (int)$id_product.'-'.(int)$id_product_attribute.'-'.(int)$id_shop;
|
||||||
$query->select('SUM(quantity)');
|
if (!isset(self::$cache_quantity_available[$key]))
|
||||||
$query->from('stock_available');
|
{
|
||||||
|
$query = new DbQuery();
|
||||||
|
$query->select('SUM(quantity)');
|
||||||
|
$query->from('stock_available');
|
||||||
|
|
||||||
|
// if null, it's a product without attributes
|
||||||
|
if ($id_product !== null)
|
||||||
|
$query->where('id_product = '.(int)$id_product);
|
||||||
|
|
||||||
|
$query->where('id_product_attribute = '.(int)$id_product_attribute);
|
||||||
|
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
|
||||||
|
|
||||||
// if null, it's a product without attributes
|
self::$cache_quantity_available[$key] = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
if ($id_product !== null)
|
}
|
||||||
$query->where('id_product = '.(int)$id_product);
|
return self::$cache_quantity_available[$key];
|
||||||
|
|
||||||
$query->where('id_product_attribute = '.(int)$id_product_attribute);
|
|
||||||
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
|
|
||||||
|
|
||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user