2

I want to place a condition based on product count in layer navigation. I have tried with following code

file localtion : app/design/frontend/Custom/goshop/Magento_LayeredNavigation/templates/layer/view.phtml

$search_obj      = $objectManager->create('Magento\CatalogSearch\Block\Result'); 
echo "<pre>";print_r($search_obj->getResultCount());

Its giving error as follows

Fatal error:  Uncaught Error: Call to a member function getLoadedProductCollection() on boolean in /var/www/html/unicorn-magento/vendor/magento/module-catalog-search/Block/Result.php:182
Stack trace:
#0 /var/www/html/unicorn-magento/vendor/magento/module-catalog-search/Block/Result.php(206): Magento\CatalogSearch\Block\Result->_getProductCollection()
#1 /var/www/html/unicorn-magento/app/design/frontend/Custom/goshop/Magento_LayeredNavigation/templates/layer/view.phtml(30): Magento\CatalogSearch\Block\Result->getResultCount()
#2 /var/www/html/unicorn-magento/vendor/magento/framework/View/TemplateEngine/Php.php(59): include('/var/www/html/u...')
#3 /var/www/html/unicorn-magento/vendor/magento/framework/View/Element/Template.php(270): Magento\Framework\View\TemplateEngine\Php->render(Object(Magento\LayeredNavigation\Block\Navigation), '/var/www/html/u...', Array)
#4 /var/www/html/unicorn-magento/vendor/magento/framework/View/Element/Template.php(300): Magento\Framework\View\Element\Template->fetchView('/var/www/html/u...')
#5 in /var/www/html/unicorn-magento/vendor/magento/module-catalog-search/Block/Result.php on line 182

Please help me to get search result product count . Thanks in advance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy