Magento: Sorting a product collection

I'm creating a template to display featured products on the home page, and I'd like to control the order of the products.

This is what I'm using at the moment to fetch a product collection based on a category:

    $_productCollection = $this->getLoadedProductCollection();

No specific sorting at all.

When I were going to sort the products, I expected this to work:

    $_productCollection = $this->getLoadedProductCollection()->addAttributeToSort('name', 'ASC');

But there's no difference at all. What am I doing wrong?

Thank you in advance!


use this one I have worked on the same way try it.

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

for descending order:

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

for product with its category:

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

Or you can find more help on magento wiki.

Need Your Help

DataGridView, Get the value of the first column of the selected row

c# datagridview

I'm wondering what would be the most efficient way to get the value of the first column in an DataGridView row.

MySQL Multi-Table Join

mysql join table

I need to modify the following MySQL statement to include information from a third table... but I suck at joins.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.