- Модуль: iblock
- Путь к файлу: ~/bitrix/modules/iblock/lib/component/base.php
- Класс: BitrixIblockComponentBase
- Вызов: Base::loadPrices
protected function loadPrices(array $itemIds)
{
if (empty($itemIds))
return;
MainTypeCollection::normalizeArrayValuesByInt($itemIds, true);
if (empty($itemIds))
return;
$this->loadMeasureRatios($itemIds);
if (empty($this->storage['PRICES_ALLOW']))
return;
$enableCompatible = $this->isEnableCompatible();
$quantityList = array_fill_keys($itemIds, array());
$select = array(
'ID', 'PRODUCT_ID', 'CATALOG_GROUP_ID', 'PRICE', 'CURRENCY',
'QUANTITY_FROM', 'QUANTITY_TO', 'PRICE_SCALE'
);
if ($enableCompatible)
$select[] = 'EXTRA_ID';
$pagedItemIds = array_chunk($itemIds, 500);
foreach ($pagedItemIds as $pageIds)
{
if (empty($pageIds))
continue;
$iterator = CatalogPriceTable::getList(array(
'select' => $select,
'filter' => array('@PRODUCT_ID' => $pageIds, '@CATALOG_GROUP_ID' => $this->storage['PRICES_ALLOW']),
'order' => array('PRODUCT_ID' => 'ASC', 'CATALOG_GROUP_ID' => 'ASC')
));
while ($row = $iterator->fetch())
{
$id = (int)$row['PRODUCT_ID'];
unset($row['PRODUCT_ID']);
if (!isset($this->prices[$id]))
{
$this->prices[$id] = array(
'RATIO' => array(),
'QUANTITY' => array(),
'SIMPLE' => array()
);
}
if ($row['QUANTITY_FROM'] !== null || $row['QUANTITY_TO'] !== null)
{
$hash = $this->getQuantityRangeHash($row);
if (!isset($quantityList[$id][$hash]))
{
$quantityList[$id][$hash] = array(
'HASH' => $hash,
'QUANTITY_FROM' => $row['QUANTITY_FROM'],
'QUANTITY_TO' => $row['QUANTITY_TO'],
'SORT_FROM' => (int)$row['QUANTITY_FROM'],
'SORT_TO' => ($row['QUANTITY_TO'] === null ? INF : (int)$row['QUANTITY_TO'])
);
}
if (!isset($this->prices[$id]['QUANTITY'][$hash]))
{
$this->prices[$id]['QUANTITY'][$hash] = array();
}
$this->prices[$id]['QUANTITY'][$hash][$row['CATALOG_GROUP_ID']] = $row;
unset($hash);
}
elseif (!isset($row['MEASURE_RATIO_ID']))
{
$this->prices[$id]['SIMPLE'][$row['CATALOG_GROUP_ID']] = $row;
}
$this->storage['CURRENCY_LIST'][$row['CURRENCY']] = $row['CURRENCY'];
unset($id);
}
unset($row, $iterator);
}
unset($pageIds, $pagedItemIds);
foreach ($itemIds as $id)
{
if (isset($this->prices[$id]))
{
foreach ($this->prices[$id] as $key => $data)
{
if (empty($data))
unset($this->prices[$id][$key]);
}
unset($key, $data);
if (count($this->prices[$id]) !== 1)
{
unset($this->prices[$id]);
}
else
{
if (!empty($this->prices[$id]['QUANTITY']))
{
$productQuantity = $quantityList[$id];
MainTypeCollection::sortByColumn(
$productQuantity,
array('SORT_FROM' => SORT_ASC, 'SORT_TO' => SORT_ASC),
'', null, true
);
$this->quantityRanges[$id] = $productQuantity;
unset($productQuantity);
if (count($this->ratios[$id]) > 1)
$this->compactItemRatios($id);
}
if (!empty($this->prices[$id]['SIMPLE']))
{
$range = $this->getFullQuantityRange();
$this->quantityRanges[$id] = array(
$range['HASH'] => $range
);
unset($range);
if (count($this->ratios[$id]) > 1)
$this->compactItemRatios($id);
}
}
}
}
unset($id);
unset($quantityList);
unset($enableCompatible);
}