1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
objectnormalizer.php
См. документацию.
1<?php
2
3
4namespace Bitrix\Sale\Rest\Normalizer;
5
6use Bitrix\Sale\BasketItem;
7use Bitrix\Sale\Payment;
8use Bitrix\Sale\PropertyValue;
9use Bitrix\Sale\Shipment;
10use Bitrix\Sale\ShipmentItem;
11use Bitrix\Sale\ShipmentItemStore;
12
19{
20 protected $externalFields;
21 protected $fields;
22 protected $order;
23
24 public function __construct(array $data=[])
25 {
26 $this->externalFields = $data;
27 }
28
29 public function init(\Bitrix\Sale\Order $order)
30 {
31 $this->order = $order;
32 return $this;
33 }
34
35 public function orderNormalize()
36 {
37 $externalFields = isset($this->externalFields['ORDER'][$this->getOrder()->getInternalId()])?
38 $this->externalFields['ORDER'][$this->getOrder()->getInternalId()]:[];
39
40 $this->fields['ORDER'] = array_merge(
42 $this->getOrder()->getFieldValues()
43 );
44 return $this;
45 }
46
47 public function basketNormalize()
48 {
49 $r=[];
50
52 foreach ($this->getOrder()->getBasket() as $item)
53 {
54 $fields = $item->getFieldValues();
55 $externalFields = $this->externalFields['BASKET']['ITEMS'][$item->getInternalIndex()] ?? [];
56
57 $props = [];
58 foreach ($item->getPropertyCollection() as $property)
59 {
60 $props[] = $property->getFieldValues();
61 }
62
63 $reservations = [];
64 $reserveQuantityCollection = $item->getReserveQuantityCollection();
65 if ($reserveQuantityCollection !== null)
66 {
67 foreach ($item->getReserveQuantityCollection() as $reserveQuantityCollectionItem)
68 {
69 $reservations[] = $reserveQuantityCollectionItem->getFieldValues();
70 }
71 }
72 unset($reserveQuantityCollection);
73
74 $r[$item->getInternalIndex()] = array_merge(
76 $fields,
77 [
78 'PROPERTIES' => $props,
79 'RESERVATIONS' => $reservations,
80 ]
81 );
82 }
83
84 $this->fields['ORDER']['BASKET_ITEMS']=$r;
85
86 return $this;
87 }
88
89 public function propertiesValueNormalize()
90 {
91 $r=[];
92 $propertyCollection = $this->getOrder()->getPropertyCollection();
94 foreach ($propertyCollection as $property)
95 {
96 $externalFields = isset($this->externalFields['PROPERTIES'][$property->getInternalIndex()])?
97 $this->externalFields['PROPERTIES'][$property->getInternalIndex()]:[];
98
99 $r[$property->getInternalIndex()] = array_merge(
101 $property->getFieldValues()
102 );
103 }
104 $this->fields['ORDER']['PROPERTY_VALUES']=$r;
105 return $this;
106 }
107 public function paymentsNormalize()
108 {
109 $r=[];
111 foreach($this->getOrder()->getPaymentCollection() as $payment)
112 {
113 $externalFields = isset($this->externalFields['PAYMENTS'][$payment->getInternalIndex()])?
114 $this->externalFields['PAYMENTS'][$payment->getInternalIndex()]:[];
115
116 $r[$payment->getInternalIndex()] = array_merge(
118 $payment->getFieldValues()
119 );
120 }
121 $this->fields['ORDER']['PAYMENTS']=$r;
122 return $this;
123 }
124 public function shipmentsNormalize()
125 {
126 $r=[];
128 foreach ($this->getOrder()->getShipmentCollection() as $shipment)
129 {
130 // рест магазина не оперирует системными отгрузками
131 if($shipment->isSystem())
132 continue;
133
134 $shipmentIndex = $shipment->getInternalIndex();
135
136 $basketItems = [];
138 foreach ($shipment->getShipmentItemCollection() as $shipmentItem)
139 {
140 $itemIndex = $shipmentItem->getInternalIndex();
141 $stores=[];
142 $storeCollection = $shipmentItem->getShipmentItemStoreCollection();
143 if ($storeCollection !== null)
144 {
146 foreach ($shipmentItem->getShipmentItemStoreCollection() as $shipmentItemStore)
147 {
148 $externalFieldsSIS = $this->externalFields['SHIPMENTS'][$shipmentIndex]['SHIPMENT_ITEMS'][$itemIndex]['STORE'][$shipmentItemStore->getInternalIndex()] ?? [];
149
150 $stores[] = array_merge(
151 $externalFieldsSIS,
152 $shipmentItemStore->getFieldValues()
153 );
154 }
155 }
156
157 $externalFieldsSI = $this->externalFields['SHIPMENTS'][$shipmentIndex]['SHIPMENT_ITEMS'][$itemIndex] ?? [];
158
159 $basketItems[] = array_merge(
160 $externalFieldsSI,
161 $shipmentItem->getFieldValues(),
162 ['STORES'=>$stores]
163 );
164
165 }
166
167 $externalFields = $this->externalFields['SHIPMENTS'][$shipmentIndex] ?? [];
168
169 $r[$shipmentIndex] = array_merge(
171 $shipment->getFieldValues(),
172 ['SHIPMENT_ITEMS'=>$basketItems]
173 );
174 }
175 $this->fields['ORDER']['SHIPMENTS']= $r;
176
177 return $this;
178 }
179 public function applyDiscountNormalize()
180 {
181 $list = $this->getOrder()
182 ->getDiscount()
183 ->getApplyResult(true);
184 if(is_array($list) && !empty($list))
185 {
186 $this->fields['ORDER']['DISCOUNTS'] = $list;
187 }
188 return $this;
189 }
190 public function taxNormalize()
191 {
192 $list = $this->getOrder()
193 ->getTax()
194 ->getTaxList();
195 if(is_array($list) && !empty($list))
196 {
197 foreach ($list as $tax)
198 $this->fields['ORDER']['TAXES'][] = $tax;
199 }
200 return $this;
201 }
202 public function tradeBindingsNormalize()
203 {
204 $r=[];
206 foreach($this->getOrder()->getTradeBindingCollection() as $item)
207 {
208 $externalFields = isset($this->externalFields['TRADE_BINDINGS'][$item->getInternalIndex()])?
209 $this->externalFields['TRADE_BINDINGS'][$item->getInternalIndex()]:[];
210
211 $r[] = array_merge(
213 $item->getFieldValues()
214 );
215 }
216
217 $this->fields['ORDER']['TRADE_BINDINGS']=$r;
218 return $this;
219 }
220
221 public function getFields()
222 {
223 return $this->fields;
224 }
225
228 protected function getOrder()
229 {
230 return $this->order;
231 }
232}
init(\Bitrix\Sale\Order $order)
Определения objectnormalizer.php:29
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$payment
Определения payment.php:14
$props
Определения template.php:269
$fields
Определения yandex_run.php:501