开发者

Magento addAttributeToFilter not working the way I think it should

开发者 https://www.devze.com 2023-02-14 03:42 出处:网络
I have a product attribute that I have set the scope to website (so in theory it would be different on each website defined).

I have a product attribute that I have set the scope to website (so in theory it would be different on each website defined).

However for some reason when I use it in an addAttributeToFilter() it seems to ignore it.

Let me show you the code I am using:

$total_products_obj = Mage::getModel('catalog/product开发者_如何转开发')
  ->getCollection()
  ->addAttributeToSelect('*')
  ->addAttributeToFilter('discontinued', array('neq' => 1) )
  ->addAttributeToFilter('video_url', array('notnull' => '') );

The attribute I am having trouble with is the video_url attribute. Like I said it's scope is set to Website where discontinued is a Global attribute.

I have not really done much with Website attributes, is there something else that I need to do in order to get this attribute to not be ignored? Right now I am getting a collection of all the products where discontinued does not equal 1.


I have found a workaround. Use the array version of the method instead, really intended for creating an 'OR' condition. This generates the correct SQL.

E.g.

->addAttributeToFilter( array( array( 'attribute'=>'video_url', 'notnull' => '' ) ))

It's a bit ugly but allows you to still use the flat catalog.


I turned off Use Flat Catalog Product and it started to work as expected.

0

精彩评论

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