@@ -284,7 +284,6 @@ protected function setProductLinks(Product $product)
284
284
{
285
285
$ links = $ this ->getLinkResolver ()->getLinks ();
286
286
287
- $ currentProductLinks = $ product ->getProductLinks ();
288
287
$ product ->setProductLinks ([]);
289
288
290
289
$ product = $ this ->productLinks ->initializeLinks ($ product , $ links );
@@ -301,14 +300,14 @@ protected function setProductLinks(Product $product)
301
300
unset($ linkTypes [$ productLink ->getLinkType ()]);
302
301
}
303
302
304
- $ readonlyRelatedProducts = false ;
305
- $ readonlyUpSellProducts = false ;
303
+ $ isReadOnlyRelatedItems = $ isReadOnlyUpSellItems = false ;
306
304
foreach ($ linkTypes as $ linkType => $ readonly ) {
307
- if ($ linkType === 'related ' && $ readonly ) {
308
- $ readonlyRelatedProducts = true ;
309
- }
310
- if ($ linkType === 'upsell ' && $ readonly ) {
311
- $ readonlyUpSellProducts = true ;
305
+ if ($ readonly ) {
306
+ if ($ linkType === 'related ' ) {
307
+ $ isReadOnlyRelatedItems = true ;
308
+ } elseif ($ linkType === 'upsell ' ) {
309
+ $ isReadOnlyUpSellItems = true ;
310
+ }
312
311
}
313
312
if (isset ($ links [$ linkType ]) && !$ readonly ) {
314
313
foreach ((array ) $ links [$ linkType ] as $ linkData ) {
@@ -326,8 +325,8 @@ protected function setProductLinks(Product $product)
326
325
}
327
326
}
328
327
}
329
- if ($ readonlyRelatedProducts && $ readonlyUpSellProducts && empty ( $ productLinks ) ) {
330
- return $ product -> setProductLinks ( $ currentProductLinks ) ;
328
+ if ($ isReadOnlyRelatedItems && $ isReadOnlyUpSellItems ) {
329
+ $ productLinks = [] ;
331
330
}
332
331
333
332
return $ product ->setProductLinks ($ productLinks );
0 commit comments