Magento. Sorting products by position

I have a collection of products.

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

In the admin panel in the catalog-> Category Management-> Product Category, I have a position for each product. How can I sort $ _products by position?

+4
source share
3 answers

, new products "position". , . , , "" . , 'position' (product).

0

$category_id.

//Load the category model

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

$products_list = $category->getData();

, $category_id

+3

, ,

$category = Mage::getModel('catalog/category')->load($categoryId);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($category);
$collection->addAttributeToSort('position', 'ASC');
+1

Source: https://habr.com/ru/post/1610083/


All Articles