16 private static $proxyBasket = array();
26 return Sale\Registry::REGISTRY_TYPE_ORDER;
36 return BasketTable::getEntity();
44 return OrderCompatibility::class;
53 $this->query =
new OrderQuery(static::getEntity());
65 $basketCompatibility =
new static();
69 return $basketCompatibility;
81 public function fillBasket(
Sale\Basket $basket, array $requestFields)
90 if (empty($requestFields[
'BASKET_ITEMS']))
93 $isStartField = $order->isStartField();
95 $basketCodeList = array();
97 $r = $this->parseBasketItems($basket, $requestFields[
'BASKET_ITEMS']);
100 $result->addErrors($r->getErrors());
104 $resultData = $r->getData();
106 if (isset($resultData[
'BASKET']))
108 $basket = $resultData[
'BASKET'];
111 if (isset($resultData[
'BASKET_CODE_LIST']))
113 $basketCodeList = $resultData[
'BASKET_CODE_LIST'];
116 if (isset($resultData[
'BASKET_CHANGED']) && $resultData[
'BASKET_CHANGED'] ===
true)
118 $order->refreshVat();
121 if (!empty($basketCodeList) && is_array($basketCodeList))
123 foreach ($basketCodeList as $index => $basketCode)
132 $r = $order->doFinalAction(
true);
133 if (!$r->isSuccess())
135 $result->addErrors($r->getErrors());
139 if (($data = $r->getData())
140 && !empty($data) && is_array($data))
142 $result->setData($result->getData() + $data);
160 protected function parseBasketItems(
Sale\Basket $basket, array $requestBasketItems)
162 $result =
new Sale\Result();
164 $basketCodeList = array();
165 $basketItemList = array();
166 $basketParentList = array();
167 $basketChildList = array();
169 $basketChanged =
false;
171 $registry = Sale\Registry::getInstance(static::getRegistryType());
172 $basketItemEntity = $registry->getBasketItemClassName();
175 foreach ($requestBasketItems as $basketIndex => $basketItemData)
177 if (isset($basketItemData[
'SET_PARENT_ID']) && strval($basketItemData[
'SET_PARENT_ID']) !=
'')
179 $parentId = intval($basketItemData[
'SET_PARENT_ID']);
180 if ($basketItemData[
'TYPE'] != $basketItemEntity::TYPE_SET && !array_key_exists($parentId, $basketParentList))
182 $basketChildList[intval($basketItemData[
'SET_PARENT_ID'])] = $basketItemData[
'SET_PARENT_ID'];
191 $basketItemsIndexList = array();
193 foreach ($basket as $basketItem)
195 $basketItemsIndexList[$basketItem->getId()] =
true;
199 foreach ($requestBasketItems as $basketIndex => $basketItemData)
201 if (!isset($basketItemData[
'BASE_PRICE']) && isset($basketItemData[
'PRICE']))
203 $basketItemData[
'BASE_PRICE'] = $basketItemData[
'PRICE'];
207 if (isset($basketItemData[
'ID']) && intval($basketItemData[
'ID']) > 0)
210 if ($basketItem = $basket->getItemById($basketItemData[
'ID']))
212 if (isset($basketItemsIndexList[$basketItem->getId()]))
213 unset($basketItemsIndexList[$basketItem->getId()]);
221 $basketItem = $basketItemEntity::create($basket, $basketItemData[
'MODULE'], $basketItemData[
'PRODUCT_ID']);
222 $basketChanged =
true;
225 $itemDuplicate = (isset($basketItemData[
'DUPLICATE']) && $basketItemData[
'DUPLICATE'] ==
"Y");
227 $basketItemData[
'SORT'] =
$sort;
230 $basketFields = static::clearFields($basketItemData);
232 if ($order->getId() > 0)
235 if ($shipmentCollection = $order->getShipmentCollection())
237 if (count($shipmentCollection) == 2
238 && (isset($basketItemData[
'QUANTITY']) && floatval($basketItemData[
'QUANTITY']) <= $basketItem->getQuantity()))
242 foreach ($shipmentCollection as $shipment)
244 if ($shipment->isSystem())
248 $basketQuantity = $shipment->getBasketItemQuantity($basketItem);
249 if ($basketQuantity <= floatval($basketItemData[
'QUANTITY']))
254 if ($shipmentItemCollection = $shipment->getShipmentItemCollection())
257 if (!$shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))
260 $shipmentItem->setQuantity(floatval($basketItemData[
'QUANTITY']));
268 $isBasketItemCanBeAdded =
true;
271 if (\CSaleBasketHelper::isSetParent($basketItemData))
273 $parentId = (int)$basketItemData[
'ID'];
274 $parentCode = $basketItemData[
'ID'];
278 $parentId = (int)$basketItemData[
'SET_PARENT_ID'];
279 $parentCode = $basketItemData[
'SET_PARENT_ID'];
284 $parentId = (int)$basketItemData[
'SET_PARENT_ID'];
285 $parentCode = $basketItemData[
'SET_PARENT_ID'];
290 if ($basketItem->isBundleParent())
292 $basketParentList[$parentCode] = $basketItem->getBasketCode();
296 $isBasketItemCanBeAdded =
false;
297 $basketItemList[$parentCode][$basketIndex] = $basketItem;
301 if ($isBasketItemCanBeAdded)
305 if ($propertyCollection = $basketItem->getPropertyCollection())
307 $propList = $propertyCollection->getPropertyValues();
311 $foundedBasketItem =
null;
313 if ($basketItem->getId() > 0 && ($foundedBasketItem = $basket->getItemById($basketItem->getId())))
315 $basketCodeList[($publicMode ? $foundedBasketItem->getId() : $basketIndex)] = $foundedBasketItem->getBasketCode();
319 if (!$itemDuplicate && ($foundedBasketItem = $basket->getExistsItem($basketItem->getField(
'MODULE'), $basketItem->getProductId(), $propList)))
321 $basketCodeList[($publicMode ? $foundedBasketItem->getId() : $basketIndex)] = $foundedBasketItem->getBasketCode();
325 if ($foundedBasketItem ===
null)
327 $basket->addItem($basketItem);
328 $basketCodeList[($publicMode ? $basketItem->getId() : $basketIndex)] = $basketItem->getBasketCode();
330 $basketChanged =
true;
336 $r = $basketItem->setFields($basketFields);
339 if (array_key_exists(
'PROPS', $basketItemData) && is_array($basketItemData))
342 if ($propertyCollection = $basketItem->getPropertyCollection())
344 $propertyCollection->setProperty($basketItemData[
'PROPS']);
350 $result->addErrors($r->getErrors());
355 if (!empty($basketChildList))
357 foreach($basketItemList as $parentBasketCode => $childBasketItemList)
360 if (!empty($basketParentList[$parentBasketCode]))
361 $parentCode = $basketParentList[$parentBasketCode];
363 if (strval($parentCode) ==
'')
367 if (!$parentBasketItem = $basket->getItemByBasketCode($parentCode))
369 throw new Main\ObjectNotFoundException(
'Entity parent "BasketItem" not found');
372 if (!empty($childBasketItemList) && is_array($childBasketItemList))
375 foreach ($childBasketItemList as $indexChildBasketItem => $childBasketItem)
377 $basketCodeIndex = ($publicMode ? $childBasketItem->getId() : $indexChildBasketItem);
378 $childBasketCode = $childBasketItem->getBasketCode();
382 if ($propertyCollection = $childBasketItem->getPropertyCollection())
384 $propList = $propertyCollection->getPropertyValues();
387 $bundleCollection = $parentBasketItem->getBundleCollection();
389 if ($foundedBasketItem = $bundleCollection->getExistsItem($childBasketItem->getField(
'MODULE'), $childBasketItem->getProductId(), $propList))
391 $childBasketCode = $foundedBasketItem->getBasketCode();
392 unset($childBasketItemList[$indexChildBasketItem]);
393 $basketCodeIndex = ($publicMode ? $foundedBasketItem->getId() : $indexChildBasketItem);
396 if (strval($childBasketCode) !=
'')
397 $basketCodeList[$basketCodeIndex] = $childBasketCode;
400 if (!empty($childBasketItemList))
402 $this->setChildBundleCollection($basket, $childBasketItemList, $parentBasketItem);
408 if (!empty($basketItemsIndexList) && is_array($basketItemsIndexList))
410 foreach ($basketItemsIndexList as $basketIndexId => $basketIndexValue)
412 if ($foundedBasketItem = $basket->getItemById($basketIndexId))
414 $foundedBasketItem->delete();
415 $basketChanged =
true;
420 $result->setData(array(
422 'BASKET_CODE_LIST' => $basketCodeList,
423 'BASKET_CHANGED' => $basketChanged,
436 private function setChildBundleCollection(
Sale\Basket $basket, array $basketItemList,
Sale\BasketItem $externalParentBasketItem =
null)
440 $isExternalBasketParent =
false;
442 if ($externalParentBasketItem !==
null)
444 if (!$externalParentBasketItem->isBundleParent())
446 throw new Main\ObjectException(
'basketItem not parent');
448 $isExternalBasketParent =
true;
452 foreach ($basketItemList as $item)
454 if ($item->isBundleChild() || (!$item->isBundleParent() && $isExternalBasketParent && $externalParentBasketItem !==
null))
457 $parentBasketItem = $item->getParentBasketItem();
459 if (!$parentBasketItem && $externalParentBasketItem !==
null)
461 $parentBasketItem = $externalParentBasketItem;
464 if ($parentBasketItem)
467 $bundleCollection = $parentBasketItem->createBundleCollection();
469 if ($basket->getItemByBasketCode($parentBasketItem->getBasketCode()))
471 $bundleCollection->addItem($item);
475 $basket->addItem($item);
481 if (!$basket = $parentBasketItem->getCollection())
483 throw new Main\ObjectNotFoundException(
'Entity "Basket" not found');
487 $order = $basket->getOrder();
490 if ($bundleCollection->getOrder() ===
null && $order instanceof
Sale\OrderBase)
491 $bundleCollection->setOrder($order);
509 $result =
new Sale\Result();
515 $registry = Sale\Registry::getInstance(static::getRegistryType());
517 if (!array_key_exists(
'FUSER_ID',
$fields) || intval(
$fields[
'FUSER_ID']) <= 0)
519 $fields[
'FUSER_ID'] = Sale\Fuser::getId(
false);
522 if (!empty(
$fields[
'ORDER_ID']) && intval(
$fields[
'ORDER_ID']) > 0)
525 $orderClassName = $registry->getOrderClassName();
526 $order = $orderClassName::load(intval(
$fields[
'ORDER_ID']));
531 $basket = $order->getBasket();
538 $basketClassName = $registry->getBasketClassName();
539 $basket = $basketClassName::loadItemsForFUser(
$fields[
"FUSER_ID"],
$fields[
'LID']);
546 $item->setField(
'QUANTITY', $item->getQuantity() +
$fields[
'QUANTITY']);
551 $r = $item->setFields(static::clearFields(
$fields));
552 if (!$r->isSuccess())
554 $result->addErrors($r->getErrors());
560 $basket->refreshData(array(
'PRICE',
'COUPONS',
'QUANTITY'), $item);
567 $item = $basket->createItem(
$fields[
"MODULE"],
$fields[
"PRODUCT_ID"]);
572 $property = $item->getPropertyCollection();
573 $property->setProperty(
$fields[
"PROPS"]);
577 $r = $item->setFields(static::clearFields(
$fields));
578 if (!$r->isSuccess())
580 $result->addErrors($r->getErrors());
586 $shipmentCollection = $order->getShipmentCollection();
587 $systemShipment = $shipmentCollection->getSystemShipment();
588 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
589 $systemShipmentItemCollection->resetCollection($basket);
591 if ($systemShipment->getDeliveryId() > 0)
594 $orderCompatibilityClassName = static::getOrderCompatibilityClassName();
596 $shipment = $orderCompatibilityClassName::getShipmentByDeliveryId($shipmentCollection, $systemShipment->getDeliveryId());
600 if ($service =
Sale\Delivery\Services\Manager::getObjectById($systemShipment->getDeliveryId()))
603 $shipment = $shipmentCollection->createItem($service);
610 $shipmentItemCollection = $shipment->getShipmentItemCollection();
613 $shipmentItem = $shipmentItemCollection->createItem($item);
615 $shipmentItem->setQuantity($item->getQuantity());
620 $r = $order->refreshData(array(
'PRICE',
'PRICE_DELIVERY'));
621 if (!$r->isSuccess())
623 $result->addErrors($r->getErrors());
634 if (!$r->isSuccess())
636 $result->addErrors($r->getErrors());
642 if ($item->getId() == 0)
647 $r = $basket->save();
648 if (!$r->isSuccess())
650 $result->addErrors($r->getErrors());
660 $id = $item->getId();
665 $result->setId($item->getId());
666 $result->addData(array(
667 'QUANTITY' => $item->getQuantity()
686 public static function update($id, array
$fields)
688 $result =
new Sale\Result();
696 $registry = Sale\Registry::getInstance(static::getRegistryType());
699 $itemResult = static::loadEntityFromBasket($id);
700 if ($itemResult->isSuccess())
702 $itemResultData = $itemResult->getData();
703 if (isset($itemResultData[
'BASKET_ITEM']))
706 $item = $itemResultData[
'BASKET_ITEM'];
707 $basket = $item->getBasket();
710 if (isset($itemResultData[
'ORDER']))
712 $order = $itemResultData[
'ORDER'];
718 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_NOT_FOUND'),
'BASKET_ITEM_NOT_FOUND'));
723 if ($order !==
null &&
725 (
int)
$fields[
'ORDER_ID'] !== (
int)$order->getId()
729 new Sale\ResultError(
730 Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_ERROR_BIND_TO_ORDER'),
731 'BASKET_ITEM_NOT_FOUND'
741 $property = $item->getPropertyCollection();
742 $property->clearCollection();
743 $property->setProperty(
$fields[
"PROPS"]);
746 if ($order !==
null && isset(
$fields[
'PRICE']))
748 if (
$fields[
'PRICE'] != $item->getPrice())
752 if (!empty(
$fields[
'FUSER_ID']))
754 $item->setFieldNoDemand(
'FUSER_ID', intval(
$fields[
'FUSER_ID']));
758 $r = $item->setFields(static::clearFields(
$fields));
759 if (!$r->isSuccess())
761 $result->addErrors($r->getErrors());
776 if ($order ===
null && !empty(
$fields[
'ORDER_ID']) && intval(
$fields[
'ORDER_ID']) > 0)
778 $orderId = intval(
$fields[
'ORDER_ID']);
780 $orderClassName = $registry->getOrderClassName();
781 if ($order = $orderClassName::load($orderId))
784 if ($basket = $order->getBasket())
786 $basket->addItem($item);
789 if (!$shipmentCollection = $order->getShipmentCollection())
791 throw new Main\ObjectNotFoundException(
'Entity "ShipmentCollection" not found');
795 $orderCompatibilityClassName = static::getOrderCompatibilityClassName();
796 $orderCompatibilityClassName::createShipmentFromShipmentSystem($shipmentCollection);
799 $r = static::syncShipmentCollectionAndBasket($shipmentCollection, $basket);
800 if (!$r->isSuccess())
802 $result->addErrors($r->getErrors());
806 $r = $order->refreshData(array(
"PRICE_DELIVERY"));
807 if (!$r->isSuccess())
809 $result->addErrors($r->getErrors());
813 $r = $order->doFinalAction(
true);
814 if (!$r->isSuccess())
816 $result->addErrors($r->getErrors());
827 if ($shipmentCollection = $order->getShipmentCollection())
829 if (count($shipmentCollection) == 2 && $shipmentCollection->isExistsSystemShipment())
832 foreach ($shipmentCollection as $shipment)
834 if ($shipment->isSystem() || $shipment->isShipped())
838 $systemShipment = $shipmentCollection->getSystemShipment();
841 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
844 if (!$systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($item->getBasketCode()))
848 if (!$shipmentItemCollection = $shipment->getShipmentItemCollection())
853 if (!$shipmentItem = $shipmentItemCollection->getItemByBasketCode($item->getBasketCode()))
857 if ($systemShipmentItem->getQuantity() > 0)
859 $r = $shipmentItem->setQuantity(($shipmentItem->getQuantity() + $systemShipmentItem->getQuantity()));
860 if (!$r->isSuccess())
862 $result->addErrors($r->getErrors());
869 if (!$result->isSuccess())
878 if (!$result->isSuccess())
883 $r = $basket->save();
886 if (!$r->isSuccess())
888 $result->addErrors($r->getErrors());
901 public static function delete($id)
903 $result =
new Sale\Result();
909 $registry = Sale\Registry::getInstance(static::getRegistryType());
911 $basketClassName = $registry->getBasketClassName();
912 $res = $basketClassName::getList(
918 'ID',
'ORDER_ID',
'SET_PARENT_ID',
'TYPE',
'FUSER_ID',
'LID'
921 if (!$itemDat = $res->fetch())
923 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_NOT_FOUND'),
'BASKET_ITEM_NOT_FOUND'));
927 if (intval($itemDat[
'ORDER_ID']) > 0)
930 $orderClassName = $registry->getOrderClassName();
932 if ($order = $orderClassName::load(intval($itemDat[
'ORDER_ID'])))
934 if ($basket = $order->getBasket())
937 $item = $basket->getItemById($id);
943 if (!array_key_exists(
'FUSER_ID', $itemDat) || intval($itemDat[
'FUSER_ID']) <= 0)
945 $itemDat[
'FUSER_ID'] = Sale\Fuser::getId();
949 $basketClassName = $registry->getBasketClassName();
950 if ($basket = $basketClassName::loadItemsForFUser($itemDat[
"FUSER_ID"], $itemDat[
'LID']))
953 $item = $basket->getItemById($id);
957 if ($basket ===
null)
959 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_COLLECTION_NOT_FOUND'),
'BASKET_COLLECTION_NOT_FOUND'));
966 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_PROPS_NOT_FOUND'),
'BASKET_ITEM_PROPS_NOT_FOUND'));
972 $r = $item->delete();
973 if (!$r->isSuccess())
975 $result->addErrors($r->getErrors());
980 if (!$result->isSuccess())
990 if (!$result->isSuccess())
996 $r = $basket->save();
1000 Sale\BasketComponentHelper::clearFUserBasketQuantity($itemDat[
'FUSER_ID'], $itemDat[
'LID']);
1001 Sale\BasketComponentHelper::clearFUserBasketPrice($itemDat[
'FUSER_ID'], $itemDat[
'LID']);
1005 if (!$r->isSuccess())
1007 $result->addErrors($r->getErrors());
1020 'ORDER_STATUS' =>
'ORDER.STATUS_ID',
1021 'ORDER_CANCELED' =>
'ORDER.CANCELED',
1022 'ORDER_PRICE' =>
'ORDER.PRICE',
1023 'ORDER_DATE' =>
'ORDER.DATE_INSERT',
1025 'USER_ID' =>
'USER.ID',
1027 'SUM_PRICE' =>
'SUMMARY_PRICE',
1029 'ORDER_ALLOW_DELIVERY' =>
'SHIPMENT.ALLOW_DELIVERY',
1030 'ORDER_DATE_ALLOW_DELIVERY' =>
'SHIPMENT.DATE_ALLOW_DELIVERY',
1031 'DEDUCTED' =>
'SHIPMENT.DEDUCTED',
1032 'SHIPMENT_SYSTEM' =>
'SHIPMENT.SYSTEM',
1034 'ORDER_PAYED' =>
'PAYMENT.PAID',
1035 'ORDER_DATE_PAYED' =>
'PAYMENT.DATE_PAID',
1046 return array_keys(static::getEntity()->getScalarFields());
1055 $registry = Sale\Registry::getInstance(static::getRegistryType());
1056 $basketItemClassName = $registry->getBasketItemClassName();
1057 $fields = $basketItemClassName::getAvailableFields();
1059 if ($index = array_search(
'SET_PARENT_ID',
$fields))
1071 protected static function loadEntityFromBasket($id)
1079 $registry = Sale\Registry::getInstance(static::getRegistryType());
1080 $basketClassName = $registry->getBasketClassName();
1081 $res = $basketClassName::getList(array(
1086 'ID',
'ORDER_ID',
'SET_PARENT_ID',
'TYPE',
'FUSER_ID',
'LID'
1089 if (!$itemDat = $res->fetch())
1091 $result->addError(
new Sale\
ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_NOT_FOUND'),
'BASKET_ITEM_NOT_FOUND'));
1095 if (intval($itemDat[
'ORDER_ID']) > 0)
1097 $orderClassName = $registry->getOrderClassName();
1099 if ($order = $orderClassName::load(intval($itemDat[
'ORDER_ID'])))
1101 if ($basket = $order->getBasket())
1104 $item = $basket->getItemById($id);
1110 $basketClassName = $registry->getBasketClassName();
1112 $basket = $basketClassName::loadItemsForFUser($itemDat[
"FUSER_ID"], $itemDat[
'LID']);
1117 $item = $basket->getItemById($id);
1123 'BASKET_ITEM' => $item
1126 if ($order !==
null)
1128 $data[
'ORDER'] = $order;
1131 $result->setData($data);
1145 protected static function appendBasketToOrder(
Sale\Order $order,
Sale\Basket $basket)
1147 $result =
new Sale\Result();
1149 $orderBasketCollection = $order->getBasket();
1151 $shipmentCollection = $order->getShipmentCollection();
1152 $systemShipment = $shipmentCollection->getSystemShipment();
1153 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
1156 foreach ($basket as $basketItem)
1158 $basketProperty = array();
1159 if ($basketPropertyCollection = $basketItem->getPropertyCollection())
1161 $basketProperty = $basketPropertyCollection->getPropertyValues();
1164 if ($orderBasketItem = $orderBasketCollection->getExistsItem($basketItem->getField(
'MODULE'), $basketItem->getField(
'PRODUCT_ID'), $basketProperty))
1166 $fields = $basketItem->getFieldValues();
1167 $orderBasketItem->setFields(static::clearFields(
$fields));
1172 $orderBasketCollection->addItem($basketItem);
1173 $basketItem->setCollection($orderBasketCollection);
1176 $systemShipmentItemCollection->resetCollection($orderBasketCollection);
1181 foreach ($basket as $basketItem)
1183 if ($systemShipment->getDeliveryId() > 0)
1186 $orderCompatibilityClassName = static::getOrderCompatibilityClassName();
1189 $shipment = $orderCompatibilityClassName::getShipmentByDeliveryId($shipmentCollection, $systemShipment->getDeliveryId());
1193 if ($service =
Sale\Delivery\Services\Manager::getObjectById($systemShipment->getDeliveryId()))
1196 $shipment = $shipmentCollection->createItem($service);
1203 $shipmentItemCollection = $shipment->getShipmentItemCollection();
1205 if (!$shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))
1207 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
1211 $r = $shipmentItem->setQuantity($basketItem->getQuantity());
1212 if (!$r->isSuccess())
1214 $result->addErrors($r->getErrors());
1229 public static function setBasketFields(array $list)
1231 $result =
new Sale\Result();
1238 foreach ($list as $basketId =>
$fields)
1240 $basketItemResult = static::loadEntityFromBasket($basketId);
1241 if ($basketItemResult->isSuccess())
1243 $basketItemResultList = $basketItemResult->getData();
1244 if (isset($basketItemResultList[
'BASKET']))
1247 $basket = $basketItemResultList[
'BASKET'];
1250 if (isset($basketItemResultList[
'BASKET_ITEM']))
1253 $basketItem = $basketItemResultList[
'BASKET_ITEM'];
1256 if (isset($basketItemResultList[
'ORDER']))
1259 $order = $basketItemResultList[
'ORDER'];
1263 if ($basketItem ===
null)
1265 $result->addError(
new Sale\ResultError(Main\Localization\
Loc::getMessage(
'SALE_BASKET_COMPATIBLE_BASKET_ITEM_NOT_FOUND'),
'BASKET_ITEM_NOT_FOUND'));
1269 if ($orderId ===
null && isset(
$fields[
'ORDER_ID']) && intval(
$fields[
'ORDER_ID']) > 0)
1271 $orderId = (int)
$fields[
'ORDER_ID'];
1274 if (isset(
$fields[
'ORDER_ID']))
1277 $basketItem->setFields(
$fields);
1279 if ($order ===
null && intval($orderId) > 0)
1281 $registry = Sale\Registry::getInstance(static::getRegistryType());
1282 $orderClassName = $registry->getOrderClassName();
1284 $order = $orderClassName::load($orderId);
1289 if ($order ===
null)
1294 if ($order !==
null && $basket !==
null)
1296 $r = static::appendBasketToOrder($order, $basket->getOrderableItems());
1297 if(!$r->isSuccess())
1299 $result->addErrors($r->getErrors());
1304 $r = $order->save();
1305 if (!$r->isSuccess())
1307 $result->addErrors($r->getErrors());
1337 if (count($shipmentCollection) > 2)
1343 if (!$order = $shipmentCollection->getOrder())
1348 $baseShipment =
null;
1350 $shipmentCollection->setMathActionOnly(
true);
1352 if (count($shipmentCollection) == 1 && $shipmentCollection->isExistsSystemShipment())
1355 if (!$systemShipment = $shipmentCollection->getSystemShipment())
1360 $shipment = $shipmentCollection->createItem();
1361 $r = $shipmentCollection->cloneShipment($systemShipment, $shipment);
1362 if (!$r->isSuccess())
1364 $result->addErrors($r->getErrors());
1371 foreach ($shipmentCollection as $shipment)
1373 if ($shipment->isSystem() || $shipment->isShipped())
1377 foreach ($basket as $basketItem)
1379 $shipmentItemCollection = $shipment->getShipmentItemCollection();
1380 if (!$shipmentItem = $shipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode()))
1382 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
1389 $r = $shipmentItem->setQuantity($basketItem->getQuantity());
1390 if (!$r->isSuccess())
1392 $result->addErrors($r->getErrors());
1400 $shipmentCollection->setMathActionOnly(
false);
1413 public static function convertBasketItemToArray(
Sale\BasketItem $basketItem)
1415 $fields = $basketItem->getFieldValues();
1418 $collection = $basketItem->getCollection();
1421 if (!$basket = $collection->getBasket())
1423 throw new Main\ObjectNotFoundException(
'Entity "Basket" not found');
1427 $fields[
'LID'] = $basket->getSiteId();
1431 if ($order = $basket->getOrder())
1433 $fields[
'LID'] = $order->getField(
'LID');
1439 if (empty(
$fields[
'FUSER_ID']))
1440 $fields[
'FUSER_ID'] = $basket->getFUserId(
true);
1444 if ($propertyCollection = $basketItem->getPropertyCollection())
1446 $fields[
'PROPS'] = $propertyCollection->getPropertyValues();
1454 return array_merge(parent::getWhiteListFields(), array(
'USER_ID'), array_keys(static::getAliasFields()));