Skip to content
Snippets Groups Projects
Commit be9e5416 authored by William Sutanto's avatar William Sutanto
Browse files

Fix sort by rating

parent e4440201
Branches sort_by
1 merge request!1Sort by
File mode changed from 100644 to 100755
...@@ -199,20 +199,39 @@ class Toolbar extends \Magento\Framework\View\Element\Template ...@@ -199,20 +199,39 @@ class Toolbar extends \Magento\Framework\View\Element\Template
)->addAttributeToSort('entity_id', $this->getCurrentDirection()); )->addAttributeToSort('entity_id', $this->getCurrentDirection());
}else if($this->getCurrentOrder() == 'rate') { }else if($this->getCurrentOrder() == 'rate') {
if ($this->getCurrentDirection() == 'desc') {
$this->_collection->getSelect()->joinLeft( $this->_collection->getSelect()->joinLeft(
'rating_option_vote_aggregated', 'review_entity_summary',
'e.entity_id = rating_option_vote_aggregated.entity_pk_value', 'e.entity_id = review_entity_summary.entity_pk_value',
array('vote_count' => 'SUM(rating_option_vote_aggregated.vote_count)')) array('vote_count' => 'AVG(review_entity_summary.rating_summary)'))
->group('e.entity_id') ->group('e.entity_id')
->order('vote_count desc'); ->order('vote_count desc');
} else {
$this->_collection->getSelect()->joinLeft(
'review_entity_summary',
'e.entity_id = review_entity_summary.entity_pk_value',
array('vote_count' => 'AVG(review_entity_summary.rating_summary)'))
->group('e.entity_id')
->order('vote_count asc');
}
}else if($this->getCurrentOrder() == 'popular') { }else if($this->getCurrentOrder() == 'popular') {
$this->_collection->getSelect()->joinLeft(
'sales_order_item', if ($this->getCurrentDirection() == 'desc') {
'e.entity_id = sales_order_item.product_id', $this->_collection->getSelect()->joinLeft(
array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)')) 'sales_order_item',
->group('e.entity_id') 'e.entity_id = sales_order_item.product_id',
->order('qty_ordered desc'); array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
->group('e.entity_id')
->order('qty_ordered desc');
} else {
$this->_collection->getSelect()->joinLeft(
'sales_order_item',
'e.entity_id = sales_order_item.product_id',
array('qty_ordered'=>'SUM(sales_order_item.qty_ordered)'))
->group('e.entity_id')
->order('qty_ordered asc');
}
}else{ }else{
$this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
......
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
File mode changed from 100644 to 100755
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment