From be9e541696b2dd7f25624f57d063385deacaf0d3 Mon Sep 17 00:00:00 2001 From: sutantowilliam <willywilliamss97@gmail.com> Date: Fri, 2 Feb 2018 12:24:15 +0700 Subject: [PATCH] Fix sort by rating --- .../Backend/Block/Widget/Button/Toolbar.php | 0 .../Block/Product/ProductList/Toolbar.php | 37 ++++++++++++++----- .../Model/Product/ProductList/Toolbar.php | 0 .../Product/ProductList/BottomToolbar.php | 0 .../Block/Product/ProductList/TopToolbar.php | 0 .../Test/Block/Order/View/ActionsToolbar.php | 0 .../ui_component/expected/listingToolbar.php | 0 7 files changed, 28 insertions(+), 9 deletions(-) mode change 100644 => 100755 app/code/Magento/Backend/Block/Widget/Button/Toolbar.php mode change 100644 => 100755 app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php mode change 100644 => 100755 app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php mode change 100644 => 100755 dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/BottomToolbar.php mode change 100644 => 100755 dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php mode change 100644 => 100755 dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php mode change 100644 => 100755 dev/tests/integration/testsuite/Magento/Ui/_files/view/ui_component/expected/listingToolbar.php diff --git a/app/code/Magento/Backend/Block/Widget/Button/Toolbar.php b/app/code/Magento/Backend/Block/Widget/Button/Toolbar.php old mode 100644 new mode 100755 diff --git a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php old mode 100644 new mode 100755 index f1567c59b60..b2322a48b34 --- a/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php +++ b/app/code/Magento/Catalog/Block/Product/ProductList/Toolbar.php @@ -199,20 +199,39 @@ class Toolbar extends \Magento\Framework\View\Element\Template )->addAttributeToSort('entity_id', $this->getCurrentDirection()); }else if($this->getCurrentOrder() == 'rate') { + if ($this->getCurrentDirection() == 'desc') { $this->_collection->getSelect()->joinLeft( - 'rating_option_vote_aggregated', - 'e.entity_id = rating_option_vote_aggregated.entity_pk_value', - array('vote_count' => 'SUM(rating_option_vote_aggregated.vote_count)')) + '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 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') { - $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 desc'); + + if ($this->getCurrentDirection() == 'desc') { + $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 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{ $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection()); diff --git a/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php b/app/code/Magento/Catalog/Model/Product/ProductList/Toolbar.php old mode 100644 new mode 100755 diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/BottomToolbar.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/BottomToolbar.php old mode 100644 new mode 100755 diff --git a/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php b/dev/tests/functional/tests/app/Magento/Catalog/Test/Block/Product/ProductList/TopToolbar.php old mode 100644 new mode 100755 diff --git a/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php b/dev/tests/functional/tests/app/Magento/Sales/Test/Block/Order/View/ActionsToolbar.php old mode 100644 new mode 100755 diff --git a/dev/tests/integration/testsuite/Magento/Ui/_files/view/ui_component/expected/listingToolbar.php b/dev/tests/integration/testsuite/Magento/Ui/_files/view/ui_component/expected/listingToolbar.php old mode 100644 new mode 100755 -- GitLab