Skip to main content
added 11 characters in body
Source Link
Shell Suite
  • 1.7k
  • 5
  • 22
  • 36

I've successfully override productList block to show my custom filtered product collection like this:

di.xml

<preference for="\Magento\Catalog\Block\Product\ListProduct" type="\Vendor\Module\Block\Product\ListProduct"/>

Vendor\Module\Block\Product\ListProduct

protected function _getProductCollection()
{
    $productCollection = parent::_getProductCollection(); 
    if(isset($_GET['custom_input'])){
      if(!empty($_GET['custom_input']){
        $customInput = $_GET['custom_input'];
        $productCollection = $this->myModuleHelper->filterProduct(customInput, productCollection);
      }
    }
    $this->_productCollection = $productCollection;
    $this->_productCollection->getSize();
    return $proCollection;
}

but the layered navigation options not showing the right option and count product count like thisthe image below:

example failed result

I've successfully override productList block to show my custom filtered product collection like this:

di.xml

<preference for="\Magento\Catalog\Block\Product\ListProduct" type="\Vendor\Module\Block\Product\ListProduct"/>

Vendor\Module\Block\Product\ListProduct

protected function _getProductCollection()
{
    $productCollection = parent::_getProductCollection(); 
    if(isset($_GET['custom_input'])){
      if(!empty($_GET['custom_input']){
        $customInput = $_GET['custom_input'];
        $productCollection = $this->myModuleHelper->filterProduct(customInput, productCollection);
      }
    }
    $this->_productCollection = $productCollection;
    $this->_productCollection->getSize();
    return $proCollection;
}

but the layered navigation options not showing the right option and count product like this:

example failed result

I've successfully override productList block to show my custom filtered product collection like this:

di.xml

<preference for="\Magento\Catalog\Block\Product\ListProduct" type="\Vendor\Module\Block\Product\ListProduct"/>

Vendor\Module\Block\Product\ListProduct

protected function _getProductCollection()
{
    $productCollection = parent::_getProductCollection(); 
    if(isset($_GET['custom_input'])){
      if(!empty($_GET['custom_input']){
        $customInput = $_GET['custom_input'];
        $productCollection = $this->myModuleHelper->filterProduct(customInput, productCollection);
      }
    }
    $this->_productCollection = $productCollection;
    $this->_productCollection->getSize();
    return $proCollection;
}

but the layered navigation options not showing the right option and product count like the image below:

example failed result

Tweeted twitter.com/StackMagento/status/931014404178628608
Source Link
Shell Suite
  • 1.7k
  • 5
  • 22
  • 36

Layered Navigation not showing the right options after overriding product list block

I've successfully override productList block to show my custom filtered product collection like this:

di.xml

<preference for="\Magento\Catalog\Block\Product\ListProduct" type="\Vendor\Module\Block\Product\ListProduct"/>

Vendor\Module\Block\Product\ListProduct

protected function _getProductCollection()
{
    $productCollection = parent::_getProductCollection(); 
    if(isset($_GET['custom_input'])){
      if(!empty($_GET['custom_input']){
        $customInput = $_GET['custom_input'];
        $productCollection = $this->myModuleHelper->filterProduct(customInput, productCollection);
      }
    }
    $this->_productCollection = $productCollection;
    $this->_productCollection->getSize();
    return $proCollection;
}

but the layered navigation options not showing the right option and count product like this:

example failed result