Programmatically add Magento products to categories

后端 未结 7 1861
执念已碎
执念已碎 2020-12-24 14:31

I am using Magento 1.4.0.1. I have over 21000 simple products, each entered into a single category. There are hundreds of categories in my site. Some products belong in mult

7条回答
  •  自闭症患者
    2020-12-24 14:48

    I just want to add that you can remove and add with getSingleton category API:

    To Remove product from category:

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

    To Add Product to Category:

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

    This will not overwrite any categories the product is already in

提交回复
热议问题