Magento的。按位置对产品集合进行排序

时间:2015-10-03 09:46:19

标签: php magento magento-1.7 magento-1.9 magento-1.8

我有产品系列。

{{1}}

在目录管理面板中 - >管理类别 - >类别产品我对每个产品都有定位。 我如何按位置对$ _products进行排序?

3 个答案:

答案 0 :(得分:3)

如果您想按类别$ category_id中的位置对产品进行排序。你可以使用以下

//Load the category model

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

$products_list = $category->getData();

您将获得按类别$ category_id

中的位置排序的所有产品

答案 1 :(得分:2)

您需要添加类别,您可以在其中设置产品的位置,作为集合的过滤器

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

答案 2 :(得分:0)

我创建了分隔扩展,它创建了名为'position'的新产品属性。在这个扩展中,我创建了一个监听类别保存事件的观察者。因此,当管理员在我的观察者中保存类别时,我获得每个位置并为每个产品设置我的属性“位置”。最后我可以通过'position'(产品)属性对产品集合进行排序。