2
$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 ?

asked Jul 8, 2016 at 4:46
1
  • have my answer helped you ? Commented Jul 11, 2016 at 5:55

2 Answers 2

4
$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');
}
answered Jul 8, 2016 at 6:19
9
  • Yes helped,without using product collection possible in report collection ? because product collection and report collection same class extend for addAttributeToSelect() method so. Commented Jul 11, 2016 at 6:01
  • Problem is all products list not order_qty descending order in page Commented Jul 11, 2016 at 6:02
  • Hello Pradeep are u there Commented Jul 11, 2016 at 6:10
  • yes say........ ? Commented Jul 11, 2016 at 6:12
  • one confusion.without using product collection possible in report collection ? because product collection and report collection same class extend for addAttributeToSelect() method so Commented Jul 11, 2016 at 6:20
0

Could not find any fast solution within reasonable time. So I am accessing the DB almost directly. load($productId, array($attributeCode)) loads all the product information For other solutions I run out of memory on my local machine.

/*
 get product attribute integer value
*/
function getProductAttributeInt($productId, $attributeCode){
 $resource = Mage::getSingleton('core/resource');
 $readConnection = $resource->getConnection('core_read');
 return 
 $readConnection->fetchOne(
 'select value from catalog_product_entity_int where entity_id=' . $productId . '
 and attribute_id = (select attribute_id from eav_attribute where attribute_code = \'' . $attributeCode . '\')'
 );
}
answered Sep 20, 2017 at 6:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.