问题描述
是否可以按字母A的顺序对位置进行排序,然后按B排序?
Is it possible to sort by A the position and then B these products alphabetically shown.
我将新产品和特卖产品归为一类,它们先显示所有新产品,然后再显示所有特卖产品.
I have new products and sale products coming into a category and they show all the new ones first then all the sale ones.
但是我需要按名称对其进行排序.
But I need to sort this by name.
推荐答案
在管理员中
转到管理类别,选择类别,然后在其产品"标签上为每个人指定一个职位编号.它们将按照该顺序排序.
Go to Manage Categories, select the category, then on it's products tab give each one a position number. They will be sorted according to that order.
以编程方式
您可以通过为每个订单调用产品集合的addAttributeToSort
方法来实现此目的.
You can do this by calling a product collection's addAttributeToSort
method for each ordering.
例如,无论您在模板中的哪个位置看到$_category->getProductCollection()
或$_product->getCollection()
,您都可以在其后立即添加->addAttributeToSort('position')->addAttributeToSort('name')
.
For example, wherever you see in a template, $_category->getProductCollection()
or $_product->getCollection()
you can then add ->addAttributeToSort('position')->addAttributeToSort('name')
immediately after it.
addAttributeToSort()
还将方向作为第二个参数,因此可以使用addAttributeToSort('name', 'asc')
或addAttributeToSort('name', 'desc')
.
addAttributeToSort()
also takes a direction as a second parameter so you can have either addAttributeToSort('name', 'asc')
or addAttributeToSort('name', 'desc')
.
这篇关于Magento-按位置和名称排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!