【问题标题】:Filter Magento Product Collection for Products with Images过滤带有图像的产品的 Magento 产品集合
【发布时间】:2010-01-12 19:28:29
【问题描述】:

我有一个从可配置产品中获取的产品集合,我想过滤该集合以仅包含附有图像的产品。我该怎么办?

代码如下所示:

$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 ) {
   ...
}

感谢任何帮助。谢谢! 乔

【问题讨论】:

    标签: php collections magento


    【解决方案1】:
    $this->_productCollection->addAttributeToFilter('small_image',array('notnull'=>'','neq'=>'no_selection'))
    

    【讨论】:

    • 谢谢你的回答,coyl。我希望根据“图库”表集获取图像,因为我不能保证用户已选择图像作为“small_image”的默认值。
    【解决方案2】:

    也适用于此:

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

    【讨论】:

      猜你喜欢
      • 2014-09-19
      • 1970-01-01
      • 2014-12-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2014-01-01
      相关资源
      最近更新 更多