Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento. Sort products collection by position

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 ?

like image 458
user3162709 Avatar asked Oct 03 '15 09:10

user3162709


1 Answers

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

like image 184
Arun Krish Avatar answered Oct 06 '22 13:10

Arun Krish