如何通过YesNo type属性过滤集合? [英] How do I filter a collection by a YesNo type attribute?
问题描述
我有一个功能"属性,该属性具有是/否"选择列表作为管理员输入.我假设是"和否"的值分别为1和0,就像其他每个是/否"列表一样.但是,如果我尝试使用功能"属性过滤集合,则无法使用:
I have a ‘featured’ attribute, which has a Yes/No select-list as the admin input. I presume that the values for Yes and No are 1 and 0, as they are for every other Yes/No list. However, if I try and filter a collection using the ‘featured’ attribute, it doesn’t work:
$feat_attribute = $_product->getResource()->getAttribute($featuredattribute)->getSource()->getOptionId(1);
但是,如果我使用下拉菜单创建功能"属性,并写下自己的是"和否",则它的工作方式如下:
But, if I make a ‘featured’ attribute with a dropdown, and write my own Yes and No, then it works as below:
$feat_attribute = $_product->getResource()->getAttribute($featuredattribute)->getSource()->getOptionId('Yes');
有人有什么想法吗?我也尝试过将值设置为true/false,yes/no,on/off等,但没有任何乐趣.
Anyone any ideas? I’ve also tried values as true/false, yes/no, on/off etc, but no joy.
推荐答案
这似乎是一个旧线程,但是无论如何我都遇到了同样的问题,我将该属性设置为在产品列表和产品视图中可见,然后将addAttributeToFilter(feature_product_attribute, 1)
应用于是/否"类型.
This seems to be an old thread, but anyway I just had the same issue, I set the attribute to be visible in product listing and product view, and then apply addAttributeToFilter(feature_product_attribute, 1)
for Yes/No type.
这篇关于如何通过YesNo type属性过滤集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!