我在目錄列表中添加了排序方法的日期。如果我選擇按日期排序,列表按日期排序 - 這是行之有效的。 但是,我應該如何設置默認排序按日期(DESC)在目錄列表中? 在我而言,不工作這些解決方案: 的catalog.xml
通過創建日期訂購產品列表
<action method="setDefaultDirection"><dir>desc</dir></action>
<action method="setDefaultOrder"><field>created_at</field></action>
和:
目錄/座/產品/列表/ Toolbar.php
protected $_direction = 'desc';
的Magento版本:1.7。 0.2。
編輯:1
我在本地文件夾/應用程序/代碼/本地/ SortByDate /做了一個新的模塊。我添加了兩個文件。首先/catalog/model/Config.php:
class SortByDate_Catalog_Model_Config extends Mage_Catalog_Model_Config {
public function getAttributeUsedForSortByArray()
{
$options = parent::getAttributeUsedForSortByArray();
if (!isset($options['created_at'])) {
$options['created_at'] = Mage::helper('catalog')->__('Date');
}
return $options;
}
}
和第二/etc/config.xml:
<config><global><models><catalog><rewrite><config>SortByDate_Catalog_Model_Config</config></rewrite></catalog></models></global></config>
編輯2 - 解決 我修改這個功能,問題消失了: )
public function setDefaultOrder($field)
{
//set default order by date
if (isset($this->_availableOrder[$field])) {
$this->_availableOrder = array(
'created_at' => $this->__('Date'),
'name' => $this->__('Name'),
'price' => $this->__('Price'),
);
$this->_orderField = $field;
}
return $this;
}
您具體是如何的日期添加到目錄列表的排序方法? 'created_at'不是一個EAV屬性,所以你沒有通過後端做我想。請在你的問題中提供更多細節。 – Alex
我爲你添加了「編輯:1」paragraf。你能檢查一下嗎? – Krzysztof
順便說一下,在StackOverflow(S.O.)上,當您發現獨立於S.O.的自己的問題時,鼓勵性的工作流程。是回答它並接受你自己的答案。它不僅讓人們有機會獎勵你的好問題和答案,還可以讓未來的人更容易看到問題,並鼓勵其他人發佈解決方案。 –