Advertisement
Guest User

Untitled

a guest
Dec 9th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
  2. <preference for="MagentoCatalogBlockProductProductListToolbar" type="{vendor}{module}BlockPluginProductProductListToolbar" />
  3. </config>
  4.  
  5. namespace {Vendor}{module}BlockPluginProductProductList;
  6.  
  7. class Toolbar extends MagentoCatalogBlockProductProductListToolbar{
  8.  
  9. $this->_collection = $collection;
  10.  
  11. $this->_collection->setCurPage($this->getCurrentPage());
  12.  
  13. $limit = (int)$this->getLimit();
  14. if ($limit) {
  15. $this->_collection->setPageSize($limit);
  16. }
  17.  
  18.  
  19. if ($this->getCurrentOrder()) {
  20.  
  21.  
  22. switch ($this->getCurrentOrder()) {
  23.  
  24. case 'created_at':
  25.  
  26. if ( $this->getCurrentDirection() == 'desc' ) {
  27.  
  28. $this->_collection
  29. ->getSelect()
  30. ->order('e.created_at DESC');
  31.  
  32.  
  33. } elseif ( $this->getCurrentDirection() == 'asc' ) {
  34.  
  35. $this->_collection
  36. ->getSelect()
  37. ->order('e.created_at ASC');
  38.  
  39. }
  40.  
  41. break;
  42. case 'in_stock':
  43. $this->_collection
  44. ->getSelect()
  45. ->joinLeft(
  46. ['admin'=>$collection->getTable('cataloginventory_stock_item')],
  47. 'e.entity_id = admin.product_id')->where('admin.is_in_stock = 1');
  48.  
  49.  
  50. break;
  51. case 'out_stock':
  52.  
  53.  
  54.  
  55. $this->_collection
  56. ->getSelect()
  57. ->joinLeft(
  58. ['admin'=>$collection->getTable('cataloginventory_stock_item')],
  59. 'e.entity_id = admin.product_id')->where('admin.is_in_stock = 0');
  60.  
  61.  
  62. break;
  63. default:
  64.  
  65. $this->_collection->setOrder($this->getCurrentOrder(), $this->getCurrentDirection());
  66. break;
  67.  
  68. }
  69.  
  70. }
  71.  
  72.  
  73.  
  74. return $this;
  75.  
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement