Skip to content
Snippets Groups Projects
Commit e901b63e authored by Albertus Djauhari Djohan's avatar Albertus Djauhari Djohan
Browse files

Merge branch 'sort_by' into '2.2-develop'

Sort by

See merge request !1
parents 6ce8b488 be9e5416
1 merge request!1Sort by
File mode changed from 100644 to 100755
...@@ -197,7 +197,43 @@ class Toolbar extends \Magento\Framework\View\Element\Template ...@@ -197,7 +197,43 @@ class Toolbar extends \Magento\Framework\View\Element\Template
$this->getCurrentOrder(), $this->getCurrentOrder(),
$this->getCurrentDirection() $this->getCurrentDirection()
)->addAttributeToSort('entity_id', $this->getCurrentDirection()); )->addAttributeToSort('entity_id', $this->getCurrentDirection());
} else { }else if($this->getCurrentOrder() == 'rate') {
if ($this->getCurrentDirection() == 'desc') {
$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 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') {
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()); $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
} }
} }
...@@ -722,4 +758,14 @@ class Toolbar extends \Magento\Framework\View\Element\Template ...@@ -722,4 +758,14 @@ class Toolbar extends \Magento\Framework\View\Element\Template
} }
return $this; return $this;
} }
public function afterGetAttributeUsedForSortByArray(
\Magento\Catalog\Model\Config $catalogConfig,
$options) {
$options['rate'] = __('Rating');
$options['popular'] = __('Popularity');
return $options;
}
} }
File mode changed from 100644 to 100755
...@@ -6,6 +6,15 @@ ...@@ -6,6 +6,15 @@
*/ */
--> -->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Config">
<plugin name="Package_CustomToolbar::addCustomOptions" type="Magento\Catalog\Block\Product\ProductList\Toolbar" />
</type>
<!-- <type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
<plugin name="Package_CustomToolbar::addPriceDecendingFilterInToolbar" type="Package\CustomToolbar\Plugin\Product\ProductList\Toolbar" />
</type> -->
<preference for="Magento\Catalog\Api\Data\ProductInterface" type="Magento\Catalog\Model\Product" /> <preference for="Magento\Catalog\Api\Data\ProductInterface" type="Magento\Catalog\Model\Product" />
<preference for="Magento\Catalog\Api\ProductRepositoryInterface" type="Magento\Catalog\Model\ProductRepository" /> <preference for="Magento\Catalog\Api\ProductRepositoryInterface" type="Magento\Catalog\Model\ProductRepository" />
<preference for="Magento\Catalog\Api\CategoryAttributeRepositoryInterface" type="Magento\Catalog\Model\Category\AttributeRepository" /> <preference for="Magento\Catalog\Api\CategoryAttributeRepositoryInterface" type="Magento\Catalog\Model\Category\AttributeRepository" />
......
This diff is collapsed.
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