Price::modify

  1. Bitrix24 API (v. 23.675.0)
  2. catalog
  3. Price
  4. modify
  • Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/controller/price.php
  • Класс: BitrixCatalogControllerPrice
  • Вызов: Price::modify
protected function modify($fields)
{
	$ids = [];
	$productId = $fields['PRODUCT']['ID'];
	$prices = $fields['PRODUCT']['PRICES'];

	$r = $this->checkPermissionIBlockElementPriceModify($productId);
	if($r->isSuccess())
	{
		foreach ($prices as $price)
		{
			if(isset($price['ID']))
			{
				self::normalizeFields($price);

				$result = BitrixCatalogModelPrice::update($price['ID'], $price);
				if($result->isSuccess())
				{
					$ids[] = $price['ID'];
				}
			}
			else
			{
				$result = BitrixCatalogModelPrice::add([
					'PRODUCT_ID' => $productId,
					'CATALOG_GROUP_ID' => $price['CATALOG_GROUP_ID'],
					'CURRENCY' => $price['CURRENCY'],
					'PRICE' => $price['PRICE'],
					'QUANTITY_FROM' => isset($price['QUANTITY_FROM']) ? $price['QUANTITY_FROM']:null,
					'QUANTITY_TO' => isset($price['QUANTITY_TO']) ? $price['QUANTITY_TO']:null,
					'EXTRA_ID' => isset($price['EXTRA_ID']) ? $price['EXTRA_ID']:null,
				]);

				if($result->isSuccess())
				{
					$ids[] = $result->getId();
				}
			}

			if($result->isSuccess() == false)
			{
				$r->addErrors($result->getErrors());
			}
		}

		if($r->isSuccess())
			$r->setData([$ids]);
	}

	return $r;
}

Добавить комментарий