Magento - 按位置和名称排序?

发布于 2024-10-02 12:37:33 字数 109 浏览 2 评论 0原文

是否可以按 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

终止放荡 2024-10-09 12:37:33

在管理中

转到管理类别,选择类别,然后在其产品选项卡上为每个类别指定一个位置编号。它们将根据该顺序进行排序。

以编程方式

您可以通过为每个订单调用产品集合的 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 either addAttributeToSort('name', 'asc') or addAttributeToSort('name', 'desc').

噩梦成真你也成魔 2024-10-09 12:37:33

在不更改任何核心文件的情况下进行此操作的最佳方法是复制位于以下位置的 Toolbar.php 文件:

/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

然后在以下位置创建一个新的目录路径(如果尚未创建):

/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

现在将第 232 行中的以下内容替换

    if ($this->getCurrentOrder()) {
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }

if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){ //defines the sort option
//sort by position (ascending) and entity_id (descending)
$this->_collection->addAttributeToSort('position','asc')->addAttributeToSort('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

Lastly,在 Magento 后端重新索引并刷新缓存,然后就可以开始了。如果您需要定义多个排序选项,请在 } else { 之前复制并粘贴以下代码

if(($this->getCurrentOrder())=='######'){ //defines the sort option
//sort by ###### (ascending) and ###### (descending)
$this->_collection->addAttributeToSort('######','asc')->addAttributeToSort('######','desc');

The best way to go about it without changing any core files is to copy the Toolbar.php file located:

/app/code/core/Mage/Catalog/Block/Product/List/Toolbar.php

then create a new directory path (if you haven't created one) under:

/app/code/local/Mage/Catalog/Block/Product/List/Toolbar.php

Now replace the following from line 232:

    if ($this->getCurrentOrder()) {
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }

to

if ($this->getCurrentOrder()) {
if(($this->getCurrentOrder())=='position'){ //defines the sort option
//sort by position (ascending) and entity_id (descending)
$this->_collection->addAttributeToSort('position','asc')->addAttributeToSort('entity_id','desc');
} else {
$this->_collection->setOrder($this->getCurrentOrder(),$this->getCurrentDirection());
}
}

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 {

if(($this->getCurrentOrder())=='######'){ //defines the sort option
//sort by ###### (ascending) and ###### (descending)
$this->_collection->addAttributeToSort('######','asc')->addAttributeToSort('######','desc');
冷默言语 2024-10-09 12:37:33

您可以从管理端进行操作,而不是编码。登录到您的管理面板
转到系统--->配置并从左侧选项卡中选择目录

然后单击右侧的前端选项卡。转到产品列表排序方式并从下拉列表中选择名称并保存配置。

使排序相对容易。 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

全部不再 2024-10-09 12:37:33

根据 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文