@@ -278,13 +278,13 @@ public function initialize(Product $product)
278
278
* @param Product $product
279
279
* @return Product
280
280
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
281
- * @SuppressWarnings(PHPMD.UnusedLocalVariable)
282
281
* @since 101.0.0
283
282
*/
284
283
protected function setProductLinks (Product $ product )
285
284
{
286
285
$ links = $ this ->getLinkResolver ()->getLinks ();
287
286
287
+ $ currentProductLinks = $ product ->getProductLinks ();
288
288
$ product ->setProductLinks ([]);
289
289
290
290
$ product = $ this ->productLinks ->initializeLinks ($ product , $ links );
@@ -300,9 +300,10 @@ protected function setProductLinks(Product $product)
300
300
foreach ($ productLinks as $ productLink ) {
301
301
unset($ linkTypes [$ productLink ->getLinkType ()]);
302
302
}
303
-
303
+ $ readonlyRelatedProducts = false ;
304
+ $ readonlyUpSellProducts = false ;
304
305
foreach ($ linkTypes as $ linkType => $ readonly ) {
305
- if (isset ($ links [$ linkType ])) {
306
+ if (isset ($ links [$ linkType ]) && ! $ readonly ) {
306
307
foreach ((array ) $ links [$ linkType ] as $ linkData ) {
307
308
if (empty ($ linkData ['id ' ])) {
308
309
continue ;
@@ -317,8 +318,16 @@ protected function setProductLinks(Product $product)
317
318
$ productLinks [] = $ link ;
318
319
}
319
320
}
321
+ if ($ linkType === 'related ' && $ readonly ) {
322
+ $ readonlyRelatedProducts = true ;
323
+ }
324
+ if ($ linkType === 'upsell ' && $ readonly ) {
325
+ $ readonlyUpSellProducts = true ;
326
+ }
327
+ }
328
+ if ($ readonlyRelatedProducts && $ readonlyUpSellProducts && empty ($ productLinks )) {
329
+ $ productLinks = $ currentProductLinks ;
320
330
}
321
-
322
331
return $ product ->setProductLinks ($ productLinks );
323
332
}
324
333
0 commit comments