Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
objectnormalizer.php
1<?php
2
3
5
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 public function basketNormalize()
47 {
48 $r=[];
50 foreach ($this->getOrder()->getBasket() as $item)
51 {
52 $fields = $item->getFieldValues();
53 $externalFields = isset($this->externalFields['BASKET']['ITEMS'][$item->getInternalIndex()])?
54 $this->externalFields['BASKET']['ITEMS'][$item->getInternalIndex()]:[];
55
56 $props = [];
57 foreach ($item->getPropertyCollection() as $property)
58 {
59 $props[] = array_merge(
60 $property->getFieldValues()
61 );
62 }
63
64 $r[$item->getInternalIndex()] = array_merge(
66 $fields,
67 ['PROPERTIES'=>$props]
68 );
69 }
70 $this->fields['ORDER']['BASKET_ITEMS']=$r;
71 return $this;
72 }
73 public function propertiesValueNormalize()
74 {
75 $r=[];
76 $propertyCollection = $this->getOrder()->getPropertyCollection();
78 foreach ($propertyCollection as $property)
79 {
80 $externalFields = isset($this->externalFields['PROPERTIES'][$property->getInternalIndex()])?
81 $this->externalFields['PROPERTIES'][$property->getInternalIndex()]:[];
82
83 $r[$property->getInternalIndex()] = array_merge(
85 $property->getFieldValues()
86 );
87 }
88 $this->fields['ORDER']['PROPERTY_VALUES']=$r;
89 return $this;
90 }
91 public function paymentsNormalize()
92 {
93 $r=[];
95 foreach($this->getOrder()->getPaymentCollection() as $payment)
96 {
97 $externalFields = isset($this->externalFields['PAYMENTS'][$payment->getInternalIndex()])?
98 $this->externalFields['PAYMENTS'][$payment->getInternalIndex()]:[];
99
100 $r[$payment->getInternalIndex()] = array_merge(
102 $payment->getFieldValues()
103 );
104 }
105 $this->fields['ORDER']['PAYMENTS']=$r;
106 return $this;
107 }
108 public function shipmentsNormalize()
109 {
110 $r=[];
112 foreach ($this->getOrder()->getShipmentCollection() as $shipment)
113 {
114 //
115 if($shipment->isSystem())
116 continue;
117
118 $basketItems = [];
120 foreach ($shipment->getShipmentItemCollection() as $shipmentItem)
121 {
122 $stores=[];
124 foreach ($shipmentItem->getShipmentItemStoreCollection() as $shipmentItemStore)
125 {
126 $externalFieldsSIS = isset($this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()]['SHIPMENT_ITEMS'][$shipmentItem->getInternalIndex()]['STORE'][$shipmentItemStore->getInternalIndex()])?
127 $this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()]['SHIPMENT_ITEMS'][$shipmentItem->getInternalIndex()]['STORE'][$shipmentItemStore->getInternalIndex()]:[];
128
129 $stores[] = array_merge(
130 $externalFieldsSIS,
131 $shipmentItemStore->getFieldValues()
132 );
133 }
134
135 $externalFieldsSI = isset($this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()]['SHIPMENT_ITEMS'][$shipmentItem->getInternalIndex()])?
136 $this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()]['SHIPMENT_ITEMS'][$shipmentItem->getInternalIndex()]:[];
137
138 $basketItems[] = array_merge(
139 $externalFieldsSI,
140 $shipmentItem->getFieldValues(),
141 ['STORES'=>$stores]
142 );
143
144 }
145
146 $externalFields = isset($this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()])?
147 $this->externalFields['SHIPMENTS'][$shipment->getInternalIndex()]:[];
148
149 $r[$shipment->getInternalIndex()] = array_merge(
151 $shipment->getFieldValues(),
152 ['SHIPMENT_ITEMS'=>$basketItems]
153 );
154 }
155 $this->fields['ORDER']['SHIPMENTS']= $r;
156 return $this;
157 }
158 public function applyDiscountNormalize()
159 {
160 $list = $this->getOrder()
161 ->getDiscount()
162 ->getApplyResult(true);
163 if(is_array($list) && !empty($list))
164 {
165 $this->fields['ORDER']['DISCOUNTS'] = $list;
166 }
167 return $this;
168 }
169 public function taxNormalize()
170 {
171 $list = $this->getOrder()
172 ->getTax()
173 ->getTaxList();
174 if(is_array($list) && !empty($list))
175 {
176 foreach ($list as $tax)
177 $this->fields['ORDER']['TAXES'][] = $tax;
178 }
179 return $this;
180 }
181 public function tradeBindingsNormalize()
182 {
183 $r=[];
185 foreach($this->getOrder()->getTradeBindingCollection() as $item)
186 {
187 $externalFields = isset($this->externalFields['TRADE_BINDINGS'][$item->getInternalIndex()])?
188 $this->externalFields['TRADE_BINDINGS'][$item->getInternalIndex()]:[];
189
190 $r[] = array_merge(
192 $item->getFieldValues()
193 );
194 }
195
196 $this->fields['ORDER']['TRADE_BINDINGS']=$r;
197 return $this;
198 }
199
200 public function getFields()
201 {
202 return $this->fields;
203 }
207 protected function getOrder()
208 {
209 return $this->order;
210 }
211}