【问题标题】:Magento show products "new_from_date" first in list.phtmlMagento 首先在 list.phtml 中显示产品“new_from_date”
【发布时间】:2013-12-25 03:06:53
【问题描述】:

我尝试在我的 list.phtml 中首先显示产品“new_from_date”..

我尝试覆盖 List.php 块类添加

   $this->_productCollection = $layer->getProductCollection()->addAttributeToSort('news_from_date','desc');

但是不行... 有什么帮助吗? 谢谢

【问题讨论】:

    标签: magento sorting collections


    【解决方案1】:

    我认为问题在于 Mage_Catalog_Block_Product_List 块中的 getSortBy 魔术方法。而在

    protected function _beforeToHtml()
    

    您可能会看到该代码

    if ($sort = $this->getSortBy()) {
        $toolbar->setDefaultOrder($sort);
    }
    
    ...
    
    $toolbar->setCollection($collection);
    

    然后转到工具栏(Mage_Catalog_Block_Product_List_Toolbar)

    public function setCollection($collection)
    {
    ...
        if ($this->getCurrentOrder()) {
            $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
        }
    

    我认为这是一个问题。您可以尝试在您的块中覆盖受保护的函数 _beforeToHtml() 并更改

    if ($sort = $this->getSortBy()) {
        $toolbar->setDefaultOrder($sort);
    }
    

    $collection->addAttributeToSort('news_from_date','desc');
    

    或者可以观察'catalog_block_product_list_collection'并在那里改变排序。这些只是建议,但我可以看到问题直接在 _beforeToHtml() 和工具栏中。

    【讨论】:

      猜你喜欢
      • 2012-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-15
      • 1970-01-01
      相关资源
      最近更新 更多