对于畅销书
在code/local/Mage/Catalog/Block/Product/List/Toolbar.php
方法setCollection中使用了
public function setCollection($collection) {
parent::setCollection($collection);
if ($this->getCurrentOrder()) {
if($this->getCurrentOrder() == 'saleability') {
$this->getCollection()->getSelect()
->joinLeft('sales_flat_order_item AS sfoi', 'e.entity_id = sfoi.product_id', 'SUM(sfoi.qty_ordered) AS ordered_qty')
->group('e.entity_id')->order('ordered_qty' . $this->getCurrentDirectionReverse());
} else {
$this->getCollection()
->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
}
}
return $this;
}
Run Code Online (Sandbox Code Playgroud)
在setCollection之后我添加了这个方法:
public function getCurrentDirectionReverse() {
if ($this->getCurrentDirection() == 'asc') {
return 'desc';
} elseif ($this->getCurrentDirection() == 'desc') {
return 'asc';
} else {
return $this->getCurrentDirection();
}
}
Run Code Online (Sandbox Code Playgroud)
最后我将mehod setDefaultOrder更改为
public function setDefaultOrder($field) {
if (isset($this->_availableOrder[$field])) {
$this->_availableOrder = array(
'name' => $this->__('Name'),
'price' => $this->__('Price'),
'position' => $this->__('Position'),
'saleability' => $this->__('Saleability'),
);
$this->_orderField = $field;
}
return $this;
}
Run Code Online (Sandbox Code Playgroud)
评分最高
http://www.fontis.com.au/blog/magento/sort-products-rating
尝试上面的代码.
添加日期
对于任何工作或关注,我不与任何上述链接相关联,只是出于知识目的和解决您的问题.
希望这一定会对你有所帮助.
归档时间: |
|
查看次数: |
6961 次 |
最近记录: |