Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
concreteproductrestriction.php
1<?php
2
4
7use \Bitrix\Main\Localization\Loc;
9
10Loc::loadMessages(__FILE__);
11
18{
24 abstract protected static function getJsHandler() : string;
25
31 abstract protected static function getBasketItems(Entity $entity) : array;
32
33
40 public static function extractParams(Entity $entity) : array
41 {
42 $basketItems = static::getBasketItems($entity);
43 $productIds = [];
44
46 foreach ($basketItems as $basketItem)
47 {
48 if ($basketItem->getField('MODULE') != 'catalog')
49 {
50 continue;
51 }
52
53 $productIds[] = (int)$basketItem->getField('PRODUCT_ID');
54 }
55
56 return $productIds;
57 }
58
63 public static function getClassTitle() : string
64 {
65 return Loc::getMessage("SALE_BASE_RESTRICTION_BY_PRODUCT");
66 }
67
68 public static function getOnApplyErrorMessage(): string
69 {
70 return Loc::getMessage('SALE_BASE_RESTRICTION_BY_PRODUCT_ON_APPLY_ERROR_MSG');
71 }
72
81 public static function check($basketItemsIds, array $restrictionParams, $serviceId = 0) : bool
82 {
83 if (
84 empty($basketItemsIds)
85 || !is_array($basketItemsIds)
86 || empty($restrictionParams["PRODUCTS"])
87 || !is_array($restrictionParams["PRODUCTS"])
88 )
89 {
90 return true;
91 }
92
93 $allowedItemsIds = $restrictionParams['PRODUCTS'];
94
95 $productsListSize = count($basketItemsIds);
96 for ($i = 0; $i < $productsListSize; $i++)
97 {
98 if (!in_array($basketItemsIds[$i], $allowedItemsIds))
99 {
100 return false;
101 }
102 }
103
104 return true;
105 }
106
112 public static function getParamsStructure($entityId = 0) : array
113 {
114 return [
115 "PRODUCTS" => [
116 "TYPE" => "CONCRETE_PRODUCT",
117 "JS_HANDLER" => static::getJsHandler(),
118 "FORM_NAME" => "PRODUCTS_IDS",
119 "LABEL" => Loc::getMessage("SALE_BASE_RESTRICTION_BY_PRODUCT_LST_LABEL"),
120 "ID" => 'sale-admin-concrete-product-restriction',
121 ],
122 ];
123 }
124}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static check($basketItemsIds, array $restrictionParams, $serviceId=0)
static extractParams(Entity $entity)