In magento 2, is it possible to have search option within category product listing? please find below attach image enter image description here

[updated] finally, i have rewritten Listproduct.php class and search is working. The problem is layered navigation is not getting update based on search results.


        namespace Mycomp\MyModule\Rewrite\Magento\Catalog\Block\Product;

         * Class ListProduct
         * @package Mycomp\MyModule\Rewrite\Magento\Catalog\Block\Product
        class ListProduct extends \Magento\Catalog\Block\Product\ListProduct

            protected function _getProductCollection()
                $query = trim($this->getRequest()->getParam('query'));
                $this->_productCollection =  parent::_getProductCollection();
                if($query != ''){  return $this->_productCollection->addAttributeToFilter('name', ['like' => '%'.$query.'%']);}
                return $this->_productCollection; //->addAttributeToFilter('name', ['like' => '%ne%']);


Could you kindly help me?

  • Yes it is possible Commented Mar 27, 2020 at 9:49
  • Can you explain? Commented Mar 27, 2020 at 10:27
  • I am facing similar issue... is this fixed ?
    – kiranmai
    Commented May 16 at 2:51

1 Answer 1

productcollection = $this->collectionFactory->create()>addAttributeToSelect('manufacturer','LG')->load();

instead of manufacturer use your attribute and instead of LG use value on that attribute and whole productCollection will be filtered by that attribute value. so than you may use that products as you want. if any questions feel free to reply, I'll try to help.

  • i think we can't use 'addAttributeToSelect' to filter. Above my code is working, The problem is layered navigation is not getting update based on search results, see highlighted section(count) in the attached image. it was wrong. (tinyurl.com/sjcroqm. Commented Mar 27, 2020 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.