Magento 1.9 – Get All Product Attributes from Report Collection Without Load

magento-1.9product-attributeproduct-collection

$store = Mage::app()->getStore();
$products = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter("status", Mage_Catalog_Model_Product_Status::STATUS_ENABLED)     
                 ->addPriceData() 
                ->addOrderedQty()
                ->setOrder("ordered_qty", "desc")
                ->setStore($store)
                ->addStoreFilter($store);

I used this product collection but when I use foreach for this collection I can not fetch all product attributes like(small_image).I know one solution in foreach $product=Mage::getModel('catalog/product')->load($_product->getId()); But I do not want to use load in foreach loop. Any alternative soltution ?

Best Answer

$store = Mage::app()->getStore();
$products = Mage::getResourceModel('reports/product_collection')
                ->addAttributeToSelect('*')
                ->addAttributeToFilter("status", Mage_Catalog_Model_Product_Status::STATUS_ENABLED)     
                ->addPriceData() 
                ->addOrderedQty()
                ->setOrder("ordered_qty", "desc")
                ->setStore($store)
                ->addStoreFilter($store);

$productIds = $products->getColumnValues('entity_id');

$productsCollection = Mage::getResourceModel('catalog/product_collection')
                        ->addAttributeToSelect(array('name','description','price','small_image')) // add whatever product attributes you want
                        ->addAttributeToFilter('entity_id',array('in' => $productIds));

foreach($productsCollection as $product){
    echo $product->getName();
    echo $product->getDescription();
    echo $product->getPrice();
    echo Mage::helper('catalog/image')->init($product,'small_image');
}
Related Topic