• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/internals/discountentities.php
  • Класс: BitrixSaleInternalsDiscountEntitiesTable
  • Вызов: DiscountEntitiesTable::updateByDiscount
static function updateByDiscount($discount, $entityList, $clear)
{
	$discount = (int)$discount;
	if ($discount <= 0)
		return false;
	$clear = ($clear === true);
	if ($clear)
	{
		self::deleteByDiscount($discount);
	}
	if (!empty($entityList) && is_array($entityList))
	{
		foreach ($entityList as &$entity)
		{
			$fields = array(
				'DISCOUNT_ID' => $discount,
				'MODULE_ID' => $entity['MODULE'],
				'ENTITY' => $entity['ENTITY'],
				'FIELD_ENTITY' => $entity['FIELD_ENTITY'],
			);
			if (is_array($fields['FIELD_ENTITY']))
				$fields['FIELD_ENTITY'] = implode('-', $fields['FIELD_ENTITY']);
			if (isset($entity['FIELD_TABLE']) && is_array($entity['FIELD_TABLE']))
			{
				foreach ($entity['FIELD_TABLE'] as $oneField)
				{
					if (empty($oneField))
						continue;
					$fields['FIELD_TABLE'] = $oneField;
					$result = self::add($fields);
				}
				unset($oneField);
			}
			else
			{
				$fields['FIELD_TABLE'] = (isset($entity['FIELD_TABLE']) ? $entity['FIELD_TABLE'] : $entity['FIELD_ENTITY']);
				$result = self::add($fields);
			}
		}
		unset($entity);
	}
	return true;
}