Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
bypaysystem.php
1<?php
3
11
12Loc::loadMessages(__FILE__);
13
18class ByPaySystem extends Base
19{
20 public static $easeSort = 200;
21 protected static $preparedData = array();
22
23 public static function getClassTitle()
24 {
25 return Loc::getMessage("SALE_DLVR_RSTR_BY_PAYSYSTEM_NAME");
26 }
27
28 public static function getClassDescription()
29 {
30 return Loc::getMessage("SALE_DLVR_RSTR_BY_PAYSYSTEM_DESCRIPT");
31 }
32
33 public static function check($paySystemIds, array $restrictionParams, $deliveryId = 0)
34 {
35 if(intval($deliveryId) <= 0)
36 return true;
37
38 if(empty($paySystemIds))
39 return true;
40
41 $paySystems = self::getPaySystemsByDeliveryId($deliveryId);
42
43 if(empty($paySystems))
44 return true;
45
46 $diff = array_diff($paySystemIds, $paySystems);
47
48 return empty($diff);
49 }
50
51 protected static function extractParams(Entity $entity)
52 {
53 $result = array();
54
55 if ($entity instanceof CollectableEntity)
56 {
58 $collection = $entity->getCollection();
59
61 $order = $collection->getOrder();
62 }
63 elseif ($entity instanceof Order)
64 {
66 $order = $entity;
67 }
68
69 if (!$order)
70 return $result;
71
73 foreach($order->getPaymentCollection() as $payment)
74 {
75 $paySystemId = $payment->getPaymentSystemId();
76 if ($paySystemId)
77 $result[] = $paySystemId;
78 }
79
80 return $result;
81 }
82
83 protected static function getPaySystemsList(): array
84 {
85 static $result = null;
86
87 if ($result !== null)
88 {
89 return $result;
90 }
91
92 $result = [];
93
94 $iterator = PaySystem\Manager::getList([
95 'select' => [
96 'ID',
97 'NAME',
98 'SORT',
99 ],
100 'filter' => [
101 '=ACTIVE' => 'Y',
102 ],
103 'order' => ['SORT' => 'ASC', 'NAME' => 'ASC']
104 ]);
105 while ($row = $iterator->fetch())
106 {
107 $result[$row['ID']] = htmlspecialcharsbx($row['NAME']);
108 }
109
110 return $result;
111 }
112
113 public static function getParamsStructure($entityId = 0)
114 {
115 $result = array(
116 "PAY_SYSTEMS" => array(
117 "TYPE" => "ENUM",
118 'MULTIPLE' => 'Y',
119 "LABEL" => Loc::getMessage("SALE_DLVR_RSTR_BY_PAYSYSTEM_PRM_PS"),
120 "OPTIONS" => self::getPaySystemsList()
121 )
122 );
123
124 return $result;
125 }
126
127 protected static function getPaySystemsByDeliveryId($deliveryId = 0)
128 {
129 if($deliveryId == 0)
130 return array();
131
132 $result = DeliveryPaySystemTable::getLinks($deliveryId, DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY, self::$preparedData);
133 return $result;
134 }
135
136 protected static function prepareParamsForSaving(array $params = array(), $deliveryId = 0)
137 {
138 if(intval($deliveryId) <= 0)
139 return $params;
140
141 if(isset($params["PAY_SYSTEMS"]) && is_array($params["PAY_SYSTEMS"]))
142 {
144 $deliveryId,
146 $params["PAY_SYSTEMS"],
147 true
148 );
149
150 unset($params["PAY_SYSTEMS"]);
151 }
152
153 return $params;
154 }
155
156 public static function save(array $fields, $restrictionId = 0)
157 {
158 $params = $fields["PARAMS"];
159 $fields["PARAMS"] = array();
160
161 $result = parent::save($fields, $restrictionId);
162
163 self::prepareParamsForSaving($params, $fields["SERVICE_ID"]);
164 return $result;
165 }
166
167 public static function prepareParamsValues(array $paramsValues, $deliveryId = 0)
168 {
169 $result = array();
170
171 if(intval($deliveryId > 0))
173
174 return array("PAY_SYSTEMS" => $result);
175 }
176
177 public static function delete($restrictionId, $deliveryId = 0)
178 {
180 $deliveryId,
182 array(),
183 true
184 );
185
186 return parent::delete($restrictionId);
187 }
188
189 public static function prepareData(array $deliveryIds)
190 {
191 if(empty($deliveryIds))
192 return;
193
194 self::$preparedData = \Bitrix\Sale\Internals\DeliveryPaySystemTable::prepareData($deliveryIds, DeliveryPaySystemTable::ENTITY_TYPE_DELIVERY);
195 }
196}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static check($paySystemIds, array $restrictionParams, $deliveryId=0)
static prepareParamsValues(array $paramsValues, $deliveryId=0)
static save(array $fields, $restrictionId=0)
static prepareParamsForSaving(array $params=array(), $deliveryId=0)
static setLinks($entityId, $entityType, array $linkedIds=array(), $actualizeRestrictions=true)
static getLinks($entityId, $entityType, array $preparedData=array(), $considerParent=true)