Magento addAttributeToFilter 没有按照我认为应该的方式工作
我有一个产品属性,我已将范围设置为网站(因此理论上它在定义的每个网站上都会有所不同)。
然而,由于某种原因,当我在 addAttributeToFilter() 中使用它时,它似乎忽略了它。
让我向您展示我正在使用的代码:
$total_products_obj = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('discontinued', array('neq' => 1) )
->addAttributeToFilter('video_url', array('notnull' => '') );
我遇到问题的属性是 video_url 属性。就像我说的,它的范围设置为网站,其中停产是全局属性。
我还没有对网站属性做太多事情,我还需要做些什么才能让这个属性不被忽略吗?现在我正在收集所有停产不等于 1 的产品。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了一个解决方法。请改用该方法的数组版本,真正用于创建“OR”条件。这会生成正确的 SQL。
例如
->addAttributeToFilter( array(
array( 'attribute'=>'video_url', 'notnull' => '' )
))
它有点难看,但允许您仍然使用平面目录。
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.