如何在Magento中找到所有没有图像的产品? [英] How can I find all products without images in Magento?

查看:53
本文介绍了如何在Magento中找到所有没有图像的产品?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些千元的产品,并希望找到所有产品无图像.我试图寻找在管理产品网格(无图像),但没有结果.如何进行禁用所有这些产品的SQL查询?

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 SQL query that disables all these products?

推荐答案

停止思维SQL的条款.开始在Magento的模型的角度来思考. Magento的模型只是碰巧使用SQL作为后端.可以通过原始SQL查询事物,但是Magento的版本会有所不同,并且可能会因所使用的后端而异.

Stop thinking in terms of SQL. Start thinking in terms of Magento's Models. Magento's models just happen to use SQL as a backend. Querying for things via raw SQL is possible, but is going to vary from version to version of the Magento, and may differ depending on the backend you're using.

运行来自测试控制器动作以下,或其他地方可以从执行Magento的代码.它查询模型中没有图像的产品

Run the following from a test controller action, or somewhere else you can execute Magento code from. It queries the model for products with no image

//this builds a collection that's analagous to 
//select * from products where image = 'no_selection'
$products = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('image', 'no_selection');

foreach($products as $product)
{
    echo  $product->getSku() . " has no image \n<br />\n";
    //var_dump($product->getData()); //uncomment to see all product attributes
                                     //remove ->addAttributeToFilter('image', 'no_selection');
                                     //from above to see all images and get an idea of
                                     //the things you may query for
}       

这篇关于如何在Magento中找到所有没有图像的产品?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆