Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
importcriterion.php
1<?php
3
4
8
10 implements Exchange\ICriterion
11{
12 use Exchange\BaseTrait;
13
14 protected $entity = null;
15
19 public function getEntity()
20 {
21 return $this->entity;
22 }
23
27 public function setEntity($entity = null)
28 {
29 $this->entity = $entity;
30 }
31
39 public static function getCurrent($entityTypeId, $entity)
40 {
41 if(!Exchange\EntityType::IsDefined($entityTypeId))
42 {
44 }
45
47 $criterion = new static();
48 $criterion->setEntity($entity);
49
50 return $criterion;
51 }
52
57 public function equals(array $fields)
58 {
59 return true;
60 }
61
62 protected function getParentTypeId()
63 {
64 return Exchange\EntityType::ORDER;
65 }
66
67 protected function getShipmentTypeId()
68 {
69 return Exchange\EntityType::SHIPMENT;
70 }
71}
72
74{
79 public function equals(array $fields)
80 {
82 $entity = $this->getEntity();
83 if(empty($entity))
84 {
85 return true;
86 }
87
88 if(($entity->getField('VERSION_1C') != $fields['VERSION_1C']) ||
89 ($entity->getField('VERSION_1C') == '' || $fields['VERSION_1C'] == '')
90 )
91 {
92 return true;
93 }
94
95 return false;
96 }
97}
98
100 implements Exchange\ICriterionOrder
101{
107 public function equalsBasketItemTax(Sale\BasketItem $basketItem, array $fields)
108 {
109 if($fields['TAX']['VAT_RATE'] != $basketItem->getVatRate()
110 || $fields['TAX']['VAT_INCLUDED']<>$basketItem->getField('VAT_INCLUDED'))
111 {
112 return true;
113 }
114
115 return false;
116 }
117
123 public function equalsBasketItem(Sale\BasketItem $basketItem, array $fields)
124 {
125 if($fields['QUANTITY'] != $basketItem->getQuantity() ||
126 $fields['PRICE'] != $basketItem->getPrice() ||
127 $fields['VAT_RATE'] != $basketItem->getVatRate() ||
128 $fields['DISCOUNT_PRICE'] != $basketItem->getDiscountPrice())
129 {
130 return true;
131 }
132
133 return false;
134 }
135
141 public function equalsBasketItemDiscount(Sale\BasketItem $basketItem, array $fields)
142 {
143 if($fields['DISCOUNT']['PRICE'] != $basketItem->getDiscountPrice() && intval($fields['DISCOUNT']['PRICE'])>0)
144 {
145 return true;
146 }
147
148 return false;
149 }
150
155 public function setEntity($entity = null)
156 {
157 if(!empty($entity) && !($entity instanceof Sale\Order))
158 throw new Main\ArgumentException("Entity must be instanceof Order");
159
160 parent::setEntity($entity);
161 }
162}
163
165{
166
171 public function setEntity($entity = null)
172 {
173 if(!empty($entity) && !($entity instanceof Sale\Shipment))
174 throw new Main\ArgumentException("Entity must be instanceof Shipment");
175
176 parent::setEntity($entity);
177 }
178
183 public function equals(array $fields)
184 {
186 $entity = $this->getEntity();
187 if(empty($entity))
188 {
189 return true;
190 }
191
192 $bBasketItemsMatch = true;
193 $basketItemsIndexList = array();
194 $fieldsItemsIndexList = array();
196 $parentImport = $this->entityFactoryCreate($this->getParentTypeId());
198 $shipmentImport = $this->entityFactoryCreate($this->getShipmentTypeId());
199
200 $basketItems = $parentImport::getGroupItemsBasketFields($fields['ITEMS']);
201 if(count($basketItems)<=0)
202 {
203 return true;
204 }
205
207 $shipmentCollection = $entity->getCollection();
208 $order = $shipmentCollection->getOrder();
209 $basket = $order->getBasket();
211 foreach ($basket as $basketItem)
212 {
213 if($entity->isExistBasketItem($basketItem))
214 {
215 $quantity = $entity->getBasketItemQuantity($basketItem);
216 if($quantity>0)
217 {
218 $basketItemsIndexList[$basketItem->getId()] = $quantity;
219 }
220 }
221 }
222
223 foreach($basketItems as $items)
224 {
225 foreach($items as $productXML_ID => $item)
226 {
227 if($basketItem = $parentImport::getBasketItemByItem($basket, $item))
228 {
229 $fieldsItemsIndexList[$basketItem->getId()] = $item['QUANTITY'];
230 }
231 }
232 }
233
234 if(count($basketItemsIndexList)<>count($fieldsItemsIndexList))
235 {
236 $bBasketItemsMatch = false;
237 }
238 else
239 {
240 foreach ($basketItemsIndexList as $basketId=>$quantity)
241 {
242 if(isset($fieldsItemsIndexList[$basketId]) && $fieldsItemsIndexList[$basketId] == $quantity)
243 unset($fieldsItemsIndexList[$basketId]);
244 }
245
246 if(count($fieldsItemsIndexList)>0)
247 $bBasketItemsMatch = false;
248 }
249
250 $itemDeliveryService = $shipmentImport::getFieldsDeliveryService($fields);
251
252 if($bBasketItemsMatch &&
253 ($entity->isShipped()? $fields['DEDUCTED']=='Y':true) &&
254 $entity->getPrice() == $itemDeliveryService['PRICE']
255 )
256 {
257 return false;
258 }
259 else
260 {
261 return true;
262 }
263 }
264}
265
267{
268 protected function getParentTypeId()
269 {
270 return Exchange\EntityType::INVOICE;
271 }
272
273 protected function getShipmentTypeId()
274 {
275 return Exchange\EntityType::INVOICE_SHIPMENT;
276 }
277}
278
280{
285 public function setEntity($entity = null)
286 {
287 if(!empty($entity) && !($entity instanceof Sale\Payment))
288 throw new Main\ArgumentException("Entity must be instanceof Payment");
289
290 parent::setEntity($entity);
291 }
292
297 public function equals(array $fields)
298 {
300 $entity = $this->getEntity();
301 if(empty($entity))
302 {
303 return true;
304 }
305
306 if(($entity->isPaid()? $fields['PAID']=='Y':true) &&
307 $entity->getSum() == $fields['SUM']
308 )
309 {
310 return false;
311 }
312 else
313 {
314 return true;
315 }
316 }
317}
318
325{
330 public function equals(array $fields)
331 {
332 $entity = $this->getEntity();
333 if(empty($entity))
334 {
335 return true;
336 }
337
338 if(($entity->getField('USER_PROFILE_VERSION') != $fields['VERSION_1C']) ||
339 ($entity->getField('USER_PROFILE_VERSION') == '' || $fields['VERSION_1C'] == '')
340 )
341 {
342 return true;
343 }
344
345 return false;
346 }
347
352 public function setEntity($entity = null)
353 {
354 if(!empty($entity) && !($entity instanceof Exchange\ProfileImport))
355 throw new Main\ArgumentException("Entity must be instanceof ProfileImport");
356
357 parent::setEntity($entity);
358 }
359}
equalsBasketItemTax(Sale\BasketItem $basketItem, array $fields)
equalsBasketItem(Sale\BasketItem $basketItem, array $fields)
equalsBasketItemDiscount(Sale\BasketItem $basketItem, array $fields)