Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
shipment.php
1<?php
2
3
5
6
10
11class Shipment extends Base
12{
13 public function getFields()
14 {
15 return [
16 'ID'=>[
17 'TYPE'=>self::TYPE_INT,
18 'ATTRIBUTES'=>[Attributes::ReadOnly]
19 ],
20 'ORDER_ID'=>[
21 'TYPE'=>self::TYPE_INT,
22 'ATTRIBUTES'=>[
25 ]
26 ],
27 'STATUS_ID'=>[
28 'TYPE'=>self::TYPE_CHAR
29 ],
30 'BASE_PRICE_DELIVERY'=>[
31 'TYPE'=>self::TYPE_FLOAT
32 ],
33 'PRICE_DELIVERY'=>[
34 'TYPE'=>self::TYPE_FLOAT
35 ],
36 'ALLOW_DELIVERY'=>[
37 'TYPE'=>self::TYPE_CHAR,
38 'ATTRIBUTES'=>[Attributes::Required]//for builder
39 ],
40 'DATE_ALLOW_DELIVERY'=>[
41 'TYPE'=>self::TYPE_DATETIME,
42 'ATTRIBUTES'=>[Attributes::ReadOnly]
43 ],
44 'EMP_ALLOW_DELIVERY_ID'=>[
45 'TYPE'=>self::TYPE_INT
46 ],
47 'DEDUCTED'=>[
48 'TYPE'=>self::TYPE_CHAR,
49 'ATTRIBUTES'=>[Attributes::Required]//for builder
50 ],
51 'DATE_DEDUCTED'=>[
52 'TYPE'=>self::TYPE_DATETIME,
53 'ATTRIBUTES'=>[Attributes::ReadOnly]
54 ],
55 'EMP_DEDUCTED_ID'=>[
56 'TYPE'=>self::TYPE_INT
57 ],
58 'REASON_UNDO_DEDUCTED'=>[
59 'TYPE'=>self::TYPE_STRING
60 ],
61 'DELIVERY_ID'=>[
62 'TYPE'=>self::TYPE_INT,
63 'ATTRIBUTES'=>[Attributes::Required]//for builder
64 ],
65 'DELIVERY_DOC_NUM'=>[
66 'TYPE'=>self::TYPE_STRING
67 ],
68 'DELIVERY_DOC_DATE'=>[
70 ],
71 'TRACKING_NUMBER'=>[
72 'TYPE'=>self::TYPE_STRING
73 ],
74 'XML_ID'=>[
75 'TYPE'=>self::TYPE_STRING
76 ],
77 'DELIVERY_NAME'=>[
78 'TYPE'=>self::TYPE_STRING,
79 'ATTRIBUTES'=>[Attributes::ReadOnly]
80 ],
81 'COMPANY_ID'=>[
82 'TYPE'=>self::TYPE_INT
83 ],
84 'MARKED'=>[
85 'TYPE'=>self::TYPE_CHAR
86 ],
87 'DATE_MARKED'=>[
88 'TYPE'=>self::TYPE_DATETIME,
89 'ATTRIBUTES'=>[Attributes::ReadOnly]
90 ],
91 'EMP_MARKED_ID'=>[
92 'TYPE'=>self::TYPE_INT
93 ],
94 'REASON_MARKED'=>[
95 'TYPE'=>self::TYPE_STRING
96 ],
97 'CANCELED'=>[
98 'TYPE'=>self::TYPE_CHAR
99 ],
100 'DATE_CANCELED'=>[
101 'TYPE'=>self::TYPE_DATETIME,
102 'ATTRIBUTES'=>[Attributes::ReadOnly]
103 ],
104 'EMP_CANCELED_ID'=>[
105 'TYPE'=>self::TYPE_INT
106 ],
107 'RESPONSIBLE_ID'=>[
108 'TYPE'=>self::TYPE_INT
109 ],
110 'DATE_RESPONSIBLE_ID'=>[
111 'TYPE'=>self::TYPE_DATETIME,
112 'ATTRIBUTES'=>[Attributes::ReadOnly]
113 ],
114 'EMP_RESPONSIBLE_ID'=>[
115 'TYPE'=>self::TYPE_INT
116 ],
117 'COMMENTS'=>[
118 'TYPE'=>self::TYPE_STRING
119 ],
120 'CURRENCY'=>[
121 'TYPE'=>self::TYPE_STRING
122 ],
123 'CUSTOM_PRICE_DELIVERY'=>[
124 'TYPE'=>self::TYPE_CHAR,
125 'ATTRIBUTES'=>[Attributes::ReadOnly]
126 ],
127 'UPDATED_1C'=>[
128 'TYPE'=>self::TYPE_CHAR
129 ],
130 'EXTERNAL_DELIVERY'=>[
131 'TYPE'=>self::TYPE_CHAR
132 ],
133 'VERSION_1C'=>[
134 'TYPE'=>self::TYPE_STRING
135 ],
136 'ID_1C'=>[
137 'TYPE'=>self::TYPE_STRING
138 ],
139 'TRACKING_STATUS'=>[
140 'TYPE'=>self::TYPE_STRING
141 ],
142 'TRACKING_LAST_CHECK'=>[
143 'TYPE'=>self::TYPE_STRING
144 ],
145 'TRACKING_DESCRIPTION'=>[
146 'TYPE'=>self::TYPE_STRING
147 ],
148 'DISCOUNT_PRICE'=>[
149 'TYPE'=>self::TYPE_FLOAT,
150 'ATTRIBUTES'=>[Attributes::ReadOnly]
151 ],
152 'DATE_INSERT'=>[
153 'TYPE'=>self::TYPE_DATETIME,
154 'ATTRIBUTES'=>[Attributes::ReadOnly]
155 ],
156 'SYSTEM'=>[
157 'TYPE'=>self::TYPE_CHAR,
158 'ATTRIBUTES'=>[Attributes::ReadOnly]
159 ],
160 'STATUS_XML_ID'=>[
161 'TYPE'=>self::TYPE_CHAR,
162 'ATTRIBUTES'=>[Attributes::ReadOnly]
163 ],
164 'DELIVERY_XML_ID'=>[
165 'TYPE'=>self::TYPE_STRING,
166 'ATTRIBUTES'=>[Attributes::ReadOnly]
167 ],
168 'ACCOUNT_NUMBER'=>[
169 'TYPE'=>self::TYPE_STRING,
170 'ATTRIBUTES'=>[Attributes::ReadOnly]
171 ],
172 'SHIPMENT_ITEMS'=>[
173 'TYPE'=>self::TYPE_LIST,
174 'ATTRIBUTES'=>[Attributes::Hidden]
175 ],
176 ];
177 }
178
179 public function internalizeFieldsModify($fields, $fieldsInfo=[])
180 {
181 $result = [];
182 $shipmentItem = new ShipmentItem();
183
184 $fieldsInfo = empty($fieldsInfo)? $this->getFields():$fieldsInfo;
185 $listFieldsInfoAdd = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly]]]);
186 $listFieldsInfoUpdate = $this->getListFieldInfo($fieldsInfo, ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable], 'skipFields'=>['ID']]]);
187
188 if(isset($fields['ORDER']['ID']))
189 $result['ORDER']['ID'] = (int)$fields['ORDER']['ID'];
190
191 if(isset($fields['ORDER']['SHIPMENTS']))
192 {
193 foreach ($fields['ORDER']['SHIPMENTS'] as $k=>$item)
194 {
195 $result['ORDER']['SHIPMENTS'][$k] = $this->internalizeFields($item,
196 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
197 );
198
199 if(isset($item['SHIPMENT_ITEMS']))
200 {
201 $result['ORDER']['SHIPMENTS'][$k]['SHIPMENT_ITEMS'] = $shipmentItem->internalizeFieldsModify(['SHIPMENT'=>['SHIPMENT_ITEMS'=>$item['SHIPMENT_ITEMS']]])['SHIPMENT']['SHIPMENT_ITEMS'];
202 }
203 }
204 }
205
206 return $result;
207 }
208
209 protected function getRewritedFields()
210 {
211 return [
212 'STATUS_XML_ID'=>[
213 'REFERENCE_FIELD'=>'STATUS_TABLE.XML_ID'
214 ],
215 'DELIVERY_XML_ID'=>[
216 'REFERENCE_FIELD'=>'DELIVERY.XML_ID'
217 ]
218 ];
219 }
220
221 public function externalizeFields($fields)
222 {
223 $shipmentItem = new \Bitrix\Sale\Rest\Entity\ShipmentItem();
224
225 $result = parent::externalizeFields($fields);
226
227 if(isset($fields['SHIPMENT_ITEMS']))
228 $result['SHIPMENT_ITEMS'] = $shipmentItem->externalizeListFields($fields['SHIPMENT_ITEMS']);
229
230 return $result;
231 }
232
233 public function externalizeFieldsModify($fields)
234 {
235 return $this->externalizeListFields($fields);
236 }
237
238 public function checkFieldsModify($fields)
239 {
240 $r = new Result();
241
242 $emptyFields = [];
243 if(!isset($fields['ORDER']['ID']))
244 {
245 $emptyFields[] = '[order][id]';
246 }
247 if(!isset($fields['ORDER']['SHIPMENTS']) || !is_array($fields['ORDER']['SHIPMENTS']))
248 {
249 $emptyFields[] = '[order][shipments][]';
250 }
251
252 if(count($emptyFields)>0)
253 {
254 $r->addError(new Error('Required fields: '.implode(', ', $emptyFields)));
255 }
256 else
257 {
258 $r = parent::checkFieldsModify($fields);
259 }
260
261 return $r;
262 }
263
264 public function checkRequiredFieldsModify($fields)
265 {
266 $r = new Result();
267
268 $shipmentItem = new ShipmentItem();
269
270 $listFieldsInfoAdd = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly], 'ignoredFields'=>['ORDER_ID']]]);
271 $listFieldsInfoUpdate = $this->getListFieldInfo($this->getFields(), ['filter'=>['ignoredAttributes'=>[Attributes::Hidden, Attributes::ReadOnly, Attributes::Immutable]]]);
272
273 foreach ($fields['ORDER']['SHIPMENTS'] as $k=>$item)
274 {
275 $required = $this->checkRequiredFields($item,
276 $this->isNewItem($item)? $listFieldsInfoAdd:$listFieldsInfoUpdate
277 );
278 if(!$required->isSuccess())
279 {
280 $r->addError(new Error('[shipments]['.$k.'] - '.implode(', ', $required->getErrorMessages()).'.'));
281 }
282
283 if(isset($item['SHIPMENT_ITEMS']))
284 {
285 $requiredShipmentItems = $shipmentItem->checkRequiredFieldsModify(['SHIPMENT'=>['SHIPMENT_ITEMS'=>$item['SHIPMENT_ITEMS']]]);
286 if(!$requiredShipmentItems->isSuccess())
287 {
288 $requiredPShipmentItemsFields = [];
289 foreach ($requiredShipmentItems->getErrorMessages() as $errorMessage)
290 {
291 $requiredPShipmentItemsFields[] = '[shipments]['.$k.']'.$errorMessage;
292 }
293 $r->addError(new Error(implode( ' ', $requiredPShipmentItemsFields)));
294 }
295 }
296 }
297 return $r;
298 }
299
300 public function internalizeArguments($name, $arguments)
301 {
302 if($name = 'getallowdeliverydate'
303 || $name == 'getallowdeliveryuserid'
304 || $name == 'getcompanyid'
305 || $name == 'getcurrency'
306 || $name == 'getdeliveryid'
307 || $name == 'getdeliveryname'
308 || $name == 'getparentorderid'
309 || $name == 'getpersontypeid'
310 || $name == 'getprice'
311 || $name == 'getphippeddate'
312 || $name == 'getshippeduserId'
313 || $name == 'getstoreid'
314 || $name == 'getunshipreason'
315 || $name == 'getvatrate'
316 || $name == 'getvatsum'
317 || $name == 'getweight'
318 || $name == 'setbasepricedelivery'
319 ){}
320 else
321 {
322 parent::internalizeArguments($name, $arguments);
323 }
324
325 return $arguments;
326 }
327}
getListFieldInfo(array $fieldsInfo, $params=[])
Definition base.php:62
internalizeFields($fields, array $fieldsInfo)
Definition base.php:281
checkRequiredFields($fields, array $fieldsInfo, $params=[])
Definition base.php:676
internalizeArguments($name, $arguments)
Definition shipment.php:300
internalizeFieldsModify($fields, $fieldsInfo=[])
Definition shipment.php:179