我有产品集合。
$_products = Mage::getModel('catalog/product')->getCollection();
在管理面板中的目录->管理分类->分类产品中,我有每个产品的位置。 我如何按位置对 $_products 进行排序?
$_products = Mage::getModel('catalog/product')->getCollection();
在管理面板中的目录->管理分类->分类产品中,我有每个产品的位置。 我如何按位置对 $_products 进行排序?
//Load the category model
$category = Mage::getModel('catalog/category')->load($category_id)
->getProductCollection()
->addAttributeToSort('position', 'ASC');
$products_list = $category->getData();
$category = Mage::getModel('catalog/category')->load($categoryId);
$collection = Mage::getResourceModel('catalog/product_collection');
$collection->addCategoryFilter($category);
$collection->addAttributeToSort('position', 'ASC');
我创建了一个独立的扩展,它创建了一个名为“position”的新产品属性。在这个扩展中,我创建了一个观察者来监听类别保存事件。因此,当管理员保存类别时,在我的观察者中,我获取每个位置并为每个产品设置我的属性“position”。最后,我可以通过“position”(产品)属性对产品集合进行排序。