【发布时间】:2013-06-03 08:16:21
【问题描述】:
我想按不为空的图像过滤产品集合。最简单的方法应该是here提到的方法,但这不起作用:返回的集合没有元素。
我认为这里的问题是,从未有图像的产品在 product/media_gallery 表之间没有关系。因此,当 Magento 尝试使用所有这些条件进行过滤时,返回的集合是空的。它没有考虑到所涉及的表之间可能不是任何类型的关系。
$collection->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' => '%/%/%'
),
));
我想我应该使用 joinLeft 条件,但我不知道应该怎么做。有人可以帮我解决这个问题吗?
我找到了一个very interesting query 应该可以解决问题。但我需要将此应用到我的收藏中:
SELECT *
FROM `catalog_product_entity` AS a
LEFT JOIN `catalog_product_entity_media_gallery` AS b ON a.entity_id = b.entity_id
WHERE b.value IS NULL
谢谢
【问题讨论】:
标签: magento