Skip to content

Commit e101e94

Browse files
committed
ACP2E-1650:Create Shipment API
- addressed build failures
1 parent be831ac commit e101e94

File tree

1 file changed

+31
-3
lines changed
  • app/code/Magento/Sales/Model/Order/Shipment

1 file changed

+31
-3
lines changed

app/code/Magento/Sales/Model/Order/Shipment/Item.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -389,11 +389,11 @@ public function setExtensionAttributes(\Magento\Sales\Api\Data\ShipmentItemExten
389389
*/
390390
private function loadChildren(): void
391391
{
392-
if ($this->_orderItem) {
392+
$hasChildrenFlag = null;
393+
if ($this->shouldLoadChildren()) {
393394
$collection = $this->_orderItem->getOrder()->getItemsCollection();
394395
$collection->filterByParent($this->_orderItem->getItemId());
395396

396-
$hasChildrenFlag = false;
397397
if ($collection->count()) {
398398
/** @var \Magento\Sales\Model\Order\Item $childItem */
399399
foreach ($collection as $childItem) {
@@ -403,7 +403,35 @@ private function loadChildren(): void
403403
}
404404
}
405405
}
406-
$this->_orderItem->setData('has_children', $hasChildrenFlag);
407406
}
407+
$this->_orderItem->setData('has_children', $hasChildrenFlag);
408+
}
409+
410+
/**
411+
* Checks if children items are already available in the shipment
412+
*
413+
* @return bool
414+
*/
415+
private function shouldLoadChildren(): bool
416+
{
417+
if (!$this->_orderItem || $this->_orderItem->getParentItemId()) {
418+
return false;
419+
}
420+
if (!$this->_shipment) {
421+
return true;
422+
}
423+
424+
$order = $this->_shipment->getOrder();
425+
/** @var Item $item */
426+
foreach ($this->getShipment()->getAllItems() as $item) {
427+
if (
428+
$this->_orderItem->getItemId() != $item->getOrderItemId() &&
429+
$this->_orderItem->getItemId() == $order->getItemById($item->getOrderItemId())->getParentItemId()
430+
) {
431+
return false;
432+
}
433+
}
434+
435+
return true;
408436
}
409437
}

0 commit comments

Comments
 (0)