[*] FO : Set cache for StockAvailable::getQuantityAvailableByProduct

This commit is contained in:
gRoussac
2013-11-11 01:00:55 +01:00
parent 8dd951c2df
commit fee461fdf1

View File

@@ -53,6 +53,8 @@ class StockAvailableCore extends ObjectModel
/** @var bool determine if a product is out of stock - it was previously in Product class */
public $out_of_stock = false;
protected static $cache_quantity_available;
/**
* @see ObjectModel::$definition
*/
@@ -343,6 +345,9 @@ class StockAvailableCore extends ObjectModel
if ($id_product_attribute === null)
$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->select('SUM(quantity)');
$query->from('stock_available');
@@ -354,7 +359,9 @@ class StockAvailableCore extends ObjectModel
$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);
self::$cache_quantity_available[$key] = (int)Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($query);
}
return self::$cache_quantity_available[$key];
}
/**