逆转magento中最新产品过滤器的排序顺序
问题描述:
我使用以下查询为我的Magento商店添加了一个最新过滤器。逆转magento中最新产品过滤器的排序顺序
UPDATE `catalog_eav_attribute`
SET `used_for_sort_by` = 1
WHERE attribute_id = (SELECT ea.attribute_id FROM `eav_attribute` ea WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") AND `attribute_code` = "created_at")
UPDATE `eav_attribute`
SET frontend_label = "Newest"
WHERE `entity_type_id` = (SELECT `entity_type_id` FROM `eav_entity_type` WHERE `entity_model` = "catalog/product") and `attribute_code` = "created_at";
排序的过滤器是反映在前端,但它首先显示旧产品和新产品在过去,谁能告诉我怎样才能改变这种排序顺序?
答
默认情况下它会被归类为升,你可以从文件改成:应用程序/代码/核心/法师/目录/座/产品/ list.php的设置集合前
protected function _beforeToHtml()
{
$toolbar = $this->getToolbarBlock();
// called prepare sortable parameters
$collection = $this->_getProductCollection();
// use sortable parameters
if ($orders = $this->getAvailableOrders()) {
$toolbar->setAvailableOrders($orders);
}
if ($sort = $this->getSortBy()) {
$toolbar->setDefaultOrder($sort);
}
if ($dir = $this->getDefaultDirection()) {
$toolbar->setDefaultDirection($dir);
}
if ($modes = $this->getModes()) {
$toolbar->setModes($modes);
}
/************ Our Condition ***********/
if($sort == 'created_at'){
$toolbar->setDefaultDirection('desc');
}
// set collection to toolbar and apply sort
$toolbar->setCollection($collection);
,做确保在进行更改之前覆盖此文件。