Magento filter products by custom attributes

不想你离开。 提交于 2020-01-04 03:01:12

问题


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();

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).

I tried all versions of addAttributeToFilter and AddFieldToFilter.

Oh, and I'm fighting with Magento 1.7.0.0


回答1:


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

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).

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



来源:https://stackoverflow.com/questions/12162154/magento-filter-products-by-custom-attributes

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!