Is it possible to run a query to find a list of products with no images assigned to them? Ideally I'd like SKUs printed out on the screen.
Asked
Active
Viewed 1.3k times
5 Answers
17
You can find the collection for below code.
$_products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(array(
array (
'attribute' => 'image',
'like' => 'no_selection'
),
array (
'attribute' => 'image', // null fields
'null' => true
),
array (
'attribute' => 'image', // empty, but not null
'eq' => ''
),
array (
'attribute' => 'image', // check for information that doesn't conform to Magento's formatting
'nlike' => '%/%/%'
),
));
you can got all product list which has no Images assign.
Keyul Shah
- 7,219
- 12
- 37
- 60
10
If you want only the products that don't have image, small_image or thumbnail assigned then the answers from @KeyulShah or @TBIInfotech will give you just that.
If you want the products that have no images at all, you can run this query on the database and get them.
SELECT
e.sku, COUNT(m.value) as cnt
FROM
catalog_product_entity e
LEFT JOIN catalog_product_entity_media_gallery m
ON e.entity_id = m.entity_id
GROUP BY
e.entity_id
HAVING
cnt = 0
If you remove the having statement you will get a 2 column result with the product skus and the number of images assigned to them.
You can just export that as a csv.
-
By any chance Will it work in Magento2 ! – Amit Singh Oct 01 '18 at 11:52
-
probably, but I cannot guarantee it – Marius Oct 01 '18 at 11:59
5
Just a small modification to what @keyul shah described, just put the code on magento root:
<?php
require 'app/Mage.php';
Mage::app();
$_products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(array(
array (
'attribute' => 'image',
'like' => 'no_selection'
),
array (
'attribute' => 'image', // null fields
'null' => true
),
array (
'attribute' => 'image', // empty, but not null
'eq' => ''
),
array (
'attribute' => 'image', // check for information that doesn't conform to Magento's formatting
'nlike' => '%/%/%'
),
));
foreach($_products as $_product){
echo $_product->getSku();
}
TBI Infotech
- 4,788
- 1
- 13
- 30
-
Your solution worked great, I've given you an upvote but will award the answer to the original post. – Francis Kim Jun 16 '14 at 06:51
4
If anyone looking for Magento 2. This will work. Its same as @Marius just added one table.
SELECT
e.sku, COUNT(m.value) as cnt
FROM catalog_product_entity e
LEFT JOIN catalog_product_entity_media_gallery_value_to_entity r
ON e.entity_id = r.entity_id
LEFT JOIN catalog_product_entity_media_gallery m
ON r.value_id = m.value_id
GROUP BY
e.entity_id
HAVING
cnt = 0
Amit Singh
- 1,765
- 3
- 19
- 37
-
I ended up writing something based on this https://magento.stackexchange.com/a/344922/70343 – Dominic Pixie Aug 20 '21 at 15:18
2
This works for me....
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter(
array(
array(
'attribute' => 'image',
'null' => '1'
),
array(
'attribute' => 'small_image',
'null' => '1'
),
array(
'attribute' => 'thumbnail',
'null' => '1'
),
array(
'attribute' => 'image',
'nlike' => '%/%/%'
),
array(
'attribute' => 'small_image',
'nlike' => '%/%/%'
),
array(
'attribute' => 'thumbnail',
'nlike' => '%/%/%'
)
),
null,
'left'
);
Rahul Dadhich
- 159
- 8
-
This works better, because if the product has not image yet, probably the attribute relation doesn't exists, and probably wont work correctly. – Beto Castillo Apr 02 '18 at 23:28