• Модуль: sale
  • Путь к файлу: ~/bitrix/modules/sale/lib/discountcouponsmanagerbase.php
  • Класс: BitrixSaleDiscountCouponsManagerBase
  • Вызов: DiscountCouponsManagerBase::setApplyByProduct
static function setApplyByProduct($product, $couponsList, $oldMode = false)
{
	static $count = null;
	if ($count === null)
		$count = 0;
	if (self::$useMode == self::MODE_SYSTEM)
		return false;
	if (empty($couponsList) || empty($product))
		return false;
	$oldMode = ($oldMode === true);
	if ($oldMode)
	{
		if (!isset($product['BASKET_ID']))
			$product['BASKET_ID'] = 'c'.$count;
		$count++;
	}
	$hash = ($oldMode ? self::getCatalogProductHash($product) : self::getProductHash($product));

	if ($hash === '')
		return false;
	$applyed = false;
	$applyList = array();
	foreach ($couponsList as $coupon)
	{
		$coupon = trim((string)$coupon);
		if ($coupon === '' || !isset(self::$coupons[$coupon]))
			continue;
		if (self::$coupons[$coupon]['STATUS'] == self::STATUS_NOT_FOUND || self::$coupons[$coupon]['STATUS'] == self::STATUS_FREEZE)
			continue;
		if (self::$coupons[$coupon]['TYPE'] == InternalsDiscountCouponTable::TYPE_BASKET_ROW && !empty(self::$coupons[$coupon]['BASKET']))
			continue;
		self::$coupons[$coupon]['BASKET'][$hash] = true;
		self::$coupons[$coupon]['STATUS'] = self::STATUS_APPLYED;
		$applyed = true;
		$applyList[$coupon] = self::$coupons[$coupon];
	}
	unset($coupon);
	if ($applyed)
	{
		$event = new MainEvent(
			'sale',
			self::EVENT_ON_COUPON_APPLY_PRODUCT,
			array(
				'PRODUCT' => $product,
				'COUPONS' => $applyList
			)
		);
		$event->send();
	}
	unset($applyList);
	return $applyed;
}