我正在尝试设置我的Magento商店,按产品顺序(按产品ID)添加到产品目录中进行排序。但是,我一直无法找到一个很好的例子来说明如何设置。它似乎在我的大多数产品类别中都是默认的,但不是全部。Magento - 按产品编号排序产品
我认为在前端的“位置”选项可以做到这一点,但它似乎并不适用于我所有的类别。我正在使用社区版1.6.1。
在此先感谢!
我正在尝试设置我的Magento商店,按产品顺序(按产品ID)添加到产品目录中进行排序。但是,我一直无法找到一个很好的例子来说明如何设置。它似乎在我的大多数产品类别中都是默认的,但不是全部。Magento - 按产品编号排序产品
我认为在前端的“位置”选项可以做到这一点,但它似乎并不适用于我所有的类别。我正在使用社区版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>
感谢您的快速回复。不幸的是,您的代码似乎对产品订单没有任何影响。在某些类别中,它仍然没有按id排序。如果有帮助,通常只有当超过9个或10个产品属于该类别时才会发生。再次感谢! – BWDesign 2012-01-13 21:36:55
@BWDesign你的意思是,只有当一个分类中有超过10种产品可用时才进行排序,对吗? – 2012-01-13 21:55:08
是的。如果有多于9种或10种产品显示在类别中,则排序不正确。另外我注意到,如果按“位置”排序,更改排序方向的确会影响项目。我认为它会根据ID DESC进行排序,然后更改为ID ASC,但显然不是。 – BWDesign 2012-01-13 22:02:43