$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 ?
-
have my answer helped you ?Pradeep Sanku– Pradeep Sanku2016年07月11日 05:55:04 +00:00Commented Jul 11, 2016 at 5:55
2 Answers 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);
$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');
}
-
Yes helped,without using product collection possible in report collection ? because product collection and report collection same class extend for addAttributeToSelect() method so.Niraj Patel– Niraj Patel2016年07月11日 06:01:47 +00:00Commented Jul 11, 2016 at 6:01
-
Problem is all products list not order_qty descending order in pageNiraj Patel– Niraj Patel2016年07月11日 06:02:53 +00:00Commented Jul 11, 2016 at 6:02
-
Hello Pradeep are u thereNiraj Patel– Niraj Patel2016年07月11日 06:10:06 +00:00Commented Jul 11, 2016 at 6:10
-
yes say........ ?Pradeep Sanku– Pradeep Sanku2016年07月11日 06:12:52 +00:00Commented 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 soNiraj Patel– Niraj Patel2016年07月11日 06:20:06 +00:00Commented Jul 11, 2016 at 6:20
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 . '\')'
);
}
Explore related questions
See similar questions with these tags.