Sorting Magento-按ID对产品进行排序
我正在尝试设置我的Magento商店,以便按照产品添加到目录的顺序(按产品ID)对产品进行排序。然而,我还没有找到一个很好的例子来说明如何设置它。在我的大多数产品类别中,默认情况下似乎都是这样,但并非所有类别都是这样 我原以为前端的“位置排序”选项可以做到这一点,但它似乎并不适用于我的所有类别。我使用的是社区版1.6.1 提前谢谢 复制:Sorting Magento-按ID对产品进行排序,sorting,magento,product,Sorting,Magento,Product,我正在尝试设置我的Magento商店,以便按照产品添加到目录的顺序(按产品ID)对产品进行排序。然而,我还没有找到一个很好的例子来说明如何设置它。在我的大多数产品类别中,默认情况下似乎都是这样,但并非所有类别都是这样 我原以为前端的“位置排序”选项可以做到这一点,但它似乎并不适用于我的所有类别。我使用的是社区版1.6.1 提前谢谢 复制: app/code/core/Mage/Catalog/Block/Product/List.php 要(创建适当的文件夹): app/code/local/M
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')
);
$options = array(
// 'position' => Mage::helper('catalog')->__('Position')
'entity_id' => Mage::helper('catalog')->__('Last')
);
PS:我在家写这篇文章,我的机器上还没有安装Magento,所以我没有测试,但结构还可以。如果遇到任何toruble,请确保字段和表名。以防有人需要: 更改此项:
'product_id' => Mage::helper('catalog')->__('Product ID')
为此:
'entity_id' => Mage::helper('catalog')->__('Product ID')
抄袭
到
在Config.php
中找到以下行:
$options = array(
'position' => Mage::helper('catalog')->__('Position')
);
替换为:
$options = array(
'position' => Mage::helper('catalog')->__('Position'),
'product_id' => Mage::helper('catalog')->__('Product ID')
);
$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>
desc
在街区
<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种产品属于该类别时才会发生。再次感谢@你的意思是,只有在一个类别中有10种以上的产品时才进行排序,对吗?是的。如果一个类别中显示的产品超过9个或10个,则排序不正确。我还注意到,如果按“位置”排序,更改排序方向会影响项目。我认为它将按ID DESC排序,然后更改为ID ASC,但显然不是这样。@BWDesign如果您不介意的话,请您回送或打印$this变量好吗?我想知道返回值是什么。你是说在List.php文件中回显它吗?我不确定在哪里添加echo,因为整个脚本是一个函数。