Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
shipmentrepository.php
1<?php
2
4
6
13{
15 private static $instance;
16
20 private function __construct()
21 {}
22
26 public static function getInstance(): ShipmentRepository
27 {
28 if (is_null(static::$instance))
29 {
30 static::$instance = new ShipmentRepository();
31 }
32
33 return static::$instance;
34 }
35
40 public function getById(int $id): ?Sale\Shipment
41 {
43 $shipmentClass = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getShipmentClassName();
44
45 $shipmentRow = $shipmentClass::getList([
46 'select' => ['ID', 'ORDER_ID'],
47 'filter' => [
48 '=ID' => $id
49 ]
50 ])->fetch();
51 if (!$shipmentRow)
52 {
53 return null;
54 }
55
56 return static::getInstance()->getByRow($shipmentRow);
57 }
58
63 public function getByIds(array $ids): array
64 {
65 $result = [];
66
68 $shipmentClass = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getShipmentClassName();
69
70 $shipmentList = $shipmentClass::getList([
71 'select' => ['ID', 'ORDER_ID'],
72 'filter' => [
73 '=ID' => $ids
74 ]
75 ]);
76
77 while ($shipmentRow = $shipmentList->fetch())
78 {
79 $shipment = static::getInstance()->getByRow($shipmentRow);
80 if (is_null($shipment))
81 {
82 continue;
83 }
84
85 $result[] = $shipment;
86 }
87
88 return $result;
89 }
90
95 private function getByRow(array $shipmenRow): ?Sale\Shipment
96 {
97 $orderClassName = Sale\Registry::getInstance(Sale\Registry::REGISTRY_TYPE_ORDER)->getOrderClassName();
98
100 $order = $orderClassName::load($shipmenRow['ORDER_ID']);
101 if ($order === null)
102 {
103 return null;
104 }
105
106 $shipmentCollection = $order->getShipmentCollection();
107
109 foreach ($shipmentCollection as $shipment)
110 {
111 if ($shipment->getId() !== (int)$shipmenRow['ID'])
112 {
113 continue;
114 }
115
116 return $shipment;
117 }
118
119 return null;
120 }
121}
fetch(Main\Text\Converter $converter=null)
Definition entity.php:112