Skip to content

Commit a0f3325

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 414a576 commit a0f3325

File tree

1 file changed

+9
-10
lines changed
  • app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization

1 file changed

+9
-10
lines changed

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)