[*] FO : Set cache for StockAvailable::getQuantityAvailableByProduct
This commit is contained in:
1 parent
8dd951c2df
commit
fee461fdf1
1 file changed
+8
-1
@@ -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,6 +345,9 @@ class StockAvailableCore extends ObjectModel
|
|||||||
if ($id_product_attribute === null)
|
if ($id_product_attribute === null)
|
||||||
$id_product_attribute = 0;
|
$id_product_attribute = 0;
|
||||||
|
|
||||||
|
$key = (int)$id_product.'-'.(int)$id_product_attribute.'-'.(int)$id_shop;
|
||||||
|
if (!isset(self::$cache_quantity_available[$key]))
|
||||||
|
{
|
||||||
$query = new DbQuery();
|
$query = new DbQuery();
|
||||||
$query->select('SUM(quantity)');
|
$query->select('SUM(quantity)');
|
||||||
$query->from('stock_available');
|
$query->from('stock_available');
|
||||||
@@ -354,7 +359,9 @@ class StockAvailableCore extends ObjectModel
|
|||||||
$query->where('id_product_attribute = '.(int)$id_product_attribute);
|
$query->where('id_product_attribute = '.(int)$id_product_attribute);
|
||||||
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
|
$query = StockAvailable::addSqlShopRestriction($query, $id_shop);
|
||||||
|
|
||||||
return (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
self::$cache_quantity_available[$key] = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
|
||||||
|
}
|
||||||
|
return self::$cache_quantity_available[$key];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in new issue
Block a user