Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
converterdocumentshipment.php
1<?php
3
4
13
14
21{
25 protected function getFieldsInfo()
26 {
28 }
29
35 public function resolveParams($documentImport)
36 {
37 if(!($documentImport instanceof DocumentBase))
38 throw new ArgumentException("Document must be instanceof DocumentBase");
39
40 $result = array();
41
42 $params = $documentImport->getFieldValues();
43
44 $availableFields = Shipment::getAvailableFields();
45
46 foreach ($availableFields as $k)
47 {
48 switch($k)
49 {
50 case 'ID_1C':
51 case 'VERSION_1C':
52 if(isset($params[$k]))
53 $fields[$k] = $params[$k];
54 break;
55 case 'COMMENTS':
56 if(isset($params['COMMENT']))
57 $fields[$k] = $params['COMMENT'];
58 break;
59 case 'DELIVERY_DOC_DATE':
60 if(isset($params['1C_DATE']))
61 $fields[$k] = $params['1C_DATE'];
62 break;
63 case 'DELIVERY_DOC_NUM':
64 if(isset($params['REK_VALUES']['1C_DELIVERY_NUM']))
65 $fields[$k] = $params['REK_VALUES']['1C_DELIVERY_NUM'];
66 break;
67 case 'DEDUCTED':
68 $deducted='';
69 $cancel='';
70
71 if(isset($params['REK_VALUES']['DEDUCTED']))
72 $deducted = $params['REK_VALUES']['DEDUCTED'];
73 if(isset($params['REK_VALUES']['CANCEL']))
74 $cancel = $params['REK_VALUES']['CANCEL'];
75
76 if($deducted == 'Y')
77 $fields[$k] = 'Y';
78 elseif($cancel == 'Y')
79 $fields[$k] = 'N';
80 break;
81 case 'ALLOW_DELIVERY':
82 $value='';
83 if(isset($params['REK_VALUES']['DEDUCTED']))
84 $value = $params['REK_VALUES']['DEDUCTED'];
85
86 if($value == 'Y')
87 $fields[$k] = 'Y';
88 break;
89 case 'TRACKING_NUMBER':
90 if(isset($params['REK_VALUES']['1C_TRACKING_NUMBER']))
91 $fields[$k] = $params['REK_VALUES']['1C_TRACKING_NUMBER'];
92 break;
93 case 'BASE_PRICE_DELIVERY':
94 $fields["BASE_PRICE_DELIVERY"] = $this->getBasePriceDelivery($params['ITEMS']);
95 break;
96 case 'DELIVERY_ID':
97 $deliverySystemId = 0;
98 if(isset($params['REK_VALUES']['DELIVERY_SYSTEM_ID']))
99 {
100 $deliverySystemId = $params['REK_VALUES']['DELIVERY_SYSTEM_ID'];
101 }
102
103 if($deliverySystemId<=0)
104 {
105 if(isset($params['REK_VALUES']['DELIVERY_SYSTEM_ID_DEFAULT']))
106 {
107 $deliverySystemId = $params['REK_VALUES']['DELIVERY_SYSTEM_ID_DEFAULT'];
108 }
109 }
110
112 $settings = $this->getSettings();
113
114 if($deliverySystemId<=0)
115 {
116 $deliverySystemId = $settings->shipmentServiceFor($this->getEntityTypeId());
117 }
118
119 if($deliverySystemId<=0)
120 {
121 $deliverySystemId = $settings->shipmentServiceDefaultFor($this->getEntityTypeId());
122 }
123
124 $fields[$k] = $deliverySystemId;
125 break;
126 }
127 }
128
129 $result['TRAITS'] = isset($fields)? $fields:array();
130 $result['ITEMS'] = isset($params['ITEMS'])? $this->modifyItemIdByItemName($params['ITEMS']):array();
131 $result['TAXES'] = isset($params['TAXES'])? $params['TAXES']:array();
132
133 return $result;
134 }
135
141 static public function sanitizeFields($shipment=null, array &$fields, ISettings $settings)
142 {
143 if(!empty($shipment) && !($shipment instanceof Shipment))
144 throw new ArgumentException("Entity must be instanceof Shipment");
145
146 foreach($fields as $k=>$v)
147 {
148 switch($k)
149 {
150 case 'BASE_PRICE_DELIVERY':
151 if((!empty($shipment)? $shipment->getPrice():'') != $v)
152 {
154 $fields['CURRENCY'] = $settings->getCurrency();
155 $fields['CUSTOM_PRICE_DELIVERY'] = "Y";
156 }
157 else
158 {
159 unset($fields['BASE_PRICE_DELIVERY']);
160 }
161 break;
162 case 'DELIVERY_ID':
163 if(!empty($shipment))
164 {
165 unset($fields['DELIVERY_ID']);
166 }
167 break;
168 }
169 }
170 unset($fields['ID']);
171 }
172
173 public function externalize(array $fields)
174 {
175 $result = array();
176
177 $traits = $fields['TRAITS'];
178 $items = $fields['ITEMS'] ?? [];
179 $stories = $fields['STORIES'] ?? [];
180 $taxes = $fields['TAXES'] ?? [];
181 $businessValue = $fields['BUSINESS_VALUE'];
182
183 $availableFields = $this->getFieldsInfo();
184
186 $settings = $this->getSettings();
187
188 foreach ($availableFields as $k=>$v)
189 {
190 $value = '';
191 switch ($k)
192 {
193 case 'ID':
194 $value = (!empty($traits['ID_1C']) ? $traits['ID_1C'] : $traits['ID']);
195 break;
196 case 'NUMBER':
197 $value = $traits['ID'];
198 break;
199 case 'TIME':
200 case 'DATE':
201 $value = $traits['DATE_INSERT'];
202 break;
203 case 'OPERATION':
204 $value = DocumentBase::resolveDocumentTypeName($this->getDocmentTypeId());
205 break;
206 case 'ROLE':
207 $value = DocumentBase::getLangByCodeField('SELLER');
208 break;
209 case 'CURRENCY':
210 $replaceCurrency = $settings->getReplaceCurrency();
211 $value = mb_substr($replaceCurrency <> ''? $replaceCurrency : $traits[$k], 0, 3);
212 break;
213 case 'CURRENCY_RATE':
214 $value = self::CURRENCY_RATE_DEFAULT;;
215 break;
216 case 'AMOUNT':
217 $price = 0;
218 foreach ($items as $item)
219 {
220 if ($item['PRODUCT_XML_ID'] !== ImportOneCBase::DELIVERY_SERVICE_XMLID)
221 {
222 $price = $price + $item['PRICE'] * $item['QUANTITY'];
223 }
224 }
225
226 $value = $price + $traits['PRICE_DELIVERY'];
227
228 break;
229 case 'VERSION':
230 $value = $traits['VERSION'];
231 break;
232 case 'NUMBER_BASE':
233 $value = $traits['ORDER_ID'];
234 break;
235 case 'TAXES':
236 if (count($taxes) > 0)
237 {
238 $value = $this->externalizeTaxes($taxes, $v);
239 }
240 break;
241 case 'STORIES':
242 if (count($stories) > 0)
243 {
244 $value = $this->externalizeStories($stories, $v);
245 }
246 break;
247 case 'COMMENT':
248 $value = $traits['COMMENTS'];
249 break;
250 case 'ITEMS':
251 if (count($items) > 0)
252 {
253 $value = $this->externalizeItems($items, $v);
254 }
255 break;
256 case 'REK_VALUES':
257 $value=array();
258 foreach($v['FIELDS'] as $name=>$fieldInfo)
259 {
260 $valueRV='';
261 switch($name)
262 {
263 case 'PRICE_DELIVERY':
264 $valueRV = ($traits['PRICE_DELIVERY'] <> ''? $traits['PRICE_DELIVERY']:"0.0000");
265 break;
266 case 'DATE_ALLOW_DELIVERY':
267 case 'DELIVERY_LOCATION':
268 case 'DATE_DEDUCTED':
269 case 'REASON_UNDO_DEDUCTED':
270 case 'RESERVED':
271 case 'REASON_MARKED':
272 case 'TRACKING_NUMBER':
273 $valueRV = $traits[$name];
274 break;
275 case 'CANCEL':
276 $valueRV = $traits['CANCELED'];
277 break;
278 case 'DELIVERY_SYSTEM_ID':
279 $valueRV = $traits['DELIVERY_ID'];
280 break;
281 case 'DELIVERY_STATUS':
282 $valueRV = $traits['STATUS_ID'];
283 break;
284 case 'DELIVERY_DEDUCTED':
285 $valueRV = $traits['DEDUCTED'];
286 break;
287 case 'DELIVERY':
288 $valueRV = $traits['DELIVERY_NAME'];
289 break;
290 case 'DELIVERY_DATE_CANCEL':
291 $valueRV = $traits['DATE_CANCELED'];
292 break;
293 case 'CANCEL_REASON':
294 $valueRV = $traits['REASON_CANCELED'];
295 break;
296 case 'SITE_NAME':
297 $valueRV = '['.$traits['LID'].'] '.static::getSiteNameByLid($traits['LID']);
298 break;
299 case 'REKV':
300 $value = array_merge($value, $this->externalizeRekv($businessValue[$name], $fieldInfo));
301 break;
302 }
303 if(!in_array($name, array('REKV')))
304 {
305 $value[] = $this->externalizeRekvValue($name, $valueRV, $fieldInfo);
306 }
307 }
308 break;
309 }
310 if(!in_array($k, array('TAXES', 'STORES', 'ITEMS', 'REK_VALUES')))
311 {
312 $this->externalizeField($value, $v);
313 }
314
315 $result[$k] = $value;
316 }
317 $result = $this->modifyTrim($result);
318 return $result;
319 }
320
321 public function externalizeItems(array $taxes, array $info)
322 {
325 return $converter->externalizeItems($taxes, $info);
326 }
327
328 public function externalizeStories(array $stories, array $info)
329 {
332 return $converter->externalizeStories($stories, $info);
333 }
334
335 public function externalizeTaxes(array $items, array $info)
336 {
339 return $converter->externalizeTaxes($items, $info);
340 }
341
342 protected function getBasePriceDelivery($list=[])
343 {
344 if(is_array($list) && count($list)>0)
345 {
346 foreach($list as $item)
347 {
348 foreach($item as $fields)
349 {
350 if($fields['TYPE'] == ImportBase::ITEM_SERVICE)
351 {
352 //if((!empty($shipment)? $shipment->getPrice():'') != $item["PRICE"])
353 //{
354 //$fields["CUSTOM_PRICE_DELIVERY"] = "Y";
355 return $fields["PRICE"];
356 //$fields["CURRENCY"] = $settings->getCurrency();
357 //}
358 //break 2;
359 }
360 }
361 }
362 }
363 return 0;
364 }
365}
static getAvailableFields()
Definition shipment.php:74
if(!function_exists(__NAMESPACE__.'\\___1034172934'))
Definition license.php:1