2013-12-07 64 views
1

我尝试在我的list.phtml,以显示产品“new_from_date”首先所有其他的..Magento的显示产品“new_from_date”先list.phtml

我尝试重写list.php的块类中添加

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

但不工作... 任何帮助吗? 谢谢

回答

0

我认为问题是在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()和工具栏中看到问题。

相关问题