Magento类别产品列表排序方式畅销产品选项

Magento类别产品列表排序方式畅销产品选项

本文介绍了Magento类别产品列表排序方式畅销产品选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在类别"产品列表的选择框中获得最佳卖方"选项.

I m trying get Best Seller option in select box at Category product listing.

我已经扩展了

class Mymodule_Catalog_Block_Product_List_Toolbar extends Mage_Catalog_Block_Product_List_Toolbar
{

    protected function _construct()
    {
        parent::_construct();
    }

    public function getAvailableOrders()
    {
        $this->_availableOrder['bestseller'] = $this->__('Best Seller');
        return $this->_availableOrder;
    }


}

此后,我在选择框中获得了畅销书"选项.但是,我不知道如何使它工作.任何帮助将不胜感激.

After that , I got Best Seller option in select box.But, I don't known how to get it work.Any help would be appreciated.

推荐答案

您还需要扩展setCollection():

You need extend setCollection() too:

public function getAvailableOrders()
{
    $this->_availableOrder['bestseller'] = $this->__('Best Seller');
    return $this->_availableOrder;
}


public function setCollection($collection)
{
    // ...
    if ($this->getCurrentOrder()) {
        if ($this->getCurrentOrder() == 'bestseller') {
            // add needed joins to collection here to get 'bestseller' column in collection
        }
        $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
    }
    return $this;
}

顺便说一句,您知道 $ this-> __('Best Seller'); 是不好的风格吗?如您所知, $ this-> __()是当前模块数据助手__()方法的快捷方式.但是,如果有人将您的块扩展到另一个模块中 - 该模块数据助手将用于将Best Seller"字符串翻译成其他语言.显然,在他的模块中,他可能没有畅销书"字符串的翻译.这就是为什么您必须始终使用 Mage :: helper('your_module/data')-> __()进行翻译的原因.

Btw, do you know that $this->__('Best Seller'); is bad style? As you know, $this->__() is shortcut for current module data helper __() method. But if someone will extended your block in another module - that module data helper will be used to translate 'Best Seller' string to other languages. It is evident that in his module he may not have translation for 'Best Seller' string. That's why you must always use Mage::helper('your_module/data')->__() for translation.

这篇关于Magento类别产品列表排序方式畅销产品选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 06:29