2010-11-12 141 views
4

是否有可能按A排序,然后B按字母顺序显示这些产品。Magento - 按位置和名称排序?

我有新产品和销售产品进入一个类别,他们显示所有新的首先,然后所有的销售。

但我需要按名称排序。

回答

14

在管理

转到管理类别,选择类别,那么它的产品标签上给每一个位置编号。他们将按照该顺序排序。

编程

你可以通过调用一个产品集合的每个排序addAttributeToSort方法做到这一点。

例如,无论您在模板中看到什么,$_category->getProductCollection()$_product->getCollection()然后您可以在它之后立即添加->addAttributeToSort('position')->addAttributeToSort('name')

addAttributeToSort()也采取方向作为第二个参数,所以你可以有addAttributeToSort('name', 'asc')addAttributeToSort('name', 'desc')

+1

可以在list.phtml文件中添加它,还是需要在我本地复制的core/mage/catalog/block/product/list.php中的list.php文件中?我试过它在list.phtml顶部我添加位置和名称<?php $ _productCollection = $ this-> getLoadedProductCollection()?>所以我得到<?php $ _productCollection = $ this-> getLoadedProductCollection() - > addAttributeToSort('position') - > addAttributeToSort('name')?>或者这是在一个阶段太晚了。 – Knade 2010-11-15 08:42:45

+0

它现在的工作程度Clockworkgeek,但它总是采取任何第二个属性,它似乎是专门应用它们而不是在一起。 – Knade 2010-11-15 10:36:14

0

相反的编码,您可以在管理端的.login这样做是为了你的adminpanel 转到系统--->配置并选择目录从左边的标签。

然后点击右边的Fronend标签。 Goto Product Lisiting排序方式并从下拉列表中选择名称并保存配置。

使排序相对容易。在magento市场有一个扩展。此扩展程序将帮助您按照我们的愿望将产品拖放到位置。我下面提供

http://www.magentocommerce.com/magento-connect/product-sorting-sequence-drag-and-drop.html

3

的最佳方式扩展链接去了解它在不改变任何核心文件是复制位于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()); 
} 
} 

最后,重新索引和刷新你的Magento后端缓存,你准备好了。如果您需要定义一个以上的排序选项复制和粘贴下面的代码之前)其他(

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

针对clockworkgeek,

一个产品可以有多个属性。当您为每个产品分配一个位置时,它与1个属性相关。另外,您需要为每个产品决定一个职位。

这里的问题是产品列表页面上的下拉菜单为您提供了选择多个属性中的一个的机会。例如:

尺码:S,M,L,XL

当你选择一个属性,默认的是那种属性按字母顺序排列这是没有意义的(L,M,S,XL)。相反,我想使用属性选项(s = 1,m = 2,l = 3,xl = 4)的相同位置进行排序。

我的印象是,通过在Magento集合中执行连接和订购,可以做到这一点。你知道如何获得这些价值或做这样的排序吗?