2

Basically I want to show static content using a block on my category menu in Magento 2.3.5. I have created a category and set Display Mode as Static Block only, Anchor set to No and Added a block from Add CMS Block dropdown, but the issue is when I try to browse this category it shows We can't find products matching the selection. How to hide this message. enter image description here

0

The message We can't find products matching the selection. comes from the file /magento/vendor/magento/module-catalog/view/frontend/templates/product/list.phtml.

You need to override the list.phtml file in your custom module or theme to hide the message.

Example:

<?php
/**
 * Product list template
 *
 * @see \Magento\Catalog\Block\Product\ListProduct
 */
?>
<?php
$_productCollection = $block->getLoadedProductCollection();
$_helper = $this->helper(Magento\Catalog\Helper\Output::class);
?>
<?php if (!$_productCollection->count()) :?>

// ---------------------- comment or remove the below code ------------------------------
<div class="message info empty"><div><?= $block->escapeHtml(__('We can\'t find products matching the selection.')) ?></div></div>

<?php else :?>
    <?= $block->getToolbarHtml() ?>
    <?= $block->getAdditionalHtml() ?>
....
....

I hope this helps!

9
  • how to use this in my child theme? – ishaq Jul 19 '20 at 12:19
  • @ishaq You need to copy the original file in your child theme and apply the changes. Copy file to the child theme app\design\frontend\<VENDOR_NAME>\<THEME_NAME>\Magento_Catalog\templates\product\listing.phtml and make the code changes. – Bhaumik Upadhyay Jul 19 '20 at 12:22
  • still, no way put this file in my custom theme but the message is still there deployed static content and cleaned and flushed cache also. put file in this location and commented the code /var/www/html/app/design/frontend/Airosoconnect/base/Magento_Catalog/templates/product – ishaq Jul 19 '20 at 12:49
  • <!-- <p class="message note"><?= $block->escapeHtml(__('We can\'t find products matching the selection.')) ?></p> --> updated this line in listing.phtml file – ishaq Jul 19 '20 at 12:50
  • Try removing the <?= $block->escapeHtml(__('We can\'t find products matching the selection.')) ?> and remove rm -rf var/* generated/* pub/static/*, re-run static content deploy, clear the cache and check again. – Bhaumik Upadhyay Jul 19 '20 at 13:07

Your Answer

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

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