Sunday 3 March 2013

marge category product collection magento


<?php
$merged_ids = array();
$categoryIdArray  =  array(2,6,5);

foreach(array_unique($categoryIdArray) as $categoryid)
{
$collection = Mage::getModel('catalog/category')->load($categoryid)->getProductCollection();
if($collection->getAllIds())
{
$temp = $collection->getAllIds();
for($k=0;$k<count($temp);$k++){
$merged_ids[] = $temp[$k];
}
unset($temp);
}
}


$merged_collection = Mage::getResourceModel('catalog/product_collection')
    ->addFieldToFilter('entity_id', $merged_ids)
    ->addAttributeToSelect('*');



?>

No comments: