Toolrbar.php file
<?php
namespace JJCustomproductshowPluginCatalogBlockProductProductList;
class Toolbar extends MagentoCatalogBlockProductProductListToolbar
{
/**
* Set collection to pager
*
* @param MagentoFrameworkDataCollection $collection
* @return MagentoCatalogBlockProductProductListToolbar
*/
public function afterGetAvailableOrders(Toolbar $subject, $availableOrders)
{
// Remove 'position' from available orders if it exists
if (isset($availableOrders['position'])) {
unset($availableOrders['position']);
}
return $availableOrders;
}
public function setCollection($collection)
{
$this->_collection = $collection;
$this->_collection->setCurPage($this->getCurrentPage());
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();
if ($limit) {
$this->_collection->setPageSize($limit);
}
if ($this->getCurrentOrder()) {
if (($this->getCurrentOrder()) == 'position') {
$this->_collection->addAttributeToSort(
$this->getCurrentOrder(),
$this->getCurrentDirection()
);
} else {
if ($this->getCurrentOrder() == 'high_to_low') {
$this->_collection->setOrder('price', 'desc');
}elseif ($this->getCurrentOrder() == 'low_to_high') {
$this->_collection->setOrder('price', 'asc');
}
}
}
return $this;
}
}
di.xml
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoCustomerControllerAccountLoginPost">
<plugin name="loginPost" type="JJCustomproductshowPluginAccountLoginPost" sortOrder="10" disabled="true"/>
</type>
<preference for="MagentoWishlistControllerIndexAdd" type="JJCustomproductshowControllerIndexAdd">
</preference>
<preference for="MagentoCatalogBlockProductProductListToolbar" type="JJCustomproductshowPluginCatalogBlockProductProductListToolbar" />
<type name="MagentoCatalogModelConfig">
<plugin name="custom_catalog_model_config" type="JJCustomproductshowPluginCatalogModelConfig"/>
</type>
</config>