I would like to programmatically assign a product collection to a category.
This is my product collection for example
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => '345'),
array('finset' => '320')
)
)
->addAttributeToSort('created_at', 'desc');
$_productCollection->getSelect()->group('e.entity_id');
I want these products to be assigned to a category id. Is it possible?
Best Answer
I will add an answer with the help of the above link i posted.