Lee
Lee

Reputation: 1495

Magento remove product from category programmatically

I have found the following piece of code to remove a product from a category:

Mage::getSingleton('catalog/category_api')->removeProduct($category->getId(),$p‌​roduct->getId());

However I'm not sure how to use it! The product I wish to remove has id 13409 and the category id is 7

How do I get the above to work? I've tried the following but it doesn't work:

Mage::getSingleton('catalog/category_api')->removeProduct($category->7,$p‌​roduct->13409);

Upvotes: 1

Views: 3799

Answers (1)

Manashvi Birla
Manashvi Birla

Reputation: 2843

To programatically remove a product from category, try this :

Mage::getSingleton('catalog/category_api')->removeProduct('7','13409');

You just need to pass the category_id and the product_id not the collection

Upvotes: 5

Related Questions