Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
delivery.php
1<?php
3
15
16Loc::loadMessages(__FILE__);
17
22class Delivery extends Restriction
23{
24 public static $easeSort = 200;
25 protected static $preparedData = array();
26
30 public static function getClassTitle()
31 {
32 return Loc::getMessage("SALE_SRV_RSTR_BY_DELIVERY_NAME");
33 }
34
38 public static function getClassDescription()
39 {
40 return Loc::getMessage("SALE_SRV_RSTR_BY_DELIVERY_DESC");
41 }
42
43 public static function getOnApplyErrorMessage(): string
44 {
45 return Loc::getMessage('SALE_SRV_RSTR_BY_DELIVERY_ON_APPLY_ERROR_MSG');
46 }
47
54 public static function check($params, array $restrictionParams, $serviceId = 0)
55 {
56 if(intval($serviceId) <= 0)
57 return true;
58
59 if(empty($params))
60 return true;
61
62 $deliveries = self::getDeliveryByPaySystemsId($serviceId);
63
64 if(empty($deliveries))
65 return true;
66
67 $diff = array_diff($params, $deliveries);
68
69 return empty($diff);
70 }
71
76 protected static function extractParams(Entity $entity)
77 {
78 $shipmentCollection = null;
79 $result = array();
80
81 if ($entity instanceof Payment)
82 {
84 $paymentCollection = $entity->getCollection();
85
87 $order = $paymentCollection->getOrder();
88
90 $shipmentCollection = $order->getShipmentCollection();
91
92 }
93 elseif ($entity instanceof Order)
94 {
95 $shipmentCollection = $entity->getShipmentCollection();
96 }
97
98 if ($shipmentCollection)
99 {
101 foreach ($shipmentCollection as $shipment)
102 {
103 if (!$shipment->isSystem())
104 {
105 $deliveryId = $shipment->getDeliveryId();
106 if ($deliveryId)
107 $result[] = $deliveryId;
108 }
109 }
110 }
111
112 return $result;
113 }
114
118 protected static function getDeliveryServiceList()
119 {
120 static $result = null;
121
122 if ($result !== null)
123 return $result;
124
125 $serviceList = array();
126 $dbRes = Services\Table::getList(array('select' => array('ID', 'NAME', 'PARENT_ID', 'CLASS_NAME')));
127 while ($service = $dbRes->fetch())
128 $serviceList[$service['ID']] = $service;
129
130 foreach ($serviceList as $service)
131 {
132 if (is_callable($service['CLASS_NAME'].'::canHasChildren') && $service['CLASS_NAME']::canHasChildren())
133 continue;
134
135 if ((int)$service['PARENT_ID'] > 0 && array_key_exists($service['PARENT_ID'], $serviceList))
136 {
137 $parentService = $serviceList[$service['PARENT_ID']];
138
139 if (is_callable($parentService['CLASS_NAME'].'::canHasChildren') && $parentService['CLASS_NAME']::canHasChildren())
140 $name = $service['NAME'].' ['.$service['ID'].']';
141 else
142 $name = $parentService['NAME'].': '.$service['NAME'].' ['.$service['ID'].']';
143 }
144 else
145 {
146 $name = $service['NAME'].' ['.$service['ID'].']';
147 }
148
149 $result[$service['ID']] = $name;
150 }
151
152 return $result;
153 }
154
159 public static function getParamsStructure($entityId = 0)
160 {
161 $result = array(
162 "DELIVERY" => array(
163 "TYPE" => "ENUM",
164 'MULTIPLE' => 'Y',
165 "LABEL" => Loc::getMessage("SALE_SRV_RSTR_BY_DELIVERY_PRM_PS"),
166 "OPTIONS" => self::getDeliveryServiceList()
167 )
168 );
169
170 return $result;
171 }
172
178 protected static function getDeliveryByPaySystemsId($paySystemId = 0)
179 {
180 if ($paySystemId == 0)
181 return array();
182
183 $result = DeliveryPaySystemTable::getLinks($paySystemId, DeliveryPaySystemTable::ENTITY_TYPE_PAYSYSTEM, self::$preparedData);
184 return $result;
185 }
186
194 protected static function prepareParamsForSaving(array $params = array(), $paySystemId = 0)
195 {
196 if(intval($paySystemId) <= 0)
197 return $params;
198
199 if(isset($params["DELIVERY"]) && is_array($params["DELIVERY"]))
200 {
202 $paySystemId,
204 $params["DELIVERY"],
205 true
206 );
207
208 unset($params["DELIVERY"]);
209 }
210
211 return $params;
212 }
213
219 public static function save(array $fields, $restrictionId = 0)
220 {
221 $params = $fields["PARAMS"];
222 $fields["PARAMS"] = array();
223
224 $result = parent::save($fields, $restrictionId);
225
226 self::prepareParamsForSaving($params, $fields["SERVICE_ID"]);
227 return $result;
228 }
229
235 public static function prepareParamsValues(array $paramsValues, $entityId = 0)
236 {
237 return array("DELIVERY" => self::getDeliveryByPaySystemsId($entityId));
238 }
239
247 public static function delete($restrictionId, $entityId = 0)
248 {
250 $entityId,
252 array(),
253 true
254 );
255
256 return parent::delete($restrictionId);
257 }
258
263 public static function prepareData(array $servicesIds)
264 {
265 if(empty($servicesIds))
266 return;
267
269 }
270}
static loadMessages($file)
Definition loc.php:64
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29
static setLinks($entityId, $entityType, array $linkedIds=array(), $actualizeRestrictions=true)
static prepareData(array $entityIds, $entityType)
static getLinks($entityId, $entityType, array $preparedData=array(), $considerParent=true)
static prepareParamsValues(array $paramsValues, $entityId=0)
Definition delivery.php:235
static check($params, array $restrictionParams, $serviceId=0)
Definition delivery.php:54
static prepareParamsForSaving(array $params=array(), $paySystemId=0)
Definition delivery.php:194
static save(array $fields, $restrictionId=0)
Definition delivery.php:219