Magento:使用集合获取没有图像的产品

Magento:使用集合获取没有图像的产品,magento,Magento,我想按图像非空筛选产品集合。最简单的方法应该是前面提到的方法,但这不起作用:返回的集合没有元素 我认为这里的问题是,从来没有图像的产品在产品/媒体库表之间没有关系。因此,当Magento尝试使用所有这些条件进行筛选时,返回的集合为空。它没有考虑到相关表之间可能没有任何类型的关系 $collection->addAttributeToFilter(array( array ( 'attribute' => 'image',

我想按图像非空筛选产品集合。最简单的方法应该是前面提到的方法,但这不起作用:返回的集合没有元素

我认为这里的问题是,从来没有图像的产品在产品/媒体库表之间没有关系。因此,当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条件,但我不知道它应该是什么。谁能帮我一下吗

我找到了一个可以解决这个问题的方法。但我需要将此应用于我的收藏:

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

感谢

要将查询应用于您的产品集合,您可以使用

$collection->getSelect()
    ->joinLeft(
        array('_gallery_table' => $collection->getTable('catalog/product_attribute_media_gallery')),
        'e.entity_id = _gallery_table.entity_id',
        array()
    )
    ->where('_gallery_table.value IS NULL');

我已经更新了这个问题,添加了查询应该是什么样子,但我不清楚如何构建它…更新了我的答案,谢谢!!这似乎有效!我认为还有一些细节,但现在我可以得到一个基本上是我需要的集合。