Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get all product collection order by product name in magento?

Tags:

php

magento

I want to get the product collection order by product name in magento? any idea??

like image 978
smart Avatar asked Mar 09 '11 13:03

smart


2 Answers

Get all products sorted by product name ascending:-

$collection = Mage::getModel('catalog/product')
                         ->getCollection()
                         ->addAttributeToSort('name', 'ASC');

Get all products sorted by product name descending:-

$collection = Mage::getModel('catalog/product')
                         ->getCollection()
                         ->addAttributeToSort('name', 'DESC');

Get limited number of products (for example: 10 products) sorted by product name ascending:-

$collection = Mage::getModel('catalog/product')
                         ->getCollection()
                         ->addAttributeToSort('name', 'ASC')
                         ->setPageSize(10);
like image 51
Mukesh Chapagain Avatar answered Oct 19 '22 02:10

Mukesh Chapagain


This should help:

$collection = Mage::getModel('catalog/category')->load($categoryId)
->getProductCollection()
->addAttributeToSort('name', 'ASC');

see in Magento Wiki

like image 32
Rito Avatar answered Oct 19 '22 02:10

Rito