@@ -284,7 +284,6 @@ protected function setProductLinks(Product $product)
284284 {
285285 $ links = $ this ->getLinkResolver ()->getLinks ();
286286
287- $ currentProductLinks = $ product ->getProductLinks ();
288287 $ product ->setProductLinks ([]);
289288
290289 $ product = $ this ->productLinks ->initializeLinks ($ product , $ links );
@@ -301,14 +300,14 @@ protected function setProductLinks(Product $product)
301300 unset($ linkTypes [$ productLink ->getLinkType ()]);
302301 }
303302
304- $ readonlyRelatedProducts = false ;
305- $ readonlyUpSellProducts = false ;
303+ $ isReadOnlyRelatedItems = $ isReadOnlyUpSellItems = false ;
306304 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+ }
312311 }
313312 if (isset ($ links [$ linkType ]) && !$ readonly ) {
314313 foreach ((array ) $ links [$ linkType ] as $ linkData ) {
@@ -326,8 +325,8 @@ protected function setProductLinks(Product $product)
326325 }
327326 }
328327 }
329- if ($ readonlyRelatedProducts && $ readonlyUpSellProducts && empty ( $ productLinks ) ) {
330- return $ product -> setProductLinks ( $ currentProductLinks ) ;
328+ if ($ isReadOnlyRelatedItems && $ isReadOnlyUpSellItems ) {
329+ $ productLinks = [] ;
331330 }
332331
333332 return $ product ->setProductLinks ($ productLinks );
0 commit comments