Magento的:addAttributeToFilter但忽略不具有这个属性的产品呢? [英] Magento: addAttributeToFilter but ignore for products that don't have this attribute?

查看:249
本文介绍了Magento的:addAttributeToFilter但忽略不具有这个属性的产品呢?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想显示在我的商店添加一些过滤器,但他们有一个讨厌的副作用。

I'm trying to show add some filters on my store, but they have a nasty side effect.

假设我有产品类型A和B.现在我只想显示,其中的颜色=蓝色/红色。

Suppose I have product type A and B. Now I want to only show A where color = blue/red.

$collection = Mage::getResourceModel('catalog/product_collection')
    ->setStoreId($this->getStoreId())
    ->addCategoryFilter($this)
    ->addAttributeToFilter(array(
          array('attribute' => 'color', 'in' => array(4, 6)),
    )
    );

这是卓有成效的,但现在因为B的产物类型没有指定颜色值(因为这个属性没有指定它)没有产品FO这种类型的节目了。

This does the trick, but now because product type B has no value assigned to color(since this attribute isn't appointed to it) no products fo this type show up.

我发现在论坛上 http://www.magentocommerce.com /板/ viewthread / 178309 ,但它不工作:

I had found this code on the forum http://www.magentocommerce.com/boards/viewthread/178309 , but it doesn't work:

array('attribute' => 'color', 'is' => new Zend_Db_Expr('null'))

确实也不:

array('attribute' => 'color', 'null' => true),

这真实地反映了产品至极分配有属性,但没有声明价值...

That actually shows products wich have the attribute assigned but with no value declared ...

我也尝试添加

array('attribute' => 'price', 'gteq' => 0), 

由于我想通这些语句与'OR'(按文档)进行连接,但即使这样不仅增加了产品类型至极有属性分配...

Because I figured these statements were connected with 'OR' (according to the documentation) but even that only adds product types wich have the attribute assigned ...

请注意,这些值来自下拉列表中,不知道这虽然很重要。

Note that these values come from a drop down list, not sure if that matters though.

推荐答案

也许为时已晚,但是这对我的作品:

Maybe it's too late, but this works for me:

$collection = Mage::getResourceModel('catalog/product_collection')
    ->setStoreId($this->getStoreId())
    ->addCategoryFilter($this)
    ->addAttributeToFilter(
        array(
            array('attribute' => 'color', 'null' => true),
            array('attribute' => 'color', 'in' => array(4, 6)),
        ),
        '',
        'left'
);

这篇关于Magento的:addAttributeToFilter但忽略不具有这个属性的产品呢?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆