开发者

Filter Magento Product Collection for Products with Images

开发者 https://www.devze.com 2022-12-16 08:15 出处:网络
I have a product collection that I am getting from a configurable product, and I want to filter that collection to only include products that have images attached to them. How do I go about th开发者_高

I have a product collection that I am getting from a configurable product, and I want to filter that collection to only include products that have images attached to them. How do I go about th开发者_高级运维is?

Code looks something like this:

$configurableProduct = $this->getConfigurableProduct();
$childProducts = $configurableProduct->getTypeInstance()->getUsedProductCollection();

// add some filter here to get only products with images
$childProducts->addAttributeToFilter( /* what goes here? */ );    

foreach( $childProducts as $product ) {
   ...
}

Any help is appreciated. Thanks! Joe


$this->_productCollection->addAttributeToFilter('small_image',array('notnull'=>'','neq'=>'no_selection'))


Works also with this:

$collection->addAttributeToFilter('small_image',array('notnull'=>'','neq'=>'no_selection'));
0

精彩评论

暂无评论...
验证码 换一张
取 消