我有几千种产品,想要找到没有图像的所有产品.我试图在管理产品网格中搜索(无图像),但没有结果.如何创建禁用所有这些产品的SQL查询?
Ala*_*orm 15
不要再考虑SQL了.开始考虑Magento的模型.Magento的模型碰巧使用SQL作为后端.可以通过原始SQL查询事物,但Magento的版本会有所不同,并且可能因您使用的后端而异.
从测试控制器操作运行以下命令,或者从其他位置执行Magento代码.它在模型中查询没有图像的产品
//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
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我知道这是超级老,但我觉得它很有用,所以我想我会发布更新.
作为Alan上面回答的补充,我发现除了'no_selection'之外还有其他场景......可能是因为插件或系统中的一般错误?最后的nlike实际上会找到所有东西,但我离开其他人只是为了好玩.
更改集合查询,如下所示:
$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' => '%/%/%'
),
));
Run Code Online (Sandbox Code Playgroud)
我不久前写了一篇博客文章,其中使用 SQL 查询来查找丢失的图像。它不会禁用产品,但至少是一个开始: http: //prattski.com/2010/06/29/magento-sql-to-find-missing-images/。从这一点来看应该很容易做到。如果您的属性 ID 与我的不匹配,您可能需要更改属性 ID。
| 归档时间: |
|
| 查看次数: |
16635 次 |
| 最近记录: |