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 Add Tooltip in Checkout Shipping Field in Magento 2?

Hello Magento Friends, In today’s blog, I will explain How to Add Tooltip in Checkout…

3 days ago

How to Integrate and Use MongoDB with Laravel?

MongoDB is a popular NoSQL database that offers flexibility and scalability when handling modern web…

4 days ago

NodeJS | Callback Function

In NodeJS, callbacks empower developers to execute asynchronous operations like reading files, handling requests, and…

5 days ago

How to Show SKU in Order Summary in Magento 2?

Hello Magento Friends, In today’s blog, we will learn How to Show SKU in Order…

7 days ago

Best Colors to Use for CTA Buttons

The "Buy Now" and "Add to Cart" buttons serve as the primary call-to-action (CTA) elements…

1 week ago

Magento 2: How to Save Custom Field Value to quote_address for Multi-Shipping Orders

Hello Magento Friends, In Magento 2, the checkout process allows customers to choose multiple shipping…

1 week ago