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

查看:21
本文介绍了如何在 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 
<br />
";
    //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天全站免登陆