开发者

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

开发者 https://www.devze.com 2023-02-15 23:01 出处:网络
I want to get the product collection order by product 开发者_JS百科name in magento? any idea??Get all products sorted by product name ascending:-

I want to get the product collection order by product 开发者_JS百科name in magento? any idea??


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);


This should help:

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

see in Magento Wiki

0

精彩评论

暂无评论...
验证码 换一张
取 消