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
389
389
*/
390
390
private function loadChildren (): void
391
391
{
392
- if ($ this ->_orderItem ) {
392
+ $ hasChildrenFlag = null ;
393
+ if ($ this ->shouldLoadChildren ()) {
393
394
$ collection = $ this ->_orderItem ->getOrder ()->getItemsCollection ();
394
395
$ collection ->filterByParent ($ this ->_orderItem ->getItemId ());
395
396
396
- $ hasChildrenFlag = false ;
397
397
if ($ collection ->count ()) {
398
398
/** @var \Magento\Sales\Model\Order\Item $childItem */
399
399
foreach ($ collection as $ childItem ) {
@@ -403,7 +403,35 @@ private function loadChildren(): void
403
403
}
404
404
}
405
405
}
406
- $ this ->_orderItem ->setData ('has_children ' , $ hasChildrenFlag );
407
406
}
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 ;
408
436
}
409
437
}
You can’t perform that action at this time.
0 commit comments