Magento. Sort products collection by position

user3162709 picture user3162709 · Oct 3, 2015 · Viewed 10.1k times · Source

I have products collection.

$_products = Mage::getModel('catalog/product')->getCollection();

In admin panel in Catalog->Manage Categories->Category products i have position for each product. How i can sort $_products by position ?

Answer

Arun Krish picture Arun Krish · Oct 3, 2015

If you want to sort products by position in category $category_id. you can use the following

//Load the category model

 $category = Mage::getModel('catalog/category')->load($category_id)
             ->getProductCollection()
             ->addAttributeToSort('position', 'ASC');

$products_list = $category->getData();

you will get all products sorted by position in that category $category_id