2010-11-12 142 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集合中執行連接和訂購,可以做到這一點。你知道如何獲得這些價值或做這樣的排序嗎?