1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
discount_coupon.php
См. документацию.
1<?php
2
8
10{
11 public const TYPE_ONE_TIME = 'Y';
12 public const TYPE_ONE_ORDER = 'O';
13 public const TYPE_NO_LIMIT = 'N';
14
15 protected static $arOneOrderCoupons = array();
16 protected static $existCouponsManager = null;
17
25 public static function GetCoupontTypes($boolFull = false)
26 {
28 }
29
30 public static function CheckFields($ACTION, &$arFields, $ID = 0)
31 {
32 global $DB, $APPLICATION, $USER;
33
34 $ACTION = mb_strtoupper($ACTION);
35 if ('UPDATE' != $ACTION && 'ADD' != $ACTION)
36 return false;
37
38 if (self::$existCouponsManager === null)
40
41 $clearFields = array(
42 'ID',
43 '~ID',
44 '~COUPON',
45 'TIMESTAMP_X',
46 'DATE_CREATE',
47 '~DATE_CREATE',
48 '~MODIFIED_BY',
49 '~CREATED_BY'
50 );
51 if ($ACTION =='UPDATE')
52 $clearFields[] = 'CREATED_BY';
53
54 foreach ($clearFields as &$fieldName)
55 {
56 if (array_key_exists($fieldName, $arFields))
57 unset($arFields[$fieldName]);
58 }
59 unset($fieldName, $clearFields);
60
61 if ((is_set($arFields, "DISCOUNT_ID") || $ACTION=="ADD") && intval($arFields["DISCOUNT_ID"]) <= 0)
62 {
63 $APPLICATION->ThrowException(Loc::getMessage("KGDC_EMPTY_DISCOUNT"), "EMPTY_DISCOUNT_ID");
64 return false;
65 }
66
67 if ((is_set($arFields, "COUPON") || $ACTION=="ADD") && $arFields["COUPON"] == '')
68 {
69 $APPLICATION->ThrowException(Loc::getMessage("KGDC_EMPTY_COUPON"), "EMPTY_COUPON");
70 return false;
71 }
72 elseif(is_set($arFields, "COUPON"))
73 {
74 $currentId = ($ACTION == 'UPDATE' ? $ID : 0);
75 $arFields['COUPON'] = mb_substr($arFields['COUPON'], 0, 32);
76 if (self::$existCouponsManager)
77 {
78 $existCoupon = DiscountCouponsManager::isExist($arFields['COUPON']);
79 if (!empty($existCoupon))
80 {
81 if ($existCoupon['MODULE'] != 'catalog' || $currentId != $existCoupon['ID'])
82 {
83 $APPLICATION->ThrowException(Loc::getMessage("KGDC_DUPLICATE_COUPON"), "DUPLICATE_COUPON");
84 return false;
85 }
86 }
87 }
88 else
89 {
90 $couponIterator = Catalog\DiscountCouponTable::getList(array(
91 'select' => array('ID', 'COUPON'),
92 'filter' => array('=COUPON' => $arFields['COUPON'])
93 ));
94 if ($existCoupon = $couponIterator->fetch())
95 {
96 if ($currentId != (int)$existCoupon['ID'])
97 {
98 $APPLICATION->ThrowException(Loc::getMessage("KGDC_DUPLICATE_COUPON"), "DUPLICATE_COUPON");
99 return false;
100 }
101 }
102 }
103 }
104
105 if ((is_set($arFields, "ACTIVE") || $ACTION=="ADD") && $arFields["ACTIVE"] != "N")
106 $arFields["ACTIVE"] = "Y";
107 if ((is_set($arFields, "ONE_TIME") || $ACTION=="ADD") && !in_array($arFields["ONE_TIME"], Catalog\DiscountCouponTable::getCouponTypes()))
108 $arFields["ONE_TIME"] = self::TYPE_ONE_TIME;
109
110 if ((is_set($arFields, "DATE_APPLY") || $ACTION=="ADD") && (!$DB->IsDate($arFields["DATE_APPLY"], false, SITE_ID, "FULL")))
111 $arFields["DATE_APPLY"] = false;
112
113 $intUserID = 0;
114 $boolUserExist = CCatalog::IsUserExists();
115 if ($boolUserExist)
116 $intUserID = (int)$USER->GetID();
117 $strDateFunction = $DB->GetNowFunction();
118 $arFields['~TIMESTAMP_X'] = $strDateFunction;
119 if ($boolUserExist)
120 {
121 if (!array_key_exists('MODIFIED_BY', $arFields) || intval($arFields["MODIFIED_BY"]) <= 0)
122 $arFields["MODIFIED_BY"] = $intUserID;
123 }
124 if ('ADD' == $ACTION)
125 {
126 $arFields['~DATE_CREATE'] = $strDateFunction;
127 if ($boolUserExist)
128 {
129 if (!array_key_exists('CREATED_BY', $arFields) || intval($arFields["CREATED_BY"]) <= 0)
130 $arFields["CREATED_BY"] = $intUserID;
131 }
132 }
133
134 return true;
135 }
136
145 public static function DeleteByDiscountID($ID, $bAffectDataFile = true)
146 {
147 $ID = (int)$ID;
148 if ($ID <= 0)
149 return false;
151 return true;
152 }
153
161 public static function SetCoupon($coupon)
162 {
163 if (self::$existCouponsManager === null)
165
166 if (self::$existCouponsManager)
167 {
169 {
170 return DiscountCouponsManager::add($coupon);
171 }
172 return false;
173 }
174 else
175 {
176 $coupon = trim((string)$coupon);
177 if ($coupon === '')
178 return false;
179
180 $session = Application::getInstance()->getSession();
181 if (!$session->isAccessible())
182 {
183 return false;
184 }
185
186 if (!isset($session['CATALOG_USER_COUPONS']) || !is_array($session['CATALOG_USER_COUPONS']))
187 $session['CATALOG_USER_COUPONS'] = array();
188
189 $couponIterator = Catalog\DiscountCouponTable::getList(array(
190 'select' => array('ID', 'COUPON'),
191 'filter' => array('=COUPON' => $coupon, '=ACTIVE' => 'Y')
192 ));
193 if ($existCoupon = $couponIterator->fetch())
194 {
195 if (!in_array($existCoupon['COUPON'], $session['CATALOG_USER_COUPONS']))
196 $session['CATALOG_USER_COUPONS'][] = $existCoupon['COUPON'];
197 return true;
198 }
199 }
200 return false;
201 }
202
207 public static function GetCoupons()
208 {
209 if (self::$existCouponsManager === null)
211
212 if (self::$existCouponsManager)
213 {
215 {
216 return DiscountCouponsManager::get(false, array('MODULE' => 'catalog'), true);
217 }
218 return array();
219 }
220 else
221 {
222 $session = Application::getInstance()->getSession();
223 if (!$session->isAccessible())
224 {
225 return [];
226 }
227
228 if (!isset($session['CATALOG_USER_COUPONS']) || !is_array($session['CATALOG_USER_COUPONS']))
229 $session['CATALOG_USER_COUPONS'] = array();
230 return $session["CATALOG_USER_COUPONS"];
231 }
232 }
233
241 public static function EraseCoupon($strCoupon)
242 {
243 if (self::$existCouponsManager === null)
245 if (self::$existCouponsManager)
246 {
248 {
249 return DiscountCouponsManager::delete($strCoupon);
250 }
251 return false;
252 }
253 else
254 {
255 $strCoupon = trim((string)$strCoupon);
256 if (empty($strCoupon))
257 return false;
258
259 $session = Application::getInstance()->getSession();
260 if (!$session->isAccessible())
261 {
262 return false;
263 }
264
265 if (!isset($session['CATALOG_USER_COUPONS']) || !is_array($session['CATALOG_USER_COUPONS']))
266 {
267 $session['CATALOG_USER_COUPONS'] = array();
268 return true;
269 }
270 $key = array_search($strCoupon, $session['CATALOG_USER_COUPONS']);
271 if ($key !== false)
272 {
273 unset($session['CATALOG_USER_COUPONS'][$key]);
274 }
275 return true;
276 }
277 }
278
283 public static function ClearCoupon()
284 {
285 if (self::$existCouponsManager === null)
287
288 if (self::$existCouponsManager)
289 {
292 }
293 else
294 {
295 $session = Application::getInstance()->getSession();
296 if ($session->isAccessible())
297 {
298 $session['CATALOG_USER_COUPONS'] = array();
299 }
300 }
301 }
302
311 public static function SetCouponByManage($intUserID, $strCoupon)
312 {
313 $intUserID = (int)$intUserID;
314 if ($intUserID >= 0)
315 {
316 if (self::$existCouponsManager === null)
318 if (self::$existCouponsManager)
319 {
321 {
322 return DiscountCouponsManager::add($strCoupon);
323 }
324 return false;
325 }
326 else
327 {
328 $strCoupon = trim((string)$strCoupon);
329 if (empty($strCoupon))
330 return false;
331
332 $session = Application::getInstance()->getSession();
333 if (!$session->isAccessible())
334 {
335 return false;
336 }
337
338 if (!isset($session['CATALOG_MANAGE_COUPONS']) || !is_array($session['CATALOG_MANAGE_COUPONS']))
339 $session['CATALOG_MANAGE_COUPONS'] = array();
340 if (!isset($session['CATALOG_MANAGE_COUPONS'][$intUserID]) || !is_array($session['CATALOG_MANAGE_COUPONS'][$intUserID]))
341 $session['CATALOG_MANAGE_COUPONS'][$intUserID] = array();
342
343 $couponIterator = Catalog\DiscountCouponTable::getList(array(
344 'select' => array('ID', 'COUPON'),
345 'filter' => array('=COUPON' => $strCoupon, '=ACTIVE' => 'Y')
346 ));
347 if ($existCoupon = $couponIterator->fetch())
348 {
349 if (!in_array($existCoupon['COUPON'], $session['CATALOG_MANAGE_COUPONS'][$intUserID]))
350 $session['CATALOG_MANAGE_COUPONS'][$intUserID][] = $existCoupon['COUPON'];
351
352 return true;
353 }
354 }
355 }
356 return false;
357 }
358
366 public static function GetCouponsByManage($intUserID)
367 {
368 $intUserID = (int)$intUserID;
369 if ($intUserID >= 0)
370 {
371 if (self::$existCouponsManager === null)
373 if (self::$existCouponsManager)
374 {
376 {
377 return DiscountCouponsManager::get(false, array('MODULE' => 'catalog'), true);
378 }
379 return false;
380 }
381 else
382 {
383 $session = Application::getInstance()->getSession();
384 if (!$session->isAccessible())
385 {
386 return false;
387 }
388
389 if (!isset($session['CATALOG_MANAGE_COUPONS']) || !is_array($session['CATALOG_MANAGE_COUPONS']))
390 $session['CATALOG_MANAGE_COUPONS'] = array();
391 if (!isset($session['CATALOG_MANAGE_COUPONS'][$intUserID]) || !is_array($session['CATALOG_MANAGE_COUPONS'][$intUserID]))
392 $session['CATALOG_MANAGE_COUPONS'][$intUserID] = array();
393
394 return $session['CATALOG_MANAGE_COUPONS'][$intUserID];
395 }
396 }
397 return false;
398 }
399
408 public static function EraseCouponByManage($intUserID, $strCoupon)
409 {
410 $intUserID = (int)$intUserID;
411 if ($intUserID >= 0)
412 {
413 if (self::$existCouponsManager === null)
415 if (self::$existCouponsManager)
416 {
418 {
419 return DiscountCouponsManager::delete($strCoupon);
420 }
421 return false;
422 }
423 else
424 {
425 $session = Application::getInstance()->getSession();
426 if (!$session->isAccessible())
427 {
428 return false;
429 }
430
431 $strCoupon = trim((string)$strCoupon);
432 if (empty($strCoupon))
433 return false;
434 if (!isset($session['CATALOG_MANAGE_COUPONS']) || !is_array($session['CATALOG_MANAGE_COUPONS']))
435 return false;
436 if (!isset($session['CATALOG_MANAGE_COUPONS'][$intUserID]) || !is_array($session['CATALOG_MANAGE_COUPONS'][$intUserID]))
437 return false;
438 $key = array_search($strCoupon, $session['CATALOG_MANAGE_COUPONS'][$intUserID]);
439 if ($key !== false)
440 {
441 unset($session['CATALOG_MANAGE_COUPONS'][$intUserID][$key]);
442 return true;
443 }
444 }
445 }
446 return false;
447 }
448
456 public static function ClearCouponsByManage($intUserID)
457 {
458 $intUserID = (int)$intUserID;
459 if ($intUserID >= 0)
460 {
461 if (self::$existCouponsManager === null)
463 if (self::$existCouponsManager)
464 {
466 {
468 }
469 return false;
470 }
471 else
472 {
473 $session = Application::getInstance()->getSession();
474 if (!$session->isAccessible())
475 {
476 return false;
477 }
478
479 if (!isset($session['CATALOG_MANAGE_COUPONS']) || !is_array($session['CATALOG_MANAGE_COUPONS']))
480 $session['CATALOG_MANAGE_COUPONS'] = array();
481 $session['CATALOG_MANAGE_COUPONS'][$intUserID] = array();
482 return true;
483 }
484 }
485 return false;
486 }
487
497 public static function OnSetCouponList($intUserID, $arCoupons, $arModules)
498 {
499 global $USER;
500 $boolResult = false;
501 if (
502 empty($arModules)
503 || (is_array($arModules) && in_array('catalog', $arModules))
504 )
505 {
506 if (!empty($arCoupons))
507 {
508 if (!is_array($arCoupons))
509 $arCoupons = array($arCoupons);
510 $intUserID = (int)$intUserID;
511
512 if (self::$existCouponsManager === null)
514 if (self::$existCouponsManager)
515 {
516 if ($intUserID == DiscountCouponsManager::getUserId())
517 {
518 foreach ($arCoupons as &$coupon)
519 {
520 if (DiscountCouponsManager::add($coupon))
521 $boolResult = true;
522 }
523 unset($coupon);
524 return $boolResult;
525 }
526 return false;
527 }
528 else
529 {
530 if ($intUserID > 0)
531 {
532 $boolCurrentUser = ($USER->IsAuthorized() && $intUserID == $USER->GetID());
533 foreach ($arCoupons as &$strOneCoupon)
534 {
535 if (self::SetCouponByManage($intUserID, $strOneCoupon))
536 $boolResult = true;
537 if ($boolCurrentUser)
538 self::SetCoupon($strOneCoupon);
539 }
540 unset($strOneCoupon);
541 }
542 elseif (0 == $intUserID && !$USER->IsAuthorized())
543 {
544 foreach ($arCoupons as &$strOneCoupon)
545 {
546 $couponResult = self::SetCoupon($strOneCoupon);
547 if ($couponResult)
548 $boolResult = true;
549 }
550 unset($strOneCoupon);
551 }
552 }
553 }
554 }
555
556 return $boolResult;
557 }
558
568 public static function OnClearCouponList($intUserID, $arCoupons, $arModules)
569 {
570 global $USER;
571
572 $boolResult = false;
573 if (
574 empty($arModules)
575 || (is_array($arModules) && in_array('catalog', $arModules))
576 )
577 {
578 if (!empty($arCoupons))
579 {
580 if (!is_array($arCoupons))
581 $arCoupons = array($arCoupons);
582 $intUserID = (int)$intUserID;
583
584 if (self::$existCouponsManager === null)
586 if (self::$existCouponsManager)
587 {
588 if ($intUserID == DiscountCouponsManager::getUserId())
589 {
590 foreach ($arCoupons as &$coupon)
591 {
593 $boolResult = true;
594 }
595 unset($coupon);
596 return $boolResult;
597 }
598 return false;
599 }
600 else
601 {
602 if ($intUserID > 0)
603 {
604 $boolCurrentUser = ($USER->IsAuthorized() && $intUserID == $USER->GetID());
605 foreach ($arCoupons as &$strOneCoupon)
606 {
607 if (self::EraseCouponByManage($intUserID, $strOneCoupon))
608 $boolResult = true;
609 if ($boolCurrentUser)
610 self::EraseCoupon($strOneCoupon);
611 }
612 unset($strOneCoupon);
613 }
614 elseif (0 == $intUserID && !$USER->IsAuthorized())
615 {
616 foreach ($arCoupons as &$strOneCoupon)
617 {
618 if (self::EraseCoupon($strOneCoupon))
619 $boolResult = true;
620 }
621 unset($strOneCoupon);
622 }
623 }
624 }
625 }
626 return $boolResult;
627 }
628
636 public static function OnDeleteCouponList($intUserID, $arModules)
637 {
638 global $USER;
639
640 $boolResult = false;
641 if (
642 empty($arModules)
643 || (is_array($arModules) && in_array('catalog', $arModules))
644 )
645 {
646 $intUserID = (int)$intUserID;
647 if (self::$existCouponsManager === null)
649 if (self::$existCouponsManager)
650 {
651 if ($intUserID == DiscountCouponsManager::getUserId())
652 {
654 }
655 return false;
656 }
657 else
658 {
659 if (0 < $intUserID)
660 {
661 $boolCurrentUser = ($USER->IsAuthorized() && $intUserID == $USER->GetID());
662 $boolResult = self::ClearCouponsByManage($intUserID);
663 if ($boolCurrentUser)
665 }
666 elseif (0 == $intUserID && !$USER->IsAuthorized())
667 {
669 }
670 }
671 }
672 return $boolResult;
673 }
674
682 public static function IsExistCoupon($strCoupon)
683 {
684 return false;
685 }
686
687 protected static function initCouponManager()
688 {
689 if (self::$existCouponsManager === null)
690 self::$existCouponsManager = Main\ModuleManager::isModuleInstalled('sale') && Main\Loader::includeModule('sale');
691 }
692}
global $APPLICATION
Определения include.php:80
static getCouponTypes($extendedMode=false)
Определения discountcoupon.php:486
static deleteByDiscount($discount)
Определения discountcoupon.php:284
static getInstance()
Определения application.php:98
static includeModule($moduleName)
Определения loader.php:67
static getMessage($code, $replace=null, $language=null)
Определения loc.php:30
static isModuleInstalled($moduleName)
Определения modulemanager.php:125
static clear($clearStorage=false)
Определения discountcouponsmanagerbase.php:703
static get($extMode=true, $filter=[], $show=false, $final=false)
Определения discountcouponsmanagerbase.php:921
static OnSetCouponList($intUserID, $arCoupons, $arModules)
Определения discount_coupon.php:497
static initCouponManager()
Определения discount_coupon.php:687
static GetCouponsByManage($intUserID)
Определения discount_coupon.php:366
static OnDeleteCouponList($intUserID, $arModules)
Определения discount_coupon.php:636
static EraseCoupon($strCoupon)
Определения discount_coupon.php:241
static DeleteByDiscountID($ID, $bAffectDataFile=true)
Определения discount_coupon.php:145
static ClearCoupon()
Определения discount_coupon.php:283
static CheckFields($ACTION, &$arFields, $ID=0)
Определения discount_coupon.php:30
static SetCoupon($coupon)
Определения discount_coupon.php:161
static EraseCouponByManage($intUserID, $strCoupon)
Определения discount_coupon.php:408
static $existCouponsManager
Определения discount_coupon.php:16
static GetCoupontTypes($boolFull=false)
Определения discount_coupon.php:25
static SetCouponByManage($intUserID, $strCoupon)
Определения discount_coupon.php:311
static ClearCouponsByManage($intUserID)
Определения discount_coupon.php:456
static OnClearCouponList($intUserID, $arCoupons, $arModules)
Определения discount_coupon.php:568
const TYPE_NO_LIMIT
Определения discount_coupon.php:13
static GetCoupons()
Определения discount_coupon.php:207
static IsExistCoupon($strCoupon)
Определения discount_coupon.php:682
static $arOneOrderCoupons
Определения discount_coupon.php:15
const TYPE_ONE_TIME
Определения discount_coupon.php:11
const TYPE_ONE_ORDER
Определения discount_coupon.php:12
static IsUserExists()
Определения catalog.php:1812
$arFields
Определения dblapprove.php:5
if($usePageNavigation) $couponIterator
Определения discount_coupon_list.php:338
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
is_set($a, $k=false)
Определения tools.php:2133
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
const SITE_ID
Определения sonet_set_content_view.php:12