1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
entitymarker.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Sale;
5
6
7use Bitrix\Main;
8use Bitrix\Sale\Internals;
9use Bitrix\Sale;
10
12
14{
16 const ENTITY_MARKED_TYPE_MANUAL = 'MANUAL';
17
18 const ENTITY_TYPE_ORDER = 'ORDER';
19 const ENTITY_TYPE_BASKET_ITEM = 'BASKET_ITEM';
20 const ENTITY_TYPE_SHIPMENT = 'SHIPMENT';
21 const ENTITY_TYPE_PAYMENT = 'PAYMENT';
22 const ENTITY_TYPE_PROPERTY_VALUE = 'PROPERTY_VALUE';
23
26
28 protected static $pool = array();
29
35 public static function addMarker(OrderBase $order, Internals\Entity $entity, Result $result)
36 {
37 if (!$result->hasWarnings())
38 {
39 return;
40 }
41
42 $entityType = static::getEntityType($entity);
43 if ($entityType === null)
44 {
45 return;
46 }
47
48 $fields = array(
49 'ENTITY' => $entity,
50 'ORDER' => $order,
51 );
52
53 if ($order->getId() > 0)
54 {
55 $fields['ORDER_ID'] = $order->getId();
56 }
57
58 if ($entity->getId() > 0)
59 {
60 $fields['ENTITY_ID'] = $entity->getId();
61 }
62
63 $fields['ENTITY_TYPE'] = $entityType;
65 foreach ($result->getWarnings() as $resultWarning)
66 {
67 $code = $resultWarning->getCode();
68 $message = $resultWarning->getMessage();
69 $isAutoFix = false;
70
71 if ($entity instanceof \IEntityMarker)
72 {
73 $isAutoFix = $entity->canAutoFixError($code);
74 }
75
76 $fields['CODE'] = $code;
77 $fields['MESSAGE'] = $message;
78 $fields['TYPE'] = $isAutoFix ? static::ENTITY_MARKED_TYPE_AUTO : static::ENTITY_MARKED_TYPE_MANUAL;
79 $fields['SUCCESS'] = static::ENTITY_SUCCESS_CODE_FAIL;
80 static::addItem($order, $entityType, $fields);
81 }
82 $resultWarnings = $result->getWarnings();
83 $lastWarning = end($resultWarnings);
84 $order->setField('REASON_MARKED', $lastWarning->getMessage());
85
86 if (
87 $entity instanceof Payment
88 || $entity instanceof Shipment
89 )
90 {
91 $entity->setField('MARKED', 'Y');
92 }
93 }
94
103 public static function updateMarker($id, array $values, Order $order, Internals\Entity $entity)
104 {
105 $result = new Result();
106 $entityType = static::getEntityType($entity);
107 if ($entityType !== null)
108 {
109 $r = static::updateItem($id, $values, $order, $entityType);
110 if (!$r->isSuccess())
111 {
112 $result->addErrors($r->getErrors());
113 }
114 }
115
116 return $result;
117 }
118
126 protected static function addItem(OrderBase $order, $entityType, array $values)
127 {
128 $orderCode = $order->getInternalId();
129
130 if (!empty(static::$pool[$orderCode]) && !empty(static::$pool[$orderCode][$entityType]) && is_array(static::$pool[$orderCode][$entityType]))
131 {
132 foreach (static::$pool[$orderCode][$entityType] as $index => $fields)
133 {
134 $foundItem = false;
135
136 foreach (static::getFieldsDuplicateCheck() as $checkField)
137 {
138 if (!empty($fields[$checkField]) && !empty($values[$checkField]) && $fields[$checkField] == $values[$checkField])
139 {
140 $foundItem = true;
141 continue;
142 }
143
144 $foundItem = false;
145 break;
146 }
147
148 if ($foundItem)
149 {
150 if (!empty($values['SUCCESS']))
151 {
152 static::$pool[$orderCode][$entityType][$index]['SUCCESS'] = $values['SUCCESS'];
153 return true;
154 }
155 }
156 }
157 }
158
159 static::$pool[$orderCode][$entityType][] = $values;
160 return true;
161 }
162
171 protected static function updateItem($id, $values, Order $order, $entityType)
172 {
173 $orderCode = $order->getInternalId();
174 $result = new Result();
175
176 if (!empty(static::$pool[$orderCode]) && !empty(static::$pool[$orderCode][$entityType]) && is_array(static::$pool[$orderCode][$entityType]))
177 {
178 foreach (static::$pool[$orderCode][$entityType] as $index => $fields)
179 {
180 $foundItem = false;
181 if ((isset($fields['ID']) && $id > 0 && intval($fields['ID']) == $id))
182 {
183 $foundItem = true;
184 }
185
186 if (!$foundItem)
187 {
188 foreach (static::getFieldsDuplicateCheck() as $checkField)
189 {
190 if (!empty($fields[$checkField]) && !empty($values[$checkField]) && $fields[$checkField] == $values[$checkField])
191 {
192 $foundItem = true;
193 continue;
194 }
195
196 $foundItem = false;
197 break;
198 }
199 }
200
201 if ($foundItem)
202 {
203 static::$pool[$orderCode][$entityType][$index] = array_merge($fields, $values);
204 return $result;
205 }
206 }
207 }
208
209 $values['ID'] = $id;
210
211 if (empty($values['ORDER']))
212 {
213 $values['ORDER'] = $order;
214 }
215
216 if ($order->getId() > 0)
217 {
218 $values['ORDER_ID'] = $order->getId();
219 }
220
221 static::$pool[$orderCode][$entityType][] = $values;
222
223 return $result;
224 }
225
232 public static function getMarker($orderCode, Internals\Entity $entity = null)
233 {
234 if (empty(static::$pool[$orderCode]))
235 {
236 return null;
237 }
238
239 if ($entity !== null)
240 {
241 $entityType = static::getEntityType($entity);
242 if ($entityType !== null && array_key_exists($entityType, static::$pool[$orderCode]))
243 {
244 return static::$pool[$orderCode][$entityType];
245 }
246 }
247 else
248 {
249 return static::$pool[$orderCode];
250 }
251
252 return null;
253 }
254
258 protected static function getEntityTypeList()
259 {
260 return array(
261 static::ENTITY_TYPE_ORDER => '\Bitrix\Sale\OrderBase',
262 static::ENTITY_TYPE_BASKET_ITEM => '\Bitrix\Sale\BasketItemBase',
263 static::ENTITY_TYPE_SHIPMENT => '\Bitrix\Sale\Shipment',
264 static::ENTITY_TYPE_PAYMENT => '\Bitrix\Sale\Payment',
265 static::ENTITY_TYPE_PROPERTY_VALUE => '\Bitrix\Sale\PropertyValue',
266 );
267 }
268
274 protected static function getEntityType(Internals\Entity $entity)
275 {
276 $typeList = static::getEntityTypeList();
277
278 foreach ($typeList as $type => $entityClass)
279 {
280 if ($entity instanceof $entityClass)
281 {
282 return $type;
283 }
284 }
285
286 return null;
287 }
288
296 public static function saveMarkers(Order $order = null)
297 {
298 global $USER;
299 $result = new Result();
300
301 $saveList = array();
302
303 $oldMarkerDataList = array();
304
305 $orderCode = null;
306
307 $newOrderList = array();
308
309 if ($order instanceof Order && $order->getId() > 0)
310 {
311 $orderCode = $order->getInternalId();
312 }
313
314 foreach (static::$pool as $orderIndex => $entityList)
315 {
316 foreach ($entityList as $entityType => $fieldsList)
317 {
318 foreach ($fieldsList as $fieldIndex => $values)
319 {
320 if ($values['ORDER'] instanceof Order)
321 {
322 if (empty($values['ORDER_ID']) && $values['ORDER']->getId() > 0)
323 {
324 $values['ORDER_ID'] = $values['ORDER']->getId();
325 $newOrderList[] = $values['ORDER_ID'];
326 }
327
328 if ($order instanceof Order && $values['ORDER']->getInternalId() != $order->getInternalId())
329 {
330 continue 3;
331 }
332 }
333
334 if (!empty($values['ENTITY']) && $values['ENTITY'] instanceof Internals\Entity)
335 {
336 if (empty($values['ENTITY_TYPE']))
337 {
338 $entityType = static::getEntityType($values['ENTITY']);
339
340 if (strval($entityType) != '')
341 {
342 $values['ENTITY_TYPE'] = $entityType;
343 }
344 }
345
346 if (!isset($values['ENTITY_ID']) || intval($values['ENTITY_ID']) <= 0)
347 {
348 $values['ENTITY_ID'] = $values['ENTITY']->getId();
349 }
350 }
351
352 $fields = array();
353
354 if (empty($values['ID']))
355 {
356 if (intval($values['ENTITY_ID']) <= 0)
357 {
358 continue;
359 }
360
361 if (empty($values['ENTITY_TYPE']))
362 {
363 throw new Main\ArgumentNullException('ENTITY_TYPE');
364 }
365
366 $fields = array(
367 'ENTITY_TYPE' => $values['ENTITY_TYPE'],
368 'ENTITY_ID' => intval($values['ENTITY_ID']),
369 'TYPE' => $values['TYPE'] ?? '',
370 'CODE' => $values['CODE'] ?? '',
371 'MESSAGE' => $values['MESSAGE'] ?? '',
372 'COMMENT' => $values['COMMENT'] ?? '',
373 );
374
375 if (is_object($USER) && $USER->IsAuthorized())
376 {
377 $fields['USER_ID'] = $USER->GetID();
378 }
379 }
380
381 if (intval($values['ORDER_ID']) >= 0)
382 {
383 $fields['ORDER_ID'] = intval($values['ORDER_ID']);
384 }
385
386 if (empty($fields['ENTITY_ID']) && intval($values['ENTITY_ID']) >= 0)
387 {
388 $fields['ENTITY_ID'] = intval($values['ENTITY_ID']);
389 }
390
391 if (empty($fields['ENTITY_TYPE']) && !empty($values['ENTITY_TYPE']))
392 {
393 $fields['ENTITY_TYPE'] = $values['ENTITY_TYPE'];
394 }
395
396 if (!empty($values['ID']))
397 {
398 $fields['ID'] = $values['ID'];
399 }
400
401 if (!empty($values['SUCCESS']))
402 {
403 $fields['SUCCESS'] = $values['SUCCESS'];
404 }
405
406 if (!empty($values['DATE_CREATE']) && $values['DATE_CREATE'] instanceof Main\Type\Date)
407 {
408 $fields['DATE_CREATE'] = $values['DATE_CREATE'];
409 }
410
411 if (!empty($values['DATE_UPDATE']) && $values['DATE_UPDATE'] instanceof Main\Type\Date)
412 {
413 $fields['DATE_UPDATE'] = $values['DATE_UPDATE'];
414 }
415
416 if ($values['ORDER'] instanceof Order)
417 {
418 unset(static::$pool[$values['ORDER']->getInternalId()][$entityType][$fieldIndex]);
419 }
420
421 if (empty($fields))
422 continue;
423
424 $markerOrderId = null;
425
426 if (!empty($values['ORDER_ID']))
427 {
428 $markerOrderId = $values['ORDER_ID'];
429 }
430
431 $saveList[$markerOrderId][] = $fields;
432 }
433 }
434 }
435
436 if (!empty($saveList) && is_array($saveList))
437 {
438 $filter = array(
439 'select' => array(
440 'ID', 'ORDER_ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'SUCCESS', 'MESSAGE'
441 ),
442 'filter' => array(
443 '!=SUCCESS' => static::ENTITY_SUCCESS_CODE_DONE
444 ),
445 'order' => array('ID' => 'ASC')
446 );
447
448 foreach ($saveList as $fieldsList)
449 {
450
451 foreach ($fieldsList as $fields)
452 {
453 if (!empty($fields['ORDER_ID']) && in_array($fields['ORDER_ID'], $newOrderList))
454 {
455 continue;
456 }
457
458 if (!empty($fields['ORDER_ID']) && (empty($filter['filter']['=ORDER_ID']) || !in_array($fields['ORDER_ID'], $filter['filter']['=ORDER_ID'])))
459 {
460 $filter['filter']['=ORDER_ID'][] = $fields['ORDER_ID'];
461 }
462
463 if (!empty($fields['ENTITY_TYPE'])
464 && (empty($filter['filter']['=ENTITY_TYPE'])
465 || (is_array($filter['filter']['=ENTITY_TYPE']) && !in_array($fields['ENTITY_TYPE'], $filter['filter']['=ENTITY_TYPE']))))
466 {
467 $filter['filter']['=ENTITY_TYPE'][] = $fields['ENTITY_TYPE'];
468 }
469 }
470 }
471
472
473 if (!empty($filter['filter']['=ENTITY_TYPE']))
474 {
475 $res = static::getList($filter);
476 while($data = $res->fetch())
477 {
478 if (isset($saveList[$data['ORDER_ID']]) && is_array($saveList[$data['ORDER_ID']]))
479 {
480 foreach($saveList[$data['ORDER_ID']] as $key => $values)
481 {
482 if (!empty($values['ID']) && $data['ID'] == $values['ID'])
483 {
484 $oldMarkerDataList[$data['ID']] = $data;
485
486 $values = array_merge($data, $values);
487 $saveList[$data['ORDER_ID']][$key] = $values;
488 continue;
489 }
490 $foundItem = false;
491
492 if (!$foundItem)
493 {
494 foreach (static::getFieldsDuplicateCheck() as $checkField)
495 {
496 if (!empty($data[$checkField]) && !empty($values[$checkField]) && $data[$checkField] == $values[$checkField])
497 {
498 $foundItem = true;
499 continue;
500 }
501
502 $foundItem = false;
503 break;
504 }
505 }
506
507 if ($foundItem)
508 {
509 foreach($saveList[$data['ORDER_ID']] as $doubleKey => $doubleValues)
510 {
511 if ($doubleKey == $key)
512 continue;
513
514 if (!empty($doubleValues['ID']) && $data['ID'] == $doubleValues['ID'])
515 {
516 if (empty($values['SUCCESS']))
517 {
518 unset($doubleValues['SUCCESS']);
519 }
520
521 $values = array_merge($doubleValues, $values);
522 unset($saveList[$data['ORDER_ID']][$doubleKey]);
523 }
524 }
525
526 $fields = array(
527 'ID' => $data['ID'],
528 );
529
530 if (!empty($values['SUCCESS']) && $data['SUCCESS'] != $values['SUCCESS'])
531 {
532 $fields['SUCCESS'] = $values['SUCCESS'];
533 }
534
535 $saveList[$data['ORDER_ID']][$key] = $fields;
536 }
537 }
538 }
539 }
540 }
541
542 foreach ($saveList as $orderId => $fieldsList)
543 {
544 foreach ($fieldsList as $fields)
545 {
546 if (!empty($fields['ID']))
547 {
548 $elementId = intval($fields['ID']);
549 unset($fields['ID']);
550
551 if (empty($fields))
552 continue;
553
554 if (!empty($oldMarkerDataList) && !empty($oldMarkerDataList[$elementId]))
555 {
556 foreach($fields as $fieldName => $fieldValue)
557 {
558 if (array_key_exists($fieldName, $oldMarkerDataList[$elementId])
559 && $oldMarkerDataList[$elementId][$fieldName] == $fieldValue)
560 {
561 unset($fields[$fieldName]);
562 }
563 }
564 }
565
566 if (empty($fields))
567 continue;
568
569 if (empty($fields['DATE_UPDATE']))
570 {
571 $fields['DATE_UPDATE'] = new Main\Type\DateTime();
572 }
573
574 if (!empty($fields['SUCCESS']) && $fields['SUCCESS'] == static::ENTITY_SUCCESS_CODE_DONE
575 && !empty($oldMarkerDataList) && !empty($oldMarkerDataList[$elementId]))
576 {
578 $oldMarkerDataList[$elementId]['ENTITY_TYPE'],
579 $oldMarkerDataList[$elementId]['ORDER_ID'],
580 'MARKER_SUCCESS',
581 $oldMarkerDataList[$elementId]['ENTITY_ID'],
582 null,
583 array(
584 "ENTITY_ID" => $oldMarkerDataList[$elementId]['ENTITY_ID'],
585 "MESSAGE" => $oldMarkerDataList[$elementId]['MESSAGE'],
586 "ENTITY_TYPE" => $oldMarkerDataList[$elementId]['ENTITY_TYPE'],
587 ),
589 );
590
591 $r = static::delete($elementId);
592 if (!$r->isSuccess())
593 {
594 $result->addErrors($r->getErrors());
595 }
596
597 continue;
598 }
599
600 $r = static::updateInternal($elementId, $fields);
601 if (!$r->isSuccess())
602 {
603 $result->addErrors($r->getErrors());
604 }
605 }
606 else
607 {
608 if (empty($fields['DATE_CREATE']))
609 {
610 $fields['DATE_CREATE'] = new Main\Type\DateTime();
611 }
612
613 $r = static::addInternal($fields);
614 if (!$r->isSuccess())
615 {
616 $result->addErrors($r->getErrors());
617 }
618 }
619 }
620 }
621 }
622
623 static::resetMarkers($orderCode);
624
625 return $result;
626 }
627
628
629 protected static function resetMarkers($orderCode = null)
630 {
631 if (intval($orderCode) > 0)
632 {
633 unset(static::$pool[$orderCode]);
634 }
635 else
636 {
637 static::$pool = array();
638 }
639 }
640
648 public static function tryFixErrorsByOrder(Order $order, $markerId = null)
649 {
650 $result = new Result();
651 if ($order->getId() <=0)
652 {
653 return $result;
654 }
655
656 $resultList = array(
657 'LIST' => array(),
658 'ERRORS' => array(),
659 );
660
661 $filter = array(
662 'filter' => array(
663 '=ORDER_ID' => $order->getId(),
664 '=TYPE' => static::ENTITY_MARKED_TYPE_AUTO,
665 ),
666 'select' => array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'SUCCESS'),
667 'order' => array('ID' => 'DESC')
668 );
669
670 if (intval($markerId) > 0)
671 {
672 $filter['filter']['=ID'] = intval($markerId);
673 }
674 else
675 {
676 $filter['filter']['!=SUCCESS'] = static::ENTITY_SUCCESS_CODE_DONE;
677 }
678
679 $res = static::getList($filter);
680 while($markerData = $res->fetch())
681 {
682 if ($markerData['SUCCESS'] == static::ENTITY_SUCCESS_CODE_DONE)
683 {
684 $resultList['LIST'][$markerData['ID']] = static::ENTITY_SUCCESS_CODE_DONE;
685 }
686 else
687 {
688 if (!$entity = static::getEntity($order, $markerData['ENTITY_TYPE'], $markerData['ENTITY_ID']))
689 {
690 $result->addError(new ResultError(Main\Localization\Loc::getMessage('SALE_ENTITY_MARKER_ENTITY_NOT_FOUND'), 'SALE_ENTITY_MARKER_ENTITY_NOT_FOUND'));
691 return $result;
692 }
693
694 if (!($entity instanceof \IEntityMarker))
695 {
696 return $result;
697 }
698
699 $r = $entity->tryFixError($markerData['CODE']);
700 if ($r->isSuccess() && !$r->hasWarnings())
701 {
702 $markerData['SUCCESS'] = static::ENTITY_SUCCESS_CODE_DONE;
703 }
704 else
705 {
706 $markerData['SUCCESS'] = static::ENTITY_SUCCESS_CODE_FAIL;
707 if (!isset($resultList['ERRORS'][$markerData['ID']]))
708 {
709 $resultList['ERRORS'][$markerData['ID']] = array();
710 }
711 $resultList['ERRORS'][$markerData['ID']] = array_merge($resultList['ERRORS'][$markerData['ID']], $r->getWarningMessages());
712 if (!$r->isSuccess())
713 {
714 $result->addErrors($r->getErrors());
715 }
716 }
717
718 static::updateMarker($markerData['ID'], $markerData, $order, $entity);
719 $resultList['LIST'][$markerData['ID']] = ($markerData['SUCCESS'] == static::ENTITY_SUCCESS_CODE_DONE);
720 }
721 }
722
723 if (!empty($resultList) && is_array($resultList))
724 {
725 $result->setData($resultList);
726 }
727
728 return $result;
729 }
730
731
737 public static function tryFixErrors()
738 {
739 static $orderList = array();
740 $orderSaveList = array();
741 $lastOrderId = null;
742
745 $orderClass = $registry->getOrderClassName();
746
747 $result = new Result();
748 $res = static::getList(array(
749 'filter' => array(
750 '=TYPE' => static::ENTITY_MARKED_TYPE_AUTO,
751 '!=SUCCESS' => static::ENTITY_SUCCESS_CODE_DONE
752 ),
753 'select' => array('ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'ORDER_ID'),
754 'order' => array('ORDER_ID' => 'ASC', 'ID' => 'DESC')
755 ));
756 while($data = $res->fetch())
757 {
758 if (array_key_exists($data['ORDER_ID'], $orderList))
759 {
760 $order = $orderList[$data['ORDER_ID']];
761 }
762 else
763 {
764 $order = $orderClass::load($data['ORDER_ID']);
765 $orderList[$data['ORDER_ID']] = $order;
766 }
767
768 if (!$entity = static::getEntity($order, $data['ENTITY_TYPE'], $data['ENTITY_ID']))
769 {
770 continue;
771 }
772
773 if ($lastOrderId !== null && $lastOrderId !== $order->getId())
774 {
775 if (isset($orderSaveList[$lastOrderId]))
776 {
777 $r = $orderSaveList[$lastOrderId]->save();
778 unset($orderSaveList[$lastOrderId]);
779 }
780 }
781
782 if (!($entity instanceof \IEntityMarker))
783 {
784 continue;
785 }
786
787 $r = $entity->tryFixError($data['CODE']);
788 if ($r->isSuccess())
789 {
790 $data['SUCCESS'] = static::ENTITY_SUCCESS_CODE_DONE;
791
792 if (!array_key_exists($data['ORDER_ID'], $orderSaveList))
793 {
794 $orderSaveList[$order->getId()] = $order;
795 }
796 }
797 else
798 {
799 $data['SUCCESS'] = static::ENTITY_SUCCESS_CODE_FAIL;
800 }
801
802 static::updateMarker($data['ID'], $data, $order, $entity);
803
804 $lastOrderId = $order->getId();
805 }
806
807 if (!empty($orderSaveList))
808 {
809 foreach ($orderSaveList as $order)
810 {
811 $order->save();
812 }
813 }
814
815 foreach ($orderList as $order)
816 {
817 static::saveMarkers($order);
818 }
819
820 return $result;
821 }
822
823 public static function loadFromDb(array $filter)
824 {
825 $entityDat = static::getList($filter)->fetch();
826 if ($entityDat)
827 {
828 return $entityDat;
829 }
830
831 return false;
832 }
833
842 public static function getEntity(Order $order, $entityType, $entityId)
843 {
844 static $entityList = array();
845
846 $hash = md5($order->getId(). '|'. $entityType . '|' . $entityId);
847
848 if (!empty($entityList[$hash]))
849 {
850 return $entityList[$hash];
851 }
852
853 $entity = null;
854 $entityCollection = null;
855
856 if ($entityType == static::ENTITY_TYPE_ORDER)
857 {
858 if ($order->getId() == $entityId)
859 {
860 return $order;
861 }
862 return null;
863 }
864 elseif($entityType == static::ENTITY_TYPE_SHIPMENT)
865 {
867 $entityCollection = $order->getShipmentCollection();
868 }
869 elseif($entityType == static::ENTITY_TYPE_PAYMENT)
870 {
872 $entityCollection = $order->getPaymentCollection();
873 }
874 elseif($entityType == static::ENTITY_TYPE_BASKET_ITEM)
875 {
877 $entityCollection = $order->getBasket();
878 }
879
880 if ($entity === null && !$entityCollection)
881 return null;
882
883 if ($entity === null)
884 {
886 if (!$entity = $entityCollection->getItemById($entityId))
887 {
888 return null;
889 }
890 }
891
892 if ($entity !== null)
893 {
894 $entityList[$hash] = $entity;
895 }
896
897 return $entity;
898 }
899
906 public static function getList(array $parameters = array())
907 {
908 return Internals\EntityMarkerTable::getList($parameters);
909 }
910
918 public static function delete($id)
919 {
920 if (intval($id) <= 0)
921 {
922 throw new Main\ArgumentNullException('ID');
923 }
924
925 return Internals\EntityMarkerTable::delete($id);
926 }
927
928 protected static function addInternal(array $data)
929 {
930 return Internals\EntityMarkerTable::add($data);
931 }
932
933 protected static function updateInternal($primary, array $data)
934 {
935 return Internals\EntityMarkerTable::update($primary, $data);
936 }
937
947 public static function getPoolItemSuccess(Order $order, $id, $entityType, $entityId, $code)
948 {
949 $orderCode = $order->getInternalId();
950
951 if (!empty(static::$pool[$orderCode]))
952 {
953 foreach (static::$pool[$orderCode] as $poolEntityType => $fieldsList)
954 {
955 foreach ($fieldsList as $fieldIndex => $values)
956 {
957 if ($values['ORDER'] instanceof Order)
958 {
959 if ($order instanceof Order && $values['ORDER']->getInternalId() != $order->getInternalId())
960 {
961 continue 2;
962 }
963 }
964
965 if (!empty($values['SUCCESS'])
966 && (isset($values['ENTITY_ID']) && intval($values['ENTITY_ID']) == intval($entityId))
967 && (isset($values['ENTITY_TYPE']) && $values['ENTITY_TYPE'] == $entityType)
968 && (isset($values['CODE']) && $values['CODE'] == $code)
969 )
970 {
971 if ((!empty($values['ID']) && $values['ID'] == $id) || !isset($values['ID']))
972 {
973 return $values['SUCCESS'];
974 }
975 }
976 }
977 }
978 }
979
980 return null;
981 }
982
983 public static function hasErrors(Order $order)
984 {
985 $orderCode = $order->getInternalId();
986 if (!empty(static::$pool[$orderCode]))
987 {
988 foreach (static::$pool[$orderCode] as $poolEntityType => $fieldsList)
989 {
990 foreach ($fieldsList as $fieldIndex => $values)
991 {
992 if ($values['ORDER'] instanceof Order)
993 {
994 if ($order instanceof Order && $values['ORDER']->getInternalId() != $order->getInternalId())
995 {
996 continue 2;
997 }
998 }
999
1000 if(empty($values['SUCCESS']) || ($values['SUCCESS'] != static::ENTITY_SUCCESS_CODE_DONE))
1001 {
1002 return true;
1003 }
1004 }
1005 }
1006 }
1007
1008 return false;
1009 }
1010
1011 private static function getFieldsDuplicateCheck()
1012 {
1013 return array(
1014 'ENTITY_ID',
1015 'ENTITY_TYPE',
1016 'CODE',
1017 );
1018 }
1019
1025 public static function deleteByOrderId($id)
1026 {
1027 if(intval($id) <= 0)
1028 return false;
1029
1030 $res = static::getList(array(
1031 'filter' => array(
1032 '=ORDER_ID' => $id
1033 ),
1034 'select' => array('ID')
1035 ));
1036 while($data = $res->fetch())
1037 {
1038 static::delete($data['ID']);
1039 }
1040 }
1041
1047 public static function deleteByEntity(Internals\Entity $entity)
1048 {
1049 if($entity->getId() <= 0)
1050 return false;
1051
1052 if ($entityType = static::getEntityType($entity))
1053 {
1054 $res = static::getList(array(
1055 'filter' => array(
1056 '=ENTITY_ID' => $entity->getId(),
1057 '=ENTITY_TYPE' => $entityType
1058 ),
1059 'select' => array('ID')
1060 ));
1061 while($data = $res->fetch())
1062 {
1063 static::delete($data['ID']);
1064 }
1065 }
1066 }
1067
1068 public static function deleteByFilter(array $values)
1069 {
1070 $res = static::getList(array(
1071 'filter' => $values,
1072 'select' => array('ID')
1073 ));
1074 while($data = $res->fetch())
1075 {
1076 static::delete($data['ID']);
1077 }
1078 }
1079
1090 public static function refreshMarkers(Order $order)
1091 {
1092 if ($order->getId() == 0)
1093 {
1094 return;
1095 }
1096
1097 $markList = [];
1098
1099 $filter = [
1100 'filter' => [
1101 '=ORDER_ID' => $order->getId(),
1102 '!=SUCCESS' => static::ENTITY_SUCCESS_CODE_DONE
1103 ],
1104 'select' => ['ID', 'ENTITY_TYPE', 'ENTITY_ID', 'CODE', 'SUCCESS'],
1105 'order' => ['ID' => 'DESC']
1106 ];
1107
1108 $res = static::getList($filter);
1109 while($markerData = $res->fetch())
1110 {
1111 if (!empty($markList[$markerData['ENTITY_TYPE']])
1112 && !empty($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']])
1113 && $markerData['CODE'] == $markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]
1114 )
1115 {
1116 continue;
1117 }
1118
1119 if ($markerData['SUCCESS'] != static::ENTITY_SUCCESS_CODE_DONE)
1120 {
1121 $markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']][] = $markerData['CODE'];
1122 }
1123
1124 $poolItemSuccess = static::getPoolItemSuccess(
1125 $order,
1126 $markerData['ID'],
1127 $markerData['ENTITY_TYPE'],
1128 $markerData['ENTITY_ID'],
1129 $markerData['CODE']
1130 );
1131
1132 if ($poolItemSuccess && $poolItemSuccess == static::ENTITY_SUCCESS_CODE_DONE)
1133 {
1134 foreach ($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']] as $markerIndex => $markerCode)
1135 {
1136 if ($markerData['CODE'] == $markerCode)
1137 {
1138 unset($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']][$markerIndex]);
1139 }
1140 }
1141
1142 if (empty($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]))
1143 {
1144 unset($markList[$markerData['ENTITY_TYPE']][$markerData['ENTITY_ID']]);
1145 }
1146 }
1147
1148 if (empty($markList[$markerData['ENTITY_TYPE']]))
1149 {
1150 unset($markList[$markerData['ENTITY_TYPE']]);
1151 }
1152 }
1153
1154 if (!empty($markList))
1155 {
1156 foreach ($markList as $markEntityType => $markEntityList)
1157 {
1158 foreach ($markEntityList as $markEntityId => $markEntityCodeList)
1159 {
1160 if (empty($markEntityCodeList))
1161 {
1162 if (($entity = static::getEntity($order, $markEntityType, $markEntityId)) && ($entity instanceof \IEntityMarker))
1163 {
1164 if ($entity->canMarked())
1165 {
1166 $markedField = $entity->getMarkField();
1167 $entity->setField($markedField, 'N');
1168 }
1169 }
1170 }
1171 }
1172 }
1173 }
1174
1175 if (empty($markList) && !static::hasErrors($order))
1176 {
1177 $shipmentCollection = $order->getShipmentCollection();
1178 if ($shipmentCollection->isMarked())
1179 {
1181 foreach ($shipmentCollection as $shipment)
1182 {
1183 if ($shipment->isMarked())
1184 {
1185 $shipment->setField('MARKED', 'N');
1186 }
1187 }
1188 }
1189
1190 $paymentCollection = $order->getPaymentCollection();
1191 if ($paymentCollection->isMarked())
1192 {
1194 foreach ($paymentCollection as $payment)
1195 {
1196 if ($payment->isMarked())
1197 {
1198 $payment->setField('MARKED', 'N');
1199 }
1200 }
1201 }
1202
1203 $order->setField('MARKED', 'N');
1204 }
1205 }
1206}
$hash
Определения ajax_redirector.php:8
$type
Определения options.php:106
static loadMessages($file)
Определения loc.php:65
Определения date.php:9
static addItem(OrderBase $order, $entityType, array $values)
Определения entitymarker.php:126
static loadFromDb(array $filter)
Определения entitymarker.php:823
static $pool
Определения entitymarker.php:28
const ENTITY_SUCCESS_CODE_DONE
Определения entitymarker.php:25
static hasErrors(Order $order)
Определения entitymarker.php:983
static getEntityType(Internals\Entity $entity)
Определения entitymarker.php:274
static getPoolItemSuccess(Order $order, $id, $entityType, $entityId, $code)
Определения entitymarker.php:947
const ENTITY_TYPE_BASKET_ITEM
Определения entitymarker.php:19
const ENTITY_TYPE_ORDER
Определения entitymarker.php:18
const ENTITY_MARKED_TYPE_MANUAL
Определения entitymarker.php:16
static getList(array $parameters=array())
Определения entitymarker.php:906
static updateInternal($primary, array $data)
Определения entitymarker.php:933
static getMarker($orderCode, Internals\Entity $entity=null)
Определения entitymarker.php:232
static resetMarkers($orderCode=null)
Определения entitymarker.php:629
const ENTITY_TYPE_SHIPMENT
Определения entitymarker.php:20
static saveMarkers(Order $order=null)
Определения entitymarker.php:296
static addInternal(array $data)
Определения entitymarker.php:928
static deleteByOrderId($id)
Определения entitymarker.php:1025
const ENTITY_TYPE_PAYMENT
Определения entitymarker.php:21
const ENTITY_TYPE_PROPERTY_VALUE
Определения entitymarker.php:22
static deleteByFilter(array $values)
Определения entitymarker.php:1068
static getEntityTypeList()
Определения entitymarker.php:258
static deleteByEntity(Internals\Entity $entity)
Определения entitymarker.php:1047
static updateMarker($id, array $values, Order $order, Internals\Entity $entity)
Определения entitymarker.php:103
static updateItem($id, $values, Order $order, $entityType)
Определения entitymarker.php:171
static tryFixErrorsByOrder(Order $order, $markerId=null)
Определения entitymarker.php:648
const ENTITY_MARKED_TYPE_AUTO
Определения entitymarker.php:15
const ENTITY_SUCCESS_CODE_FAIL
Определения entitymarker.php:24
const SALE_ORDER_HISTORY_ACTION_LOG_LEVEL_1
Определения orderhistory.php:29
static addAction($entityName, $orderId, $type, $id=null, $entity=null, array $fields=array(), $level=null)
Определения orderhistory.php:97
static getInstance($type)
Определения registry.php:183
const REGISTRY_TYPE_ORDER
Определения registry.php:16
$data['IS_AVAILABLE']
Определения .description.php:13
$orderId
Определения payment.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
$entity
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
Определения ufield.php:9
Определения collection.php:2
$payment
Определения payment.php:14
$order
Определения payment.php:8
$paymentCollection
Определения payment.php:11
$entityId
Определения payment.php:4
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$fields
Определения yandex_run.php:501