- Модуль: catalog
- Путь к файлу: ~/bitrix/modules/catalog/lib/helpers/admin/iblockpricechanger.php
- Класс: BitrixCatalogHelpersAdminIblockPriceChanger
- Вызов: IblockPriceChanger::updatePrices
public function updatePrices($productsIdList)
{
$result = new MainResult();
if ($this->userDialogParams == false)
{
$result->addError(
new MainError("IBLIST_CHPRICE_ERROR_WRONG_INPUT_VALUE", null)
);
return $result;
}
if($this->userDialogParams['UNITS'] === null)
{
$result->addError(
new MainError("IBLIST_CHPRICE_ERROR_WRONG_CURRENCY")
);
return $result;
}
if (!empty( $productsIdList['SECTIONS']) )
{
$this->collectAllSectionsElements($productsIdList);
}
if (CCatalogSku::GetInfoByProductIBlock($this->iblockId))
{
$priceElementsListSplitedByType = $this->collectPriceSkuElementsId($productsIdList);
}
else
{
$priceElementsListSplitedByType['SIMPLE_ELEMENTS'] = $productsIdList['ELEMENTS'];
}
$parameters = array(
"select" => array(
'ID',
'PRODUCT_ID',
'CATALOG_GROUP_ID',
'PRICE',
'CURRENCY',
'EXTRA_ID',
'QUANTITY_FROM',
'QUANTITY_TO',
'ELEMENT_NAME' => 'ELEMENT.NAME',
'ELEMENT_IBLOCK_ID' => 'ELEMENT.IBLOCK_ID'
),
"filter" => $this->initFilterParams(),
'order' => array('PRODUCT_ID' => 'ASC', 'CATALOG_GROUP_ID' => 'ASC')
);
$group = CatalogGroupTable::getList(array(
'select' => array('ID'),
'filter' => array('=BASE'=>'Y')
))->fetch();
$basePriceId = (!empty($group) ? (int)$group['ID'] : 0);
unset($group);
$initialType = 0;
if (isset($this->userDialogParams['INITIAL_PRICE_TYPE']))
{
$id = (int)$this->userDialogParams['INITIAL_PRICE_TYPE'];
if ($id > 0)
$initialType = $id;
unset($id);
}
$targetType = 0;
if (isset($this->userDialogParams['PRICE_TYPE']))
{
$id = (int)$this->userDialogParams['PRICE_TYPE'];
if ($id > 0)
$targetType = $id;
unset($id);
}
if ($targetType == 0)
return $result;
if ($initialType > 0 && $targetType == $initialType)
return $result;
CatalogProductSku::enableDeferredCalculation();
foreach ($priceElementsListSplitedByType as $typeElements => $priceElementsIdList)
{
$priceElementsIdList = array_chunk($priceElementsIdList, 500);
foreach ($priceElementsIdList as $productIdList)
{
$parameters['filter']['@PRODUCT_ID'] = $productIdList;
$cpriceResult = CatalogModelPrice::getList($parameters);
$elementsCPriceList = array();
while ($row = $cpriceResult->fetch())
{
$row['PRODUCT_TYPE_CODE'] = $typeElements;
$productId = (int)$row['PRODUCT_ID'];
if (!isset($elementsCPriceList[$productId]))
$elementsCPriceList[$productId] = array(
'QUANTITY' => array(),
'SIMPLE' => array()
);
$priceType = (int)$row['CATALOG_GROUP_ID'];
if ($row['QUANTITY_FROM'] !== null || $row['QUANTITY_TO'] !== null)
{
$hash = ($row['QUANTITY_FROM'] === null ? 'ZERO' : $row['QUANTITY_FROM']).
'-'.($row['QUANTITY_TO'] === null ? 'INF' : $row['QUANTITY_TO']);
if (!isset($elementsCPriceList[$productId]['QUANTITY'][$hash]))
$elementsCPriceList[$productId]['QUANTITY'][$hash] = array();
$elementsCPriceList[$productId]['QUANTITY'][$hash][$priceType] = $row;
unset($hash);
}
else
{
$elementsCPriceList[$productId]['SIMPLE'][$priceType] = $row;
}
}
if (!empty($elementsCPriceList))
{
foreach ($elementsCPriceList as $productId => $prices)
{
foreach ($prices as $key => $data)
{
if (empty($data))
unset($prices[$key]);
}
unset($key, $data);
if (count($prices) !== 1)
continue;
if (!empty($prices['QUANTITY']))
{
foreach ($prices['QUANTITY'] as $hash => $rangePrices)
{
if (!empty($rangePrices))
$this->updatePriceBlock($productId, $rangePrices, $basePriceId);
}
unset($hash, $rangePrices);
}
if (!empty($prices['SIMPLE']))
{
$this->updatePriceBlock($productId, $prices['SIMPLE'], $basePriceId);
}
}
unset($productId, $prices);
}
unset($elementsCPriceList);
}
}
CatalogProductSku::disableDeferredCalculation();
CatalogProductSku::calculate();
CatalogModelPrice::clearCache();
return $result;
}