【发布时间】:2012-01-13 17:56:33
【问题描述】:
我正在尝试设置我的 Magento 商店,以便按照产品添加到目录的顺序(按产品 ID)对产品进行排序。但是,我还没有找到一个很好的例子来说明如何设置它。在我的大多数产品类别中似乎默认这样做,但不是全部。
我认为前端的“位置”选项可以做到这一点,但它似乎不适用于我的所有类别。我正在使用社区版 1.6.1。
提前致谢!
【问题讨论】:
我正在尝试设置我的 Magento 商店,以便按照产品添加到目录的顺序(按产品 ID)对产品进行排序。但是,我还没有找到一个很好的例子来说明如何设置它。在我的大多数产品类别中似乎默认这样做,但不是全部。
我认为前端的“位置”选项可以做到这一点,但它似乎不适用于我的所有类别。我正在使用社区版 1.6.1。
提前致谢!
【问题讨论】:
复制: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,所以我没有测试,但结构还可以。如果您遇到任何问题,请确保字段和表名。
【讨论】:
以防万一有人需要: 改变这个:
'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>
【讨论】: