- Модуль: catalog
- Путь к файлу: ~/bitrix/modules/catalog/lib/product/price.php
- Класс: BitrixCatalogProductPrice
- Вызов: Price::loadRoundRules
static function loadRoundRules(array $priceTypes)
{
if (empty($priceTypes))
return;
MainTypeCollection::normalizeArrayValuesByInt($priceTypes);
if (empty($priceTypes))
return;
$skipCache = (defined('CATALOG_SKIP_CACHE') && CATALOG_SKIP_CACHE);
$cacheTime = (int)self::CACHE_TIME;
/** @var BitrixMainDataManagedCache $managedCache */
$managedCache = MainApplication::getInstance()->getManagedCache();
$needLoad = array();
foreach ($priceTypes as $priceTypeId)
{
if (!isset(self::$roundRules[$priceTypeId]))
{
$rulesFound = false;
$cacheId = static::getRulesCacheId($priceTypeId);
if (!$skipCache)
{
$cacheExist = $managedCache->read($cacheTime, $cacheId, CatalogRoundingTable::getTableName());
if ($cacheExist)
{
$rulesFound = true;
self::$roundRules[$priceTypeId] = $managedCache->get($cacheId);
}
}
if ($skipCache || !$rulesFound)
$needLoad[] = $priceTypeId;
unset($cacheId, $rulesFound);
}
}
unset($priceTypeId);
if (!empty($needLoad))
{
foreach ($needLoad as $priceTypeId)
self::$roundRules[$priceTypeId] = array();
unset($priceTypeId);
$iterator = CatalogRoundingTable::getList(array(
'select' => array('PRICE', 'ROUND_TYPE', 'ROUND_PRECISION', 'CATALOG_GROUP_ID'),
'filter' => array('@CATALOG_GROUP_ID' => $needLoad),
'order' => array('CATALOG_GROUP_ID' => 'ASC', 'PRICE' => 'DESC')
));
while ($row = $iterator->fetch())
{
$priceTypeId = (int)$row['CATALOG_GROUP_ID'];
self::$roundRules[$priceTypeId][] = $row;
unset($priceTypeId);
}
unset($row, $iterator);
if (!$skipCache)
{
foreach ($needLoad as $priceTypeId)
$managedCache->set(static::getRulesCacheId($priceTypeId), self::$roundRules[$priceTypeId]);
unset($priceType);
}
}
unset($needLoad);
unset($managedCache, $cacheTime, $skipCache);
}