Skip to content

Commit e8f2a08

Browse files
committed
ACP2E-2978: Saving product by admin user with different role scope overwrites/deletes existing Related product information in the product
1 parent db958ad commit e8f2a08

File tree

1 file changed

+13
-4
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization

1 file changed

+13
-4
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,13 +278,13 @@ public function initialize(Product $product)
278278
* @param Product $product
279279
* @return Product
280280
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
281-
* @SuppressWarnings(PHPMD.UnusedLocalVariable)
282281
* @since 101.0.0
283282
*/
284283
protected function setProductLinks(Product $product)
285284
{
286285
$links = $this->getLinkResolver()->getLinks();
287286

287+
$currentProductLinks = $product->getProductLinks();
288288
$product->setProductLinks([]);
289289

290290
$product = $this->productLinks->initializeLinks($product, $links);
@@ -300,9 +300,10 @@ protected function setProductLinks(Product $product)
300300
foreach ($productLinks as $productLink) {
301301
unset($linkTypes[$productLink->getLinkType()]);
302302
}
303-
303+
$readonlyRelatedProducts = false;
304+
$readonlyUpSellProducts = false;
304305
foreach ($linkTypes as $linkType => $readonly) {
305-
if (isset($links[$linkType])) {
306+
if (isset($links[$linkType]) && !$readonly) {
306307
foreach ((array) $links[$linkType] as $linkData) {
307308
if (empty($linkData['id'])) {
308309
continue;
@@ -317,8 +318,16 @@ protected function setProductLinks(Product $product)
317318
$productLinks[] = $link;
318319
}
319320
}
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;
320330
}
321-
322331
return $product->setProductLinks($productLinks);
323332
}
324333

0 commit comments

Comments
 (0)