• Модуль: catalog
  • Путь к файлу: ~/bitrix/modules/catalog/lib/discountcoupon.php
  • Класс: BitrixCatalogDiscountCouponTable
  • Вызов: DiscountCouponTable::checkCoupon
static function checkCoupon($value, $primary, array $row, MainEntityField $field)
{
	$value = trim((string)$value);
	if ($value == '')
		return Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_COUPON_EMPTY');

	if (self::$existCouponsManager === null)
		self::initUseMode();
	if (self::$existCouponsManager)
	{
		$existCoupon = SaleDiscountCouponsManager::isExist($value);
		if (!empty($existCoupon))
		{
			$currentId = (int)(is_array($primary) ? $primary['ID'] : $primary);
			if ($existCoupon['MODULE'] != 'catalog' || $currentId != $existCoupon['ID'])
				return Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_COUPON_EXIST');
		}
	}
	else
	{
		$currentId = (int)(is_array($primary) ? $primary['ID'] : $primary);
		$couponIterator = self::getList(array(
			'select' => array('ID'),
			'filter' => array('=COUPON' => $value, '!=ID' => $currentId),
			'limit' => 1
		));
		if ($existCoupon = $couponIterator->fetch())
			return Loc::getMessage('DISCOUNT_COUPON_VALIDATOR_COUPON_EXIST');
	}
	return true;
}