Magento过滤器产品的自定义属性 [英] Magento filter products by custom attributes

查看:103
本文介绍了Magento过滤器产品的自定义属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我尝试了所有内容并阅读了所有内容,但对于在Magento中过滤产品集合感到非常困惑.我创建了一个新的产品属性'syncron_state',但是我无法通过此过滤器来过滤product_collection.当我尝试按核心属性进行过滤时,效果很明显.

I think I tried everything and read everything, but I'm pretty confused about filtering product collection in Magento. I created a new product attribute 'syncron_state', but I can't manage to filter the product_collection by this filter. When I try to filter by core attributes it works and that's clear.

$productsCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('sku', array('eq' => '000001'))
->setCurPage(1)->setPageSize(10)
->load();

但是,如果我尝试按属性进行过滤,我什么也没得到.

But if I try to filter by my attribute I get nothing.

$productsCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToFilter('syncron_state', array('eq' => '1'))
->setCurPage(1)->setPageSize(10)
->load();

syncron_state是一个Yes/No属性,据我所知它在数据库中具有一个整数值(但是我在过滤中也尝试了true/false和yes/no).

The syncron_state is a Yes/No Attribute, as far as I know it has an integer value in database (but i tried true/false and yes/no in filtering also).

我尝试了所有版本的addAttributeToFilter和AddFieldToFilter.

I tried all versions of addAttributeToFilter and AddFieldToFilter.

哦,我正在与Magento 1.7.0.0战斗

Oh, and I'm fighting with Magento 1.7.0.0

推荐答案

使用syncron_state作为过滤器的集合应该正常工作,至少对于将syncron_state设置为.

Your collection using syncron_state as a filter should work as expected, at least for products having syncron_state set to yes.

不获取产品的可能原因之一是,您未能将新的syncron_state属性添加到适当的属性集中(这是必须的).

One possible reason for not getting products would be, that you failed to add the new syncron_state attribute to the proper attribute set (which is a must).

另一个可能的原因是,您只是忘记将至少一个产品的syncron_state属性设置为Yes.

Another possible reason would be, that you simply forgot to set the syncron_state attribute of at least one product to Yes.

这篇关于Magento过滤器产品的自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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