41 $this->data = array();
45 public function getEdit($defTails =
false)
49 function searchProductByBarcode(_this)
52 if(event.keyCode == 13)
54 '.$this->jsObjName.
'.checkProductByBarcode(_this.nextElementSibling);
55 event.preventDefault();
59 <div class="adm-s-gray-title" style="padding-right: 2px;">
61 <div class="adm-s-gray-title-btn-container">
63 class="adm-btn adm-btn-green adm-btn-add"
64 onClick="'.$this->systemJsObjName.
'.addProductSearch();"
69 <div class="adm-s-gray-title-btn-container" style="margin-right: 25px;">
70 <span class="adm-bus-order-find-by-barcode" onclick="BX.Sale.Admin.GeneralShipment.findProductByBarcode(this);">'.Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_FIND_BY_BARCODE').
'</span>
72 <div class="adm-s-gray-title-btn-container" style="margin-right: 25px; display: none;">
73 <input type="text" style="width: 150px;" onkeypress="searchProductByBarcode(this);">
74 <span class="adm-btn" onclick="'.$this->jsObjName.
'.checkProductByBarcode(this);">'.
Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_FIND').
'</span>
76 <div class="clb"></div>
80 <div class="adm-s-order-table-ddi">
81 <table class="adm-s-order-table-ddi-table" style="width: 100%;" id="'.$this->idPrefix.
'sale_order_edit_product_table">
84 <td class="adm-s-order-table-context-menu-column">
85 <span class="adm-s-order-table-title-icon"
87 onclick="'.$this->jsObjName.
'.onHeadMenu(this);"
93 foreach($this->visibleColumns as $id => $name)
95 $result .=
"<td style='width: 200px'>".$name.
"</td>";
97 $result .=
"<td>".$name.
"</td>";
104 $result .=
'<div class="adm-list-table-footer" id="b_sale_order_shipment_footer" style="margin-top: -5px; padding-top: 10px;">
105 <span class="adm-selectall-wrap" style="margin-top: 5px; font-weight: bold;">'.Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_GOODS_ALL').
': </span><span class="adm-selectall-wrap" style="margin-top: 5px; font-weight: bold;" id="'.$this->idPrefix.
'_count">0</span>
106 <span class="adm-selectall-wrap" style="margin-top: 5px; font-weight: bold;">'.
Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_GOODS_SELECTED').
': </span><span class="adm-selectall-wrap" style="margin-top: 5px; font-weight: bold;" id="'.$this->idPrefix.
'_selected_count">0</span>
107 <span class="adm-selectall-wrap" style="margin-top: 5px; font-weight: bold;">'.str_replace(array(
'#CURRENT_PAGE#',
'#COUNT_PAGE#'), array(
'1',
'1'),
Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_PAGE')).
'</span>
110 $result .=
'<div class="adm-list-table-footer" id="b_sale_order_shipment_footer">
111 <span class="adm-selectall-wrap">
112 <input type="checkbox" class="adm-checkbox adm-designed-checkbox" name="action_target" value="selected" id="action_target" '.($this->shipment->isShipped() ?
'disabled' :
'').
'>
113 <label for="action_target" class="adm-checkbox adm-designed-checkbox-label"></label>
114 <label title="'.
Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_APPLY').
'" for="action_target" class="adm-checkbox-label">'.
Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_APPLY_FOR_ALL').
'</label>
117 <span class="adm-table-item-edit-wrap adm-table-item-edit-single">
118 <a href="javascript:void(0);" class="adm-table-btn-delete adm-edit-disable" hidefocus="true" title="" id="action_delete_button" onclick="'.$this->jsObjName.
'.groupMoveToSystemBasket(this);"></a>
127 $exceptionFields = array(
'QUANTITY',
'REMAINING_QUANTITY');
128 foreach ($exceptionFields as $field)
130 if (array_key_exists($field, $this->visibleColumns))
131 unset($this->visibleColumns[$field]);
135 <div class="adm-s-order-table-ddi">
136 <table class="adm-s-order-table-ddi-table" style="width: 100%;" id="'.$this->idPrefix.
'_'.$index.
'">
140 foreach ($this->visibleColumns as $id => $name)
143 $result .=
"<td style='width: 200px'>".$name.
"</td>";
145 $result .=
"<td>".$name.
"</td>";
152 $result .= $this->
getViewScript($index, $this->visibleColumns);
163 "QUANTITY" =>
Loc::getMessage(
"SALE_ORDER_BASKET_SETTINGS_COL_QUANTITY"),
167 if (self::$useStoreControl)
169 $columnName = array_merge(
173 "CUR_AMOUNT" =>
Loc::getMessage(
"SALE_ORDER_BASKET_SETTINGS_COL_CUR_AMOUNT"),
174 "REMAINING_QUANTITY" =>
Loc::getMessage(
"SALE_ORDER_BASKET_SETTINGS_COL_REMAINING_QUANTITY")
179 $columnName = array_merge(
182 "BARCODE" =>
Loc::getMessage(
"SALE_ORDER_BASKET_SETTINGS_COL_BARCODE"),
207 public function prepareData(array $inParams = array())
211 $shipmentCollection = $this->shipment->getCollection();
212 $shipmentItemCollection = $this->shipment->getShipmentItemCollection();
213 $result = $this->getProductsInfo($shipmentItemCollection);
215 $result[
'UNSHIPPED_PRODUCTS'] = array();
217 if ($this->shipment->getId() > 0)
220 $systemShipment = $shipmentCollection->getSystemShipment();
221 $systemItemsCollection = $systemShipment->getShipmentItemCollection();
223 $systemCollectionProduct = $this->getProductsInfo($systemItemsCollection);
225 $result[
'UNSHIPPED_PRODUCTS'] = array_diff_key($systemCollectionProduct[
'ITEMS'], $result[
'ITEMS']);
236 public function getProductsInfo($shipmentItemCollection)
239 $shipment = $shipmentItemCollection->getShipment();
240 $systemShipmentItemCollection =
null;
241 $systemShipmentItem =
null;
250 $systemShipment =
$shipment->getCollection()->getSystemShipment();
251 $systemShipmentItemCollection = $systemShipment->getShipmentItemCollection();
256 $catalogProductsIds = array();
259 foreach($shipmentItemCollection as $item)
261 $basketItem = $item->getBasketItem();
263 if ($basketItem && $basketItem->getField(
"MODULE") ==
"catalog")
264 $catalogProductsIds[] = $basketItem->getProductId();
267 if(!empty($catalogProductsIds))
268 $catalogProductsFields =
self::getProductsData($catalogProductsIds, $this->order->getSiteId(), $this->visibleColumns, $this->order->getUserId());
271 foreach($shipmentItemCollection as $item)
275 $basketItem = $item->getBasketItem();
278 $systemShipmentItem =
null;
279 if ($systemShipmentItemCollection)
282 $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketCode($basketItem->getBasketCode());
285 $productId = $basketItem->getProductId();
287 if ($basketItem->getField(
"MODULE") ===
"catalog" && !empty($catalogProductsFields[$productId]))
289 $params = $catalogProductsFields[$productId];
292 if (intval($basketItem->getField(
"MEASURE_CODE")) > 0)
294 $params[
"MEASURE_CODE"] = intval($basketItem->getField(
"MEASURE_CODE"));
296 elseif (!isset($params[
"MEASURE_CODE"]))
298 $params[
"MEASURE_CODE"] = 0;
301 if (!empty($basketItem->getField(
"MEASURE_NAME")))
303 $params[
"MEASURE_TEXT"] = $basketItem->getField(
"MEASURE_NAME");
305 elseif(!isset($params[
"MEASURE_TEXT"]))
307 $params[
"MEASURE_TEXT"] =
"";
310 if ($basketItem->isBundleParent())
312 $params[
"BASE_ELEMENTS_QUANTITY"] = $basketItem->getBundleBaseQuantity();
313 if (!isset($params[
'IS_SET_ITEM']))
314 $params[
'IS_SET_ITEM'] =
'N';
315 if (!isset($params[
'IS_SET_PARENT']))
316 $params[
'IS_SET_PARENT'] =
'Y';
317 if (!isset($params[
'OLD_PARENT_ID']))
318 $params[
'OLD_PARENT_ID'] =
'';
320 $params[
"BASKET_ID"] = $basketItem->getId();
321 $params[
"PRODUCT_PROVIDER_CLASS"] = $basketItem->getProvider();
322 $params[
"NAME"] = $basketItem->getField(
"NAME");
323 $params[
"MODULE"] = $basketItem->getField(
"MODULE");
324 $params[
'TYPE'] = (int)$basketItem->getField(
'TYPE');
325 $params[
'BARCODE_INFO'] = [];
327 $itemStoreCollection = $item->getShipmentItemStoreCollection();
328 if ($itemStoreCollection)
331 foreach ($itemStoreCollection as $barcode)
334 if (!isset($params[
'BARCODE_INFO'][$storeId]))
336 $params[
'BARCODE_INFO'][
$storeId] = [];
339 $params[
'BARCODE_INFO'][
$storeId][] = [
341 'BARCODE' =>
$barcode->getBarcode(),
342 'MARKING_CODE' =>
$barcode->getMarkingCode(),
343 'QUANTITY' =>
$barcode->getQuantity(),
349 $params[
'ORDER_DELIVERY_BASKET_ID'] = $item->getId();
351 $systemItemQuantity = ($systemShipmentItem) ? $systemShipmentItem->getQuantity() : 0;
352 $params[
"QUANTITY"] = floatval($item->getQuantity() + $systemItemQuantity);
353 $params[
"AMOUNT"] = floatval($item->getQuantity());
354 $params[
"PRICE"] = $basketItem->getPrice();
355 $params[
"CURRENCY"] = $basketItem->getCurrency();
356 $params[
"PROPS"] = array();
359 foreach($basketItem->getPropertyCollection() as $property)
361 $params[
"PROPS"][] = array(
362 "VALUE" => $property->getField(
"VALUE"),
363 "NAME" => $property->getField(
"NAME"),
364 "CODE" => $property->getField(
"CODE"),
365 "SORT" => $property->getField(
"SORT")
369 if(\
Bitrix\Main\Loader::includeModule(
"catalog"))
371 $productInfo = \CCatalogSku::GetProductInfo($productId);
374 $params[
"OFFERS_IBLOCK_ID"] = $productInfo[
"OFFER_IBLOCK_ID"];
375 $params[
"IBLOCK_ID"] = $productInfo[
"IBLOCK_ID"];
376 $params[
"PRODUCT_ID"] = $productInfo[
"ID"];
380 $params[
"PARENT_BASKET_ID"] = $basketItem->getParentBasketItemId() ?? 0;
383 if ($basketItem->getBasketCode() == intval($basketItem->getBasketCode()) && !$basketItem->isBundleParent() && !empty($params[
'SET_ITEMS']))
385 unset($params[
'SET_ITEMS'], $params[
'OLD_PARENT_ID']);
386 $params[
'IS_SET_PARENT'] =
'N';
389 $params[
'IS_SUPPORTED_MARKING_CODE'] = $basketItem->isSupportedMarkingCode() ?
'Y' :
'N';
393 $systemShipmentItem =
null;
394 if ($systemShipmentItemCollection)
397 $systemShipmentItem = $systemShipmentItemCollection->getItemByBasketId($item->getBasketId());
400 $systemItemQuantity = ($systemShipmentItem) ? $systemShipmentItem->getQuantity() : 0;
402 'NAME' =>
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_WRONG_BASKET_ITEM"),
403 'QUANTITY' => floatval($item->getQuantity() + $systemItemQuantity),
404 'AMOUNT' => floatval($item->getQuantity()),
405 'BASKET_ID' => $item->getBasketId(),
409 $items[$params[
'BASKET_ID']] = $params;
412 $bundleChild = array();
413 foreach ($items as $basketId => $item)
415 $parentBasketId = $item[
'PARENT_BASKET_ID'];
416 if ($parentBasketId > 0)
418 $item[
'IS_SET_ITEM'] =
'Y';
419 $item[
'OLD_PARENT_ID'] = $items[$parentBasketId][
'OLD_PARENT_ID'];
420 $bundleChild[$parentBasketId][] = $item;
421 unset($items[$basketId]);
425 foreach ($items as $basketId => $item)
427 if (isset($bundleChild[$basketId]))
428 $items[$basketId][
'SET_ITEMS'] = $bundleChild[$basketId];
431 $result[
'ITEMS'] = $items;
441 public function modifyFromRequest(
$data, $request)
444 foreach (
$data[
'ITEMS'] as $code => $item)
446 $basketCode = $item[
'BASKET_ID'];
448 if (!isset($request[$basketCode]))
450 $data[
'UNSHIPPED_PRODUCTS'][$code] =
$data[
'ITEMS'][$code];
451 unset(
$data[
'ITEMS'][$code]);
456 foreach (
$data[
'UNSHIPPED_PRODUCTS'] as $code => $item)
458 $basketCode = $item[
'BASKET_ID'];
460 if (isset($request[$basketCode]))
462 $data[
'ITEMS'][$code] =
$data[
'UNSHIPPED_PRODUCTS'][$code];
463 unset(
$data[
'UNSHIPPED_PRODUCTS'][$code]);
470 foreach ($request as $basketCode => $product)
472 $basket = $this->order->getBasket();
474 $basketItem = $basket->getItemById($product[
'BASKET_ID']);
475 if ($basketItem && $basketItem->isBundleChild())
477 $parentBasketItem = $basketItem->getParentBasketItem();
478 foreach (
$data[
'ITEMS'][$parentBasketItem->getId()][
'SET_ITEMS'] as $id => $setItem)
480 if ($setItem[
'PRODUCT_ID'] == $product[
'PRODUCT_ID'])
482 $item = &
$data[
'ITEMS'][$parentBasketItem->getId()][
'SET_ITEMS'][$id];
489 $item = &
$data[
'ITEMS'][$product[
'BASKET_ID']];
491 $item[
'AMOUNT'] = $product[
'AMOUNT'];
492 $item[
'QUANTITY'] = $product[
'QUANTITY'];
493 if ($product[
'BARCODE_INFO'])
495 foreach ($product[
'BARCODE_INFO'] as $id => $info)
498 if (!isset($item[
'BARCODE_INFO'][$storeId]))
500 $item[
'BARCODE_INFO'][
$storeId] = array();
501 if ($basketItem->isBundleParent())
503 $item[
'BARCODE_INFO'][
$storeId][0] = array();
504 $item[
'BARCODE_INFO'][
$storeId][0][
'QUANTITY'] = $info[
'QUANTITY'];
506 if ($info[
'BARCODE'])
508 foreach ($info[
'BARCODE'] as $barcode)
510 $item[
'BARCODE_INFO'][
$storeId][] = array(
511 'ID' => (
int)$barcode[
'ID'],
512 'BARCODE' => (
string)$barcode[
'VALUE'],
513 'MARKING_CODE' => (
string)$barcode[
'MARKING_CODE'],
514 'QUANTITY' => ($basketItem->isbarcodeMulti()) ? 1 : $info[
'QUANTITY']
521 foreach ($item[
'BARCODE_INFO'][$storeId] as &$barcodeInfo)
523 if ($info[
'BARCODE'])
525 $barcode = array_shift($info[
'BARCODE']);
526 $barcodeInfo[
'ID'] = (int)$barcode[
'ID'];
527 $barcodeInfo[
'BARCODE'] = (string)$barcode[
'VALUE'];
528 $barcodeInfo[
'MARKING_CODE'] = (string)$barcode[
'MARKING_CODE'];
530 $barcodeInfo[
'QUANTITY'] = ($basketItem->isbarcodeMulti()) ? 1 : $info[
'QUANTITY'];
545 if(!static::$jsInited)
547 \Bitrix\Main\Page\Asset::getInstance()->addJs(
"/bitrix/js/sale/admin/order_basket.js");
548 \Bitrix\Main\Page\Asset::getInstance()->addJs(
"/bitrix/js/sale/admin/order_shipment_basket.js");
549 \Bitrix\Main\UI\Extension::load(
'sale.admin_order');
550 static::$jsInited =
true;
552 $data = $this->prepareData();
554 if (!empty($recoveryData))
556 $data = $this->modifyFromRequest(
$data, $recoveryData[
'1'][
'PRODUCT']);
559 $keys = array_merge(array_keys(
$data[
"ITEMS"]), array_keys(
$data[
"UNSHIPPED_PRODUCTS"]));
562 <script type="text/javascript">
564 SALE_ORDER_BASKET_ROW_SETTINGS: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_ROW_SETTINGS")).
'",
565 SALE_ORDER_BASKET_PROD_MENU_ADD: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_PROD_MENU_ADD")).
'",
566 SALE_ORDER_BASKET_PROD_MENU_DELETE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_PROD_MENU_DELETE")).
'",
567 SALE_ORDER_BASKET_TURN: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_TURN")).
'",
568 SALE_ORDER_BASKET_EXPAND: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_EXPAND")).
'",
569 SALE_ORDER_BASKET_NO_PICTURE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_BASKET_NO_PICTURE")).
'",
570 SALE_ORDER_SHIPMENT_BASKET_SELECTED_PRODUCTS_DEL: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_SELECTED_PRODUCTS_DEL")).
'",
571 SALE_ORDER_SHIPMENT_BASKET_ALL_PRODUCTS_DEL: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_ALL_PRODUCTS_DEL")).
'",
572 SALE_ORDER_SHIPMENT_BASKET_ADD_NEW_STORE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_ADD_NEW_STORE")).
'",
573 SALE_ORDER_SHIPMENT_BASKET_BARCODE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE")).
'",
574 SALE_ORDER_SHIPMENT_BASKET_CLOSE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_CLOSE")).
'",
575 SALE_ORDER_SHIPMENT_BASKET_ADD: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_ADD")).
'",
576 SALE_ORDER_SHIPMENT_BASKET_NO_PRODUCTS: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_NO_PRODUCTS")).
'",
577 SALE_ORDER_SHIPMENT_BASKET_BARCODE_ALREADY_USED: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_ALREADY_USED")).
'",
578 SALE_ORDER_SHIPMENT_BASKET_BARCODE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE")).
'",
579 SALE_ORDER_SHIPMENT_BASKET_BARCODE_CLOSE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_CLOSE")).
'",
580 SALE_ORDER_SHIPMENT_BASKET_BARCODE_ENTER: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_ENTER")).
'",
581 SALE_ORDER_SHIPMENT_BASKET_ERROR_ALREADY_SHIPPED: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_ERROR_ALREADY_SHIPPED")).
'",
582 SALE_ORDER_SHIPMENT_BASKET_ERROR_NOT_FOUND: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_ERROR_NOT_FOUND")).
'",
583 SALE_ORDER_SHIPMENT_BASKET_BARCODE_EMPTY: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_EMPTY")).
'",
587 '.$this->jsObjName.
' = new BX.Sale.Admin.ShipmentBasketEdit({
588 tableId: "'.$this->idPrefix.
'sale_order_edit_product_table",
589 productsOrder: '.\CUtil::PhpToJSObject($keys).
',
590 idPrefix: "'.$this->idPrefix.
'",
591 products: '.\CUtil::PhpToJSObject(
$data[
"ITEMS"]).
',
592 orderId: '.((int)$this->order->getId()).
',
593 visibleColumns: '.\CUtil::PhpToJSObject($this->visibleColumns).
',
594 objName: "'.$this->jsObjName.
'",
595 isShipped: "'.$this->shipment->isShipped().
'",
597 PRICE_DELIVERY_DISCOUNT: {
598 id: "'.$this->idPrefix.
'sale_order_edit_basket_price_delivery_discount",
599 value: "'.roundEx(floatval(0), SALE_VALUE_PRECISION).
'",
603 dataForRecovery: '.\CUtil::PhpToJSObject($recoveryData).
',
604 useStoreControl: "'.self::$useStoreControl.
'"
607 '.$this->systemJsObjName.
' = new BX.Sale.Admin.SystemShipmentBasketEdit({
608 tableId: "unshipped",
609 productsOrder: '.\CUtil::PhpToJSObject($keys).
',
611 products: '.\CUtil::PhpToJSObject(
$data[
"UNSHIPPED_PRODUCTS"]).
',
612 visibleColumns: '.\CUtil::PhpToJSObject(self::getDefaultUnShippedVisibleColumns()).
',
613 objName: "'.$this->systemJsObjName.
'"
616 '.$this->jsObjName.
'.link = '.$this->systemJsObjName.
';
617 '.$this->systemJsObjName.
'.link = '.$this->jsObjName.
';
620 $result .= $this->settingsDialog->getScripts();
621 $result .=
'</script>';
628 \Bitrix\Main\Page\Asset::getInstance()->addJs(
"/bitrix/js/sale/admin/order_shipment_basket.js");
629 \Bitrix\Main\UI\Extension::load(
'sale.admin_order');
631 $data = $this->prepareData();
635 SALE_ORDER_SHIPMENT_VIEW_BASKET_NO_PRODUCTS: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_VIEW_BASKET_NO_PRODUCTS")).
'",
636 SALE_ORDER_SHIPMENT_BASKET_BARCODE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE")).
'",
637 SALE_ORDER_SHIPMENT_BASKET_BARCODE_CLOSE: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_CLOSE")).
'",
638 SALE_ORDER_SHIPMENT_BASKET_BARCODE_EMPTY: "'.\CUtil::JSEscape(
Loc::getMessage(
"SALE_ORDER_SHIPMENT_BASKET_BARCODE_EMPTY")).
'",
643 var viewBasket_'.$index.
' = new BX.Sale.Admin.ShipmentBasket({
644 idPrefix: "'.$this->idPrefix.
'",
645 productsOrder: '.\CUtil::PhpToJSObject(array_keys(
$data[
"ITEMS"])).
',
646 tableId: "'.$this->idPrefix.
'_'.$index.
'",
647 products: '.\CUtil::PhpToJSObject(
$data[
"ITEMS"]).
',
649 useStoreControl: "'.self::$useStoreControl.
'"
659 $shippingItems = array();
660 $idsFromForm = array();
661 $basket =
$order->getBasket();
662 $shipmentItemCollection =
$shipment->getShipmentItemCollection();
663 if (is_null(self::$useStoreControl))
666 if(is_array($shipmentBasket))
669 foreach ($shipmentBasket as $items)
671 $items[
'QUANTITY'] = floatval(str_replace(
',',
'.', $items[
'QUANTITY'] ?? 0));
672 $items[
'AMOUNT'] = floatval(str_replace(
',',
'.', $items[
'AMOUNT']));
673 if (isset($items[
'BASKET_ID']) && $items[
'BASKET_ID'] > 0)
675 if (!$basketItem = $basket->getItemById($items[
'BASKET_ID']))
679 'SALE_ORDER_SHIPMENT_BASKET_BASKET_ITEM_NOT_FOUND',
681 '#BASKET_ITEM_ID#' => $items[
'BASKET_ID'],
684 'PROVIDER_UNRESERVED_SHIPMENT_ITEM_WRONG_BASKET_ITEM')
689 $basketCode = $basketItem->getBasketCode();
693 $basketCode = $items[
'BASKET_CODE'];
694 if(!$basketItem = $basket->getItemByBasketCode($basketCode))
698 'SALE_ORDER_SHIPMENT_BASKET_BASKET_ITEM_NOT_FOUND',
700 '#BASKET_ITEM_ID#' => $items[
'BASKET_ID'],
703 'PROVIDER_UNRESERVED_SHIPMENT_ITEM_WRONG_BASKET_ITEM')
710 'BASKET_CODE' => $basketCode,
711 'AMOUNT' => $items[
'AMOUNT'],
712 'ORDER_DELIVERY_BASKET_ID' => $items[
'ORDER_DELIVERY_BASKET_ID'] ??
null,
714 $idsFromForm[$basketCode] = array();
716 if (!empty($items[
'BARCODE_INFO']) && (self::$useStoreControl || $basketItem->isSupportedMarkingCode()))
718 foreach ($items[
'BARCODE_INFO'] as $item)
720 if ($basketItem->isBundleParent())
722 $shippingItems[] = $tmp;
726 $tmp[
'BARCODE'] = array(
727 'ORDER_DELIVERY_BASKET_ID' => $items[
'ORDER_DELIVERY_BASKET_ID'],
728 'STORE_ID' => (
int)$item[
'STORE_ID'],
729 'QUANTITY' => ($basketItem->isBarcodeMulti() || $basketItem->isSupportedMarkingCode()) ? 1 : $item[
'QUANTITY']
733 if (!empty($item[
'BARCODE']) && is_array($item[
'BARCODE']))
735 foreach ($item[
'BARCODE'] as $barcode)
737 if(self::$useStoreControl && ($barcodeCount >= $items[
'QUANTITY']))
742 $barcode[
'ID'] = (int)$barcode[
'ID'];
743 $idsFromForm[$basketCode][
'BARCODE_IDS'][
$barcode[
'ID']] =
true;
745 if ($barcode[
'ID'] > 0)
746 $tmp[
'BARCODE'][
'ID'] =
$barcode[
'ID'];
748 unset($tmp[
'BARCODE'][
'ID']);
750 $tmp[
'BARCODE'][
'BARCODE'] =
$barcode[
'VALUE'];
751 $tmp[
'BARCODE'][
'MARKING_CODE'] =
$barcode[
'MARKING_CODE'];
752 $shippingItems[] = $tmp;
756 elseif (!$basketItem->isBarcodeMulti() && !$basketItem->isSupportedMarkingCode())
758 $shippingItems[] = $tmp;
762 if ($basketItem->isBarcodeMulti() || $basketItem->isSupportedMarkingCode())
764 while ($barcodeCount < $item[
'QUANTITY'])
766 unset($tmp[
'BARCODE'][
'ID']);
767 $tmp[
'BARCODE'][
'BARCODE'] =
'';
768 $tmp[
'BARCODE'][
'MARKING_CODE'] =
'';
769 $shippingItems[] = $tmp;
777 $shippingItems[] = $tmp;
785 foreach ($shipmentItemCollection as $shipmentItem)
787 if (!array_key_exists($shipmentItem->getBasketCode(), $idsFromForm))
790 $r = $shipmentItem->delete();
791 if (!$r->isSuccess())
792 $result->addErrors($r->getErrors());
795 $shipmentItemStoreCollection = $shipmentItem->getShipmentItemStoreCollection();
796 if ($shipmentItemStoreCollection)
799 foreach ($shipmentItemStoreCollection as $shipmentItemStore)
801 $shipmentItemId = $shipmentItemStore->getId();
802 if (!isset($idsFromForm[$shipmentItem->getBasketCode()][
'BARCODE_IDS'][$shipmentItemId]))
804 $delResult = $shipmentItemStore->delete();
805 if (!$delResult->isSuccess())
806 $result->addErrors($delResult->getErrors());
812 $isStartField = $shipmentItemCollection->isStartField();
815 foreach ($shippingItems as $shippingItem)
817 if ((
int)$shippingItem[
'ORDER_DELIVERY_BASKET_ID'] <= 0)
819 $basketCode = $shippingItem[
'BASKET_CODE'];
821 $basketItem =
$order->getBasket()->getItemByBasketCode($basketCode);
824 $shipmentItem = $shipmentItemCollection->createItem($basketItem);
825 if ($shipmentItem ===
null)
834 unset($shippingItem[
'BARCODE'][
'ORDER_DELIVERY_BASKET_ID']);
838 $shipmentItem = $shipmentItemCollection->getItemById($shippingItem[
'ORDER_DELIVERY_BASKET_ID']);
839 $basketItem = $shipmentItem->getBasketItem();
842 if ($shippingItem[
'AMOUNT'] <= 0)
846 Loc::getMessage(
'SALE_ORDER_SHIPMENT_BASKET_ERROR_QUANTITY', array(
'#BASKET_ITEM#' => $basketItem->getField(
'NAME'))),
847 'BASKET_ITEM_'.$basketItem->getBasketCode()
853 if ($shipmentItem->getQuantity() < $shippingItem[
'AMOUNT'])
855 $order->setMathActionOnly(
true);
856 $setFieldResult = $shipmentItem->setField(
'QUANTITY', $shippingItem[
'AMOUNT']);
857 $order->setMathActionOnly(
false);
859 if (!$setFieldResult->isSuccess())
860 $result->addErrors($setFieldResult->getErrors());
863 if (!empty($shippingItem[
'BARCODE']) && (self::$useStoreControl || $basketItem->isSupportedMarkingCode()))
865 $barcode = $shippingItem[
'BARCODE'];
868 $shipmentItemStoreCollection = $shipmentItem->getShipmentItemStoreCollection();
869 if ($shipmentItemStoreCollection)
871 if (!$basketItem->isBarcodeMulti() && !$basketItem->isSupportedMarkingCode())
874 $r = $shipmentItemStoreCollection->setBarcodeQuantityFromArray($shipmentBasket[$basketItem->getId()]);
877 $result->addErrors($r->getErrors());
881 if (isset($barcode[
'ID']) && intval($barcode[
'ID']) > 0)
884 if ($shipmentItemStore = $shipmentItemStoreCollection->getItemById($barcode[
'ID']))
886 unset($barcode[
'ID']);
887 $setFieldResult = $shipmentItemStore->setFields($barcode);
889 if (!$setFieldResult->isSuccess())
890 $result->addErrors($setFieldResult->getErrors());
895 $shipmentItemStore = $shipmentItemStoreCollection->createItem($basketItem);
896 $setFieldResult = $shipmentItemStore->setFields($barcode);
897 if (!$setFieldResult->isSuccess())
898 $result->addErrors($setFieldResult->getErrors());
903 $setFieldResult = $shipmentItem->setField(
'QUANTITY', $shippingItem[
'AMOUNT']);
904 if (!$setFieldResult->isSuccess())
905 $result->addErrors($setFieldResult->getErrors());
910 $hasMeaningfulFields = $shipmentItemCollection->hasMeaningfulField();
913 $r = $shipmentItemCollection->doFinalAction($hasMeaningfulFields);
914 if (!$r->isSuccess())
916 $result->addErrors($r->getErrors());