Magento でカスタム ソート オプションを追加するにはどうすればよいですか。価格順の並べ替えに加えて、ベストセラー、トップ評価、独占を追加したいと考えています。助けてください
7210 次
3 に答える
8
ベストセラー向け
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;
}
setCollection の後に、次のメソッドを追加しました。
public function getCurrentDirectionReverse() {
if ($this->getCurrentDirection() == 'asc') {
return 'desc';
} elseif ($this->getCurrentDirection() == 'desc') {
return 'asc';
} else {
return $this->getCurrentDirection();
}
}
最後に、メソッド 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;
}
最高評価の
http://www.fontis.com.au/blog/magento/sort-products-rating
上記のコードを試してください。
追加日
私は上記のリンクのいずれにも関連していません。これは、知識を目的として、問題を解決するためのものです。
これが確実に役立つことを願っています。
于 2013-09-16T15:45:09.853 に答える