I want to display products on homepage according to the value of the position. Suppose i have product category Wood having 4 products then product having position value 1 will be shown first then position value 2 will be shown and the product having position value 4 will be shown in last.
1 Answer
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->getAttributeToSelect('*');
$collection->setOrder('position', 'ASC');
foreach($collection as $_product)
{
$_product = Mage::getModel('catalog/product')->load($_product->getId()) ;
//enter what you do here.
}
So what you are doing here is 1 get the entire product collection. 2 Selecting all the attributes (this is not very resource efficient you should only select the required attribtues). thirdly you set the collection order by the position attribute and order it ascending.