Magento-按ID分类产品



我正在尝试设置我的Magento商店,以便按照产品添加到目录的顺序(按产品ID)对产品进行排序。然而,我一直找不到一个好的例子来说明如何设置它。在我的大多数产品类别中,它似乎都是默认的,但并不是所有的产品类别。

我原以为前端的"职位"排序选项可以做到这一点,但它似乎不适用于我的所有类别。我使用的是社区版本1.6.1。

提前感谢!

复制:
app/code/core/Mage/Catalog/Block/Product/List.php

to(创建合适的文件夹):
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,所以我没有测试,但结构还可以。如果你遇到任何麻烦,请确保字段和表名。

以防万一有人需要:更改此项:

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

到此:

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

复制

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>

最新更新