Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
- <preference for="MagentoCatalogBlockProductProductListToolbar" type="{vendor}{module}BlockPluginProductProductListToolbar" />
- </config>
- namespace {Vendor}{module}BlockPluginProductProductList;
- class Toolbar extends MagentoCatalogBlockProductProductListToolbar{
- $this->_collection = $collection;
- $this->_collection->setCurPage($this->getCurrentPage());
- $limit = (int)$this->getLimit();
- if ($limit) {
- $this->_collection->setPageSize($limit);
- }
- if ($this->getCurrentOrder()) {
- switch ($this->getCurrentOrder()) {
- case 'created_at':
- if ( $this->getCurrentDirection() == 'desc' ) {
- $this->_collection
- ->getSelect()
- ->order('e.created_at DESC');
- } elseif ( $this->getCurrentDirection() == 'asc' ) {
- $this->_collection
- ->getSelect()
- ->order('e.created_at ASC');
- }
- break;
- case 'in_stock':
- $this->_collection
- ->getSelect()
- ->joinLeft(
- ['admin'=>$collection->getTable('cataloginventory_stock_item')],
- 'e.entity_id = admin.product_id')->where('admin.is_in_stock = 1');
- break;
- case 'out_stock':
- $this->_collection
- ->getSelect()
- ->joinLeft(
- ['admin'=>$collection->getTable('cataloginventory_stock_item')],
- 'e.entity_id = admin.product_id')->where('admin.is_in_stock = 0');
- break;
- default:
- $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
- break;
- }
- }
- return $this;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement