How to get a count of product with no images using SQL Query in Magento 2

How to get a count of product with no images using SQL Query in Magento 2

Magneto is designed to boost your online Ecommerce store and set it in motion from all perspective starting from shopping experience to store conversions. Out of the box, Magento contains tons of unique features, powerful integrations and due to its flexibility, it became first to pick among all. Between the comparison of Magento 1 vs Magento 2, Magento 2 contains brand new architecture and database design as well as it became faster and more flexible. Another benefit of having Magento 2 is it unlocked access to all the latest features that are constantly being developed by Magento and the Magento community.

That’s why we always recommended migrating your Magento store to Latest Magento 2 which is one of the keys to business success but it will be advisable to migrate your Magento store with the support of a Magento expert. Because sooner or later you definitely may encounter some conflicts or not showing product image which is common among all. We are pioneers in migrating stores and have successfully migrated 500+ online stores so you can ask us for a Free migration quote if you are looking for the migration process.

Generally, after migration process having products with no images its common among all that’s why at MageComp blog, we will guide you to fix it easily.

Here i am sharing code which is used for retrieve product with disable status and no images.

$collection = $productCollection->create()
    	->addAttributeToSelect('*') >addAttributeToFilter('status',\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED)
        ->addAttributeToFilter('small_image', array('neq' => "no_selection"));
 
 
$collectionCount = $collection->count();
var_dump($collectionCount); //Get Collection Count
 
// Print Product Name
foreach ($collection as $product){
   echo 'Name  =  '.$product->getName().'
'; }

You can also run SQL Query for retrieve disable product status with no image.

SELECT e.*, IF(at_status.value_id > 0, at_status.value, at_status_default.value) AS status, IF(at_small_image.value_id > 0, at_small_image.value, at_small_image_default.value) AS small_image FROM catalog_product_entity AS e INNER JOIN catalog_product_entity_int AS at_status_default ON (at_status_default.entity_id = e.entity_id) AND (at_status_default.attribute_id = '97') AND at_status_default.store_id = 0 LEFT JOIN catalog_product_entity_int AS at_status ON (at_status.entity_id = e.entity_id) AND (at_status.attribute_id = '97') AND (at_status.store_id = 1) INNER JOIN catalog_product_entity_varchar AS at_small_image_default ON (at_small_image_default.entity_id = e.entity_id) AND (at_small_image_default.attribute_id = '88') AND at_small_image_default.store_id = 0 LEFT JOIN catalog_product_entity_varchar AS at_small_image ON (at_small_image.entity_id = e.entity_id) AND (at_small_image.attribute_id = '88') AND (at_small_image.store_id = 1) WHERE (IF(at_status.value_id > 0, at_status.value, at_status_default.value) = '2') AND (IF(at_small_image.value_id > 0, at_small_image.value, at_small_image_default.value) != 'no_selection')

And that’s it for today! Hopefully, your issue is fixed now.
Comment down below if you are looking for any help regarding this article.
Happy fixing!

Previous Article

How to Add Block After Add to Cart Button in Magento 2 Product page

Next Article

How to Override core code using Custom Plugin in Magento 2

Write a Comment

Leave a Comment

Your email address will not be published. Required fields are marked *

Get Connect With Us

Subscribe to our email newsletter to get the latest posts delivered right to your email.
Pure inspiration, zero spam ✨