Magento - 按位置和名称排序?
是否可以按 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在管理中
转到管理类别,选择类别,然后在其产品选项卡上为每个类别指定一个位置编号。它们将根据该顺序进行排序。
以编程方式
您可以通过为每个订单调用产品集合的
addAttributeToSort
方法来执行此操作。例如,无论您在模板中看到
$_category->getProductCollection()
或$_product->getCollection()
,您都可以添加-> ;addAttributeToSort('position')->addAttributeToSort('name')
紧随其后。addAttributeToSort()
还将方向作为第二个参数,因此您可以使用addAttributeToSort('name', 'asc')
或addAttributeToSort('name', '描述')
。In admin
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.
Programmatically
You can do this by calling a product collection's
addAttributeToSort
method for each ordering.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()
also takes a direction as a second parameter so you can have eitheraddAttributeToSort('name', 'asc')
oraddAttributeToSort('name', 'desc')
.在不更改任何核心文件的情况下进行此操作的最佳方法是复制位于以下位置的 Toolbar.php 文件:
然后在以下位置创建一个新的目录路径(如果尚未创建):
现在将第 232 行中的以下内容替换
为
Lastly,在 Magento 后端重新索引并刷新缓存,然后就可以开始了。如果您需要定义多个排序选项,请在 } else { 之前复制并粘贴以下代码
The best way to go about it without changing any core files is to copy the Toolbar.php file located:
then create a new directory path (if you haven't created one) under:
Now replace the following from line 232:
to
Lastly, reindex and refresh cache on your Magento backend and your ready to go. If you need to define more then one sort option copy and paste the code below just before } else {
您可以从管理端进行操作,而不是编码。登录到您的管理面板
转到系统--->配置并从左侧选项卡中选择目录。
然后单击右侧的前端选项卡。转到产品列表排序方式并从下拉列表中选择名称并保存配置。
使排序相对容易。 magento 市场上有一个可用的扩展。此扩展将帮助您将产品拖放到我们希望的位置。我在下面提供了扩展链接
http://www .magentocommerce.com/magento-connect/product-sorting-sequence-drag-and-drop.html
Instead of coding, You can do it from the admin end .Login to your adminpanel
Goto System--->Configuration and choose Catalog from the left tab.
Then click the Fronend tab on the right. Goto Product Lisiting Sort by and choose Name from the dropdown and save the configuration.
To Make the sorting relatively easy. There is an extension available in the magento market. This extension will helps you to drag and drop the products to the position as per our wish. I provided the extension link below
http://www.magentocommerce.com/magento-connect/product-sorting-sequence-drag-and-drop.html
根据 Clockworkgeek 的说法,
一个产品可以有多个属性。当您为每个产品分配一个位置时,它与 1 个属性相关。此外,您还需要为每种产品确定一个位置。
这里的问题是产品列表页面上的下拉菜单为您提供了选择多个属性之一的机会。例如:
尺码:S、M、L、XL
当您选择属性时,默认情况下会按字母顺序对该属性进行排序,这是没有意义的(L、M、S、XL)。相反,我想使用属性选项的相同位置(s=1,m=2,l=3,xl=4)进行排序。
我的印象是,通过在 Magento 集合中执行连接和排序可以做到这一点。您知道如何获取这些值或进行类似排序吗?
In response to clockworkgeek,
A product can have multiple attributes. When you assign each product a single position, it relates to 1 attribute. In addition, you would be required to decide a position for each product.
The problem here is that the dropdown on the product listings page offers you the opportunity to pick one of multiple attributes. For example:
Size: S, M, L, XL
When you choose an attribute, the default is to sort that attribute alphabetical which does not make sense (L, M, S, XL). Instead, I would like to use the same position of the attribute-option (s=1, m=2, l=3, xl=4) for sorting.
I am under the impression that doing this would be possible by performing a join and order by in Magento collections. Do you know how to get those values or do sorting like that?