2namespace Bitrix\Catalog;
5use Bitrix\Main\Application;
6use Bitrix\Main\Localization\Loc;
9Loc::loadMessages(__FILE__);
65 return 'b_catalog_discount_coupon';
78 'autocomplete' =>
true,
79 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_ID_FIELD')
83 'validation' =>
array(__CLASS__,
'validateDiscountId'),
84 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_DISCOUNT_ID_FIELD')
87 'values' =>
array(
'N',
'Y'),
88 'default_value' =>
'Y',
89 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_ACTIVE_FIELD')
93 'validation' =>
array(__CLASS__,
'validateCoupon'),
94 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_COUPON_FIELD')
97 'default_value' =>
null,
98 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_DATE_APPLY_FIELD')
101 'column_name' =>
'ONE_TIME',
102 'values' =>
array(self::TYPE_ONE_ROW, self::TYPE_ONE_ORDER, self::TYPE_NO_LIMIT),
103 'default_value' => self::TYPE_ONE_ORDER,
104 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_ONE_TIME_FIELD')
107 'default_value' =>
function()
111 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_TIMESTAMP_X_FIELD')
113 'MODIFIED_BY' =>
new Main\Entity\IntegerField(
'MODIFIED_BY',
array(
114 'default_value' =>
null,
115 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_MODIFIED_BY_FIELD')
117 'DATE_CREATE' =>
new Main\Entity\DatetimeField(
'DATE_CREATE',
array(
118 'default_value' =>
function()
122 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_DATE_CREATE_FIELD')
125 'default_value' =>
null,
126 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_CREATED_BY_FIELD')
128 'DESCRIPTION' =>
new Main\Entity\TextField(
'DESCRIPTION',
array(
129 'default_value' =>
null,
130 'title' => Loc::getMessage(
'DISCOUNT_COUPON_ENTITY_DESCRIPTION_FIELD')
132 'CREATED_BY_USER' =>
new Main\Entity\ReferenceField(
135 array(
'=this.CREATED_BY' =>
'ref.ID')
137 'MODIFIED_BY_USER' =>
new Main\Entity\ReferenceField(
140 array(
'=this.MODIFIED_BY' =>
'ref.ID')
142 'DISCOUNT' =>
new Main\Entity\ReferenceField(
144 '\Bitrix\Catalog\Discount',
145 array(
'=this.DISCOUNT_ID' =>
'ref.ID'),
146 array(
'join_type' =>
'LEFT')
159 array(__CLASS__,
'checkDiscountId')
172 array(__CLASS__,
'checkCoupon')
187 if ((
int)$value <= 0)
188 return Loc::getMessage(
'DISCOUNT_COUPON_VALIDATOR_DISCOUNT_ID');
204 $value = trim((
string)$value);
206 return Loc::getMessage(
'DISCOUNT_COUPON_VALIDATOR_COUPON_EMPTY');
208 if (self::$existCouponsManager ===
null)
210 if (self::$existCouponsManager)
213 if (!empty($existCoupon))
215 $currentId = (int)(is_array($primary) ? $primary[
'ID'] : $primary);
216 if ($existCoupon[
'MODULE'] !=
'catalog' || $currentId != $existCoupon[
'ID'])
217 return Loc::getMessage(
'DISCOUNT_COUPON_VALIDATOR_COUPON_EXIST');
222 $currentId = (int)(is_array($primary) ? $primary[
'ID'] : $primary);
224 'select' =>
array(
'ID'),
225 'filter' =>
array(
'=COUPON' => $value,
'!=ID' => $currentId),
229 return Loc::getMessage(
'DISCOUNT_COUPON_VALIDATOR_COUPON_EXIST');
242 $result =
new Main\Entity\EventResult;
245 $modifyFieldList =
array();
249 if (!empty($modifyFieldList))
250 $result->modifyFields($modifyFieldList);
251 unset($modifyFieldList);
264 $result =
new Main\Entity\EventResult;
267 $modifyFieldList =
array();
271 if (!empty($modifyFieldList))
272 $result->modifyFields($modifyFieldList);
273 unset($modifyFieldList);
290 $helper = $conn->getSqlHelper();
292 'delete from '.$helper->quote(self::getTableName()).
' where '.$helper->quote(
'DISCOUNT_ID').
' = '.
$discount
294 unset($helper, $conn);
305 if (self::$existCouponsManager ===
null)
307 if (!self::$existCouponsManager)
315 Main\EventResult::SUCCESS,
317 'mode' =>
Sale\DiscountCouponsManager::COUPON_MODE_SIMPLE,
318 'getData' =>
array(
'\Bitrix\Catalog\DiscountCouponTable',
'getData'),
319 'isExist' =>
array(
'\Bitrix\Catalog\DiscountCouponTable',
'isExist'),
320 'saveApplied' =>
array(
'\Bitrix\Catalog\DiscountCouponTable',
'saveApplied'),
336 if (self::$existCouponsManager ===
null)
339 $coupon = trim($coupon);
345 'ID',
'COUPON',
'DISCOUNT_ID',
'TYPE',
'ACTIVE',
346 'DISCOUNT_NAME' =>
'DISCOUNT.NAME',
'DISCOUNT_ACTIVE' =>
'DISCOUNT.ACTIVE',
347 'DISCOUNT_ACTIVE_FROM' =>
'DISCOUNT.ACTIVE_FROM',
'DISCOUNT_ACTIVE_TO' =>
'DISCOUNT.ACTIVE_TO'
349 'filter' =>
array(
'=COUPON' => $coupon)
353 if (!empty($existCoupon))
355 if (!empty(self::$types))
357 $existCoupon[
'TYPE'] = (
358 isset(self::$types[$existCoupon[
'TYPE']])
359 ? self::$types[$existCoupon[
'TYPE']]
376 $coupon = trim($coupon);
381 'select' =>
array(
'ID',
'COUPON'),
382 'filter' =>
array(
'=COUPON' => $coupon)
386 if (!empty($existCoupon))
389 'ID' => $existCoupon[
'ID'],
390 'COUPON' => $existCoupon[
'COUPON'],
391 'MODULE' =>
'catalog'
407 $currentTimestamp = $currentTime->getTimestamp();
410 if (!is_array($coupons))
411 $coupons =
array($coupons);
418 $deactivateCoupons =
array();
419 $multiCoupons =
array();
422 'ID',
'COUPON',
'DISCOUNT_ID',
'TYPE',
'ACTIVE',
423 'DISCOUNT_ACTIVE' =>
'DISCOUNT.ACTIVE',
424 'DISCOUNT_ACTIVE_FROM' =>
'DISCOUNT.ACTIVE_FROM',
'DISCOUNT_ACTIVE_TO' =>
'DISCOUNT.ACTIVE_TO'
426 'filter' =>
array(
'@ID' => $coupons,
'=ACTIVE' =>
'Y'),
427 'order' =>
array(
'ID' =>
'ASC')
431 if ($existCoupon[
'DISCOUNT_ACTIVE'] !=
'Y')
434 ($existCoupon[
'DISCOUNT_ACTIVE_FROM'] instanceof
Main\
Type\
DateTime && $existCoupon[
'DISCOUNT_ACTIVE_FROM']->getTimestamp() > $currentTimestamp)
436 ($existCoupon[
'DISCOUNT_ACTIVE_TO'] instanceof
Main\
Type\
DateTime && $existCoupon[
'DISCOUNT_ACTIVE_TO']->getTimestamp() < $currentTimestamp)
441 $existCoupon[
'TYPE'] == self::TYPE_ONE_ROW
442 || $existCoupon[
'TYPE'] == self::TYPE_ONE_ORDER
445 $deactivateCoupons[$existCoupon[
'COUPON']] = $existCoupon[
'ID'];
449 $multiCoupons[$existCoupon[
'COUPON']] = $existCoupon[
'ID'];
453 if (!empty($deactivateCoupons) || !empty($multiCoupons))
455 $conn = Application::getConnection();
456 $helper = $conn->getSqlHelper();
457 $tableName = $helper->quote(self::getTableName());
458 if (!empty($deactivateCoupons))
461 'update '.$tableName.
' set '.$helper->quote(
'ACTIVE').
' = \'N\', '.$helper->quote(
'DATE_APPLY').
' = '.$helper->getCurrentDateTimeFunction().
462 ' where '.$helper->quote(
'ID').
' in ('.implode(
',', $deactivateCoupons).
')'
465 if (!empty($multiCoupons))
468 'update '.$tableName.
' set '.$helper->quote(
'DATE_APPLY').
' = '.$helper->getCurrentDateTimeFunction().
469 ' where '.$helper->quote(
'ID').
' in ('.implode(
',', $multiCoupons).
')'
472 unset($tableName, $helper);
475 'DEACTIVATE' => $deactivateCoupons,
476 'INCREMENT' => $multiCoupons
488 $extendedMode = ($extendedMode ===
true);
492 self::TYPE_ONE_ROW => Loc::getMessage(
'DISCOUNT_COUPON_TABLE_TYPE_ONE_ROW'),
493 self::TYPE_ONE_ORDER => Loc::getMessage(
'DISCOUNT_COUPON_TABLE_TYPE_ONE_ORDER'),
494 self::TYPE_NO_LIMIT => Loc::getMessage(
'DISCOUNT_COUPON_TABLE_TYPE_NO_LIMIT')
497 return array(self::TYPE_ONE_ROW, self::TYPE_ONE_ORDER, self::TYPE_NO_LIMIT);
507 if (self::$existCouponsManager ===
null)
519 if (self::$existCouponsManager ===
null)
521 if (!self::$existCouponsManager)
523 self::$types =
array(
524 self::TYPE_ONE_ROW =>
Sale\
Internals\DiscountCouponTable::TYPE_BASKET_ROW,
526 self::TYPE_NO_LIMIT =>
Sale\
Internals\DiscountCouponTable::TYPE_MULTI_ORDER
528 self::$typeUnknown =
$event->getParameter(
'COUPON_UNKNOWN');
541 static $currentUserID =
false;
542 if ($currentUserID ===
false)
545 $currentUserID = (isset(
$USER) &&
$USER instanceof \CUser ? (int)
$USER->getID() :
null);
547 foreach ($keys as &$oneKey)
550 if (array_key_exists($oneKey,
$data))
551 $setField = (
$data[$oneKey] !==
null && (int)
$data[$oneKey] <= 0);
554 $result[$oneKey] = $currentUserID;
569 foreach ($keys as &$oneKey)
572 if (array_key_exists($oneKey,
$data))
573 $setField = (
$data[$oneKey] !==
null && !is_object(
$data[$oneKey]));
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static checkCoupon($value, $primary, array $row, Main\Entity\Field $field)
static getCouponTypes($extendedMode=false)
static deleteByDiscount($discount)
static setUserID(&$result, $data, $keys)
static onBeforeAdd(Main\Entity\Event $event)
static setTimestamp(&$result, $data, $keys)
static $existCouponsManager
static validateDiscountId()
static initTypes(Main\Event $event)
static couponManager(Main\Event $event)
static onBeforeUpdate(Main\Entity\Event $event)
static saveApplied($coupons, $userId, Main\Type\DateTime $currentTime)
static checkDiscountId($value, $primary, array $row, Main\Entity\Field $field)
static getConnection($name="")
static includeModule($moduleName)
static isModuleInstalled($moduleName)
static normalizeArrayValuesByInt(&$map, $sorted=true)
if($usePageNavigation) $couponIterator
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)