How can I find all products without images in Magento?

前端 未结 10 694
Happy的楠姐
Happy的楠姐 2020-12-18 03:39

I have some thousand products and want to find all products without an image. I tried to search for (no image) in the admin products grid, but no result. How can I make an S

10条回答
  •  时光取名叫无心
    2020-12-18 04:02

    I know this is super old, but I found it helpful, so I thought I'd post an update.

    As an addition to Alan's answer above, I found that there are other scenarios than just the 'no_selection' .. maybe due to plugins, or general bugs in the system? The final nlike will actually find everything, but I left the others just for fun.

    Change the collection query as follows:

    $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' => '%/%/%'
            ),
        ));
    

提交回复
热议问题