/**
  * @return $this
  */
 protected function _beforeToHtml()
 {
     $toolbar = $this->getToolbarBlock();
     // called prepare sortable parameters
     $collection = $this->_getProductCollection();
     // use sortable parameters
     $orders = $this->getAvailableOrders();
     if ($orders) {
         $toolbar->setAvailableOrders($orders);
     }
     $toolbar->setDefaultOrder('relevance');
     $dir = $this->getDefaultDirection();
     if ($dir) {
         $toolbar->setDefaultDirection($dir);
     }
     $modes = $this->getModes();
     if ($modes) {
         $toolbar->setModes($modes);
     }
     // set collection to toolbar and apply sort
     $toolbar->setCollection($collection);
     $this->setChild('toolbar', $toolbar);
     $this->_eventManager->dispatch('catalog_block_product_list_collection', ['collection' => $this->_getProductCollection()]);
     $this->_getProductCollection()->load();
     return parent::_beforeToHtml();
 }
Example #2
0
 /**
  * @return $this
  */
 protected function _beforeToHtml()
 {
     parent::_beforeToHtml();
     /** @var \Magento\Catalog\Block\Product\ProductList\Toolbar $toolbar */
     $toolbar = $this->getChildBlock('toolbar');
     /** @var \Magento\Theme\Block\Html\Pager $pager */
     $pager = $toolbar->getChildBlock('product_list_toolbar_pager');
     $pager->setFragment('sample_news.author.view.product');
     return $this;
 }