@@ -309,25 +309,27 @@ protected function setProductLinks(Product $product)
309
309
$ isReadOnlyUpSellItems = true ;
310
310
}
311
311
}
312
- if (isset ($ links [$ linkType ]) && !$ readonly ) {
313
- foreach ((array ) $ links [$ linkType ] as $ linkData ) {
314
- if (empty ($ linkData ['id ' ])) {
315
- continue ;
312
+ if ($ isReadOnlyRelatedItems && $ isReadOnlyUpSellItems ) {
313
+ $ productLinks = null ;
314
+ break ;
315
+ } else {
316
+ if (isset ($ links [$ linkType ]) && !$ readonly ) {
317
+ foreach ((array ) $ links [$ linkType ] as $ linkData ) {
318
+ if (empty ($ linkData ['id ' ])) {
319
+ continue ;
320
+ }
321
+
322
+ $ linkProduct = $ this ->productRepository ->getById ($ linkData ['id ' ]);
323
+ $ link = $ this ->productLinkFactory ->create ();
324
+ $ link ->setSku ($ product ->getSku ())
325
+ ->setLinkedProductSku ($ linkProduct ->getSku ())
326
+ ->setLinkType ($ linkType )
327
+ ->setPosition (isset ($ linkData ['position ' ]) ? (int ) $ linkData ['position ' ] : 0 );
328
+ $ productLinks [] = $ link ;
316
329
}
317
-
318
- $ linkProduct = $ this ->productRepository ->getById ($ linkData ['id ' ]);
319
- $ link = $ this ->productLinkFactory ->create ();
320
- $ link ->setSku ($ product ->getSku ())
321
- ->setLinkedProductSku ($ linkProduct ->getSku ())
322
- ->setLinkType ($ linkType )
323
- ->setPosition (isset ($ linkData ['position ' ]) ? (int ) $ linkData ['position ' ] : 0 );
324
- $ productLinks [] = $ link ;
325
330
}
326
331
}
327
332
}
328
- if ($ isReadOnlyRelatedItems && $ isReadOnlyUpSellItems ) {
329
- $ productLinks = [];
330
- }
331
333
332
334
return $ product ->setProductLinks ($ productLinks );
333
335
}
0 commit comments