Skip to content

Commit

Permalink
magento#20481 REST products update category_ids cannot be removed
Browse files Browse the repository at this point in the history
Code review, updated unit tests
  • Loading branch information
ygyryn committed Feb 7, 2019
1 parent b602067 commit d1b7097
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class ProductRepository implements \Magento\Catalog\Api\ProductRepositoryInterfa
* @param \Magento\Framework\Serialize\Serializer\Json|null $serializer
* @param int $cacheLimit [optional]
* @param ReadExtensions|null $readExtensions
* @param Magento\Catalog\Api\CategoryLinkManagementInterface|null $categoryLinkManagement
* @param Magento\Catalog\Api\CategoryLinkManagementInterface|null $linkManagement
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
Expand Down Expand Up @@ -638,7 +638,7 @@ public function save(ProductInterface $product, $saveOptions = false)
}

$this->saveProduct($product);
if ($assignToCategories === true) {
if ($assignToCategories === true && $product->getCategoryIds()) {
$this->linkManagement->assignProductToCategories(
$product->getSku(),
$product->getCategoryIds()
Expand Down
12 changes: 10 additions & 2 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ protected function setUp()
'setData',
'getStoreId',
'getMediaGalleryEntries',
'getExtensionAttributes'
'getExtensionAttributes',
'getCategoryIds'
]
);

Expand All @@ -220,7 +221,8 @@ protected function setUp()
'validate',
'save',
'getMediaGalleryEntries',
'getExtensionAttributes'
'getExtensionAttributes',
'getCategoryIds'
]
);
$this->initializedProduct->expects($this->any())
Expand Down Expand Up @@ -269,6 +271,12 @@ protected function setUp()
$this->initializedProduct
->method('getExtensionAttributes')
->willReturn($this->productExtension);
$this->product
->method('getCategoryIds')
->willReturn([1, 2, 3, 4]);
$this->initializedProduct
->method('getCategoryIds')
->willReturn([1, 2, 3, 4]);
$storeMock = $this->getMockBuilder(StoreInterface::class)
->disableOriginalConstructor()
->setMethods([])
Expand Down

0 comments on commit d1b7097

Please sign in to comment.