2012-01-13 182 views
4

我正在嘗試設置我的Magento商店,按產品順序(按產品ID)添加到產品目錄中進行排序。但是,我一直無法找到一個很好的例子來說明如何設置。它似乎在我的大多數產品類別中都是默認的,但不是全部。Magento - 按產品編號排序產品

我認爲在前端的「位置」選項可以做到這一點,但它似乎並不適用於我所有的類別。我正在使用社區版1.6.1。

在此先感謝!

回答

3

複製:
app/code/core/Mage/Catalog/Block/Product/List.php

到(創建此時,相應的文件夾):
app/code/local/Mage/Catalog/Block/Product/List.php

查找以下行中list.php的:

$this->_productCollection = $layer->getProductCollection(); 

添加以下行如下:

$this->_productCollection->joinField('category_product', 'catalog/category_product', 'product_id', 'product_id=entity_id', array('store_id'=> Mage::app()->getStore()->getId()), 'left'); 

// Here is the explain 
/* 
* @param string $alias 'category_product' 
* @param string $table 'catalog/category_product' 
* @param string $field 'name' 
* @param string $bind 'PK(product_id)=FK(entity_id)' 
* @param string|array $cond 
* @param string $joinType 'left' 
* 
* default definition 
* joinField($alias, $table, $field, $bind, $cond=null, $joinType='inner') 
* 
*/ 

複製
app/code/core/Mage/Catalog/Model/Config.php


app/code/local/Mage/Catalog/Model/Config.php

查找config.php文件中的以下行:

'position' => Mage::helper('catalog')->__('Position') 

替換爲:

$options = array(
    'position' => Mage::helper('catalog')->__('Position'), 
    'product_id' => Mage::helper('catalog')->__('Product ID') 
); 

PS:我寫這篇文章從家裏,我沒有得到的Magento安裝在我的機器上,所以我沒有測試但結構確定。如果您遇到任何問題,請確定字段和表名。

+0

感謝您的快速回復。不幸的是,您的代碼似乎對產品訂單沒有任何影響。在某些類別中,它仍然沒有按id排序。如果有幫助,通常只有當超過9個或10個產品屬於該類別時纔會發生。再次感謝! – BWDesign 2012-01-13 21:36:55

+0

@BWDesign你的意思是,只有當一個分類中有超過10種產品可用時才進行排序,對嗎? – 2012-01-13 21:55:08

+0

是的。如果有多於9種或10種產品顯示在類別中,則排序不正確。另外我注意到,如果按「位置」排序,更改排序方向的確會影響項目。我認爲它會根據ID DESC進行排序,然後更改爲ID ASC,但顯然不是。 – BWDesign 2012-01-13 22:02:43

1

以防萬一有人需要: 更改此:

'product_id' => Mage::helper('catalog')->__('Product ID') 

這樣:

'entity_id' => Mage::helper('catalog')->__('Product ID') 
1

複製

app/code/core/Mage/Catalog/Model/Config.php 

app/code/local/Mage/Catalog/Model/Config.php 

找到以下行Config.php

$options = array(
    'position' => Mage::helper('catalog')->__('Position') 
); 

替換爲:

$options = array(
//  'position' => Mage::helper('catalog')->__('Position') 
     'entity_id' => Mage::helper('catalog')->__('Last') 
    ); 

然後更改默認的排序方向下降: 開放app/design/frontend/your theme/your layout/layout/catalog.xml 添加一行

<action method="setDefaultDirection"><dir>desc</dir></action> 

在塊

<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml"> 
    <block type="page/html_pager" name="product_list_toolbar_pager"/> 
     <!-- The following code shows how to set your own pager increments --> 
here 

    </block> 
</block>