Skip to content

Commit b602067

Browse files
committed
#20481 REST products update category_ids cannot be removed
Code review
1 parent 9dc3a19 commit b602067

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
165165
/**
166166
* @var CategoryLinkManagementInterface
167167
*/
168-
private $categoryLinkManagement;
169-
170-
/**
171-
* @var AssignProductToCategories
172-
*/
173-
private $assignProductToCategories = false;
168+
private $linkManagement;
174169

175170
/**
176171
* ProductRepository constructor.
@@ -227,7 +222,7 @@ public function __construct(
227222
\Magento\Framework\Serialize\Serializer\Json $serializer = null,
228223
$cacheLimit = 1000,
229224
ReadExtensions $readExtensions = null,
230-
CategoryLinkManagementInterface $categoryLinkManagement = null
225+
CategoryLinkManagementInterface $linkManagement = null
231226
) {
232227
$this->productFactory = $productFactory;
233228
$this->collectionFactory = $collectionFactory;
@@ -252,7 +247,7 @@ public function __construct(
252247
$this->cacheLimit = (int)$cacheLimit;
253248
$this->readExtensions = $readExtensions ?: \Magento\Framework\App\ObjectManager::getInstance()
254249
->get(ReadExtensions::class);
255-
$this->categoryLinkManagement = $categoryLinkManagement ?:\Magento\Framework\App\ObjectManager::getInstance()
250+
$this->linkManagement = $linkManagement ?:\Magento\Framework\App\ObjectManager::getInstance()
256251
->get(CategoryLinkManagementInterface::class);
257252
}
258253

@@ -587,6 +582,7 @@ protected function processMediaGallery(ProductInterface $product, $mediaGalleryE
587582
*/
588583
public function save(ProductInterface $product, $saveOptions = false)
589584
{
585+
$assignToCategories = false;
590586
$tierPrices = $product->getData('tier_price');
591587

592588
try {
@@ -604,7 +600,7 @@ public function save(ProductInterface $product, $saveOptions = false)
604600
$extensionAttributes = $product->getExtensionAttributes();
605601
if (empty($extensionAttributes->__toArray())) {
606602
$product->setExtensionAttributes($existingProduct->getExtensionAttributes());
607-
$this->assignProductToCategories = true;
603+
$assignToCategories = true;
608604
}
609605
} catch (NoSuchEntityException $e) {
610606
$existingProduct = null;
@@ -642,8 +638,8 @@ public function save(ProductInterface $product, $saveOptions = false)
642638
}
643639

644640
$this->saveProduct($product);
645-
if ($this->assignProductToCategories === true) {
646-
$this->categoryLinkManagement->assignProductToCategories(
641+
if ($assignToCategories === true) {
642+
$this->linkManagement->assignProductToCategories(
647643
$product->getSku(),
648644
$product->getCategoryIds()
649645
);

0 commit comments

Comments
 (0)