How To

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!

Click to rate this post!
[Total: 3 Average: 4]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

How to Integrate ChatGPT with Laravel Application?

In this guide, we'll explore how to integrate ChatGPT, an AI-powered chatbot, with a Laravel…

2 days ago

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

4 days ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

4 days ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

5 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

6 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

1 week ago