Is it possible to programmatically hide products on the front end that has no image?
Running Magento 2.3.
You can create two plugin one for "Magento\Catalog\Model\Layer" and another for "Magento\Catalog\Block\Product\ProductList\Toolbar" as describe below to Hide products with no images on frontend
step 1) Create a di.xml under /app/code/Vendor/Module/etc/
File : di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Catalog\Model\Layer">
<plugin name="custom_product_model_layer" type="Vendor\Module\Model\Plugin\Layer" />
</type>
<type name="Magento\Catalog\Block\Product\ProductList\Toolbar">
<plugin name="custom_product_toolbar" type="Vendor\Module\Model\Plugin\Toolbar" />
</type>
</config>
step 2) create Layer.php under /app/code/Vendor/Module/Model/Plugin/
File : Layer.php
<?php
namespace Vendor\Module\Model\Plugin;
use Magento\Catalog\Model\Layer as CatalogLayer;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
class Layer
{
public function aroundgetProductCollection(\Magento\Catalog\Model\Layer $subject, \Closure $proceed)
{
$collection = $proceed();
$collection
->addAttributeToSelect('*')
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->addAttributeToFilter('small_image', array('neq' => ''))
->addAttributeToFilter('small_image', array('neq' => null));
return $collection;
}
}
step 3) create Toolbar.php under /app/code/Vendor/Module/Model/Plugin/
File : Toolbar.php
<?php
namespace Vendor\Module\Model\Plugin;
use Magento\Catalog\Model\ResourceModel\Product\Collection as ProductCollection;
class Toolbar
{
public function aroundgetProductCollection(\Magento\Catalog\Model\Layer $subject, \Closure $proceed)
{
$collection = $proceed();
$collection
->addAttributeToSelect('*')
->addAttributeToFilter('small_image', array('neq' => 'no_selection'))
->addAttributeToFilter('small_image', array('neq' => ''))
->addAttributeToFilter('small_image', array('neq' => null));
return $collection;
}
}
step 4: Run Below CLI commands
sudo php bin/magento setup:di:compile