We are facing issues - https://prnt.sc/mgdybf why we are not able to remove the Deal and Pre Owned category.
Could not save product "26652" with position 0 to category 435
What is this error message about? How to solve this issue?
Regards Rachna
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityWe are facing issues - https://prnt.sc/mgdybf why we are not able to remove the Deal and Pre Owned category.
Could not save product "26652" with position 0 to category 435
What is this error message about? How to solve this issue?
Regards Rachna
Update
Some people have faced this issue already and have a solution. Check these posts
Magento2: Could not save product "330664" with position 0 to category 3567
https://github.com/magento/magento2/issues/8970
The error is from the CategoryLinkRepository File from module-catalog which handles the save functionality. Check your exception log for more details, which tells you exactly why you couldn't save the product. Hope am pointing you to the right direction. Check also deleteByIds method, it can be the potential cause of this issue.
/**
* {@inheritdoc}
*/
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) {
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;
}
magento\vendor\magento\module-catalog\Model\CategoryLinkRepository.php
/**
* {@inheritdoc}
*/
public function save(\Magento\Catalog\Api\Data\CategoryProductLinkInterface $productLink)
{
$category = $this->categoryRepository->get($productLink->getCategoryId());
$product = $this->productRepository->get($productLink->getSku());
$productPositions = $category->getProductsPosition();
$productPositions[$product->getId()] = $productLink->getPosition();
$category->setPostedProducts($productPositions);
try {
$category->save();
} catch (\Exception $e) {
throw new CouldNotSaveException(
__(
'Could not save product "%1" with position %2 to category %3',
$product->getId(),
$productLink->getPosition(),
$category->getId()
),
$e
);
}
return true;
}