While unasign the product from multiple categories to single category and trying to save the product, it thorow the error like below
Could not save product "20072" with position 0 to category 7
I am saving the product mannually via admin end
While unasign the product from multiple categories to single category and trying to save the product, it thorow the error like below
Could not save product "20072" with position 0 to category 7
I am saving the product mannually via admin end
It is fixed in Magento latest version.
You can check fixes here.
To fix this issue i created a custom module.
Hope it helps.
public function deleteByIds($categoryId, $sku)
{
$category = $this->categoryRepository->get($categoryId);
$product = $this->productRepository->get($sku);
$productPositions = $category->getProductsPosition();
$productID = $product->getId();
if (!isset($productPositions[$productID])) {
throw new InputException(__('Category does not contain specified product'));
}
$backupPosition = $productPositions[$productID];
unset($productPositions[$productID]);
$category->setPostedProducts($productPositions);
try {
$category->save();
} catch (\Exception $e) {
echo $e->getMessage();
exit;
throw new CouldNotSaveException(
__(
'Could not save product "%product" with position %position to category %category',
[
"product" => $product->getId(),
"position" => $backupPosition,
"category" => $category->getId()
]
),
$e
);
}
return true;
}
the "echo $e->getMessage();
" gives you the exact error.
In my case it was "Duplication of URL key."
So just check what error message you are getting from here....
File: Vendor/magento/module-catalog/Model/CategoryLinkRepository.php