File tree Expand file tree Collapse file tree 1 file changed +31
-3
lines changed
app/code/Magento/Sales/Model/Order/Shipment Expand file tree Collapse file tree 1 file changed +31
-3
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments