Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Stop to override other categories in magento
 
mahmoodkk
Jr. Member
 
Total Posts:  1
Joined:  2012-07-17
 

Hi i am working on categories.i am facing problem regarding categories and products.I have more than 2 categories with same products.After creating new category I want to assign those products that exist under category1, (category 1 and category 2 have same products).It will remove products from category2 due to my code.My code is :

$collection = $category->getProductCollection();
$collection->addAttributeToSelect(’*’);

foreach ($collection as $product) {
$categories_pd = $product->getCategoryIds();
$product->setCategoryIds(array($new_cateid , $category1_id));
$product->save();
}

I know that due to setcatgoryIds function its removing other entries.Can anyone know right function or logic to fix this issue.

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top