addAttributeToFilter下拉值查询Magento 1.9



我的Magento遇到了一个问题,我目前正在尝试列出下拉属性"condition"设置为"Exchange"的搜索结果

$_productCollection=$this->getLoadedProductCollection();
$_productCollection->addAttributeToSelect('*')
->addAttributeToFilter('condition', array('eq' => 'Exchange'));

我理解,因为它是一个下拉列表,所以有一些不同,加上我正在编辑我的list.phtml文件。

这是重新定义属性时搜索转储的输出:

( [] => Array ( [0] => Array ( [value] => 6475 [label] => Exchange ) [1] => Array ( [value] => 6476 [label] => New ) ) ) [_attribute:protected] => Mage_Catalog_Model_Resource_Eav_Attribute Object *RECURSION* [_options:protected] => Array ( [] => Array ( [0] => Array ( [value] => 6475 [label] => Exchange ) [1] => Array ( [value] => 6476 [label] => New ) ) ) ) [_attributeIdCache:protected] => Array ( ) [_dataTable:protected] => catalog_product_entity_int [_resourceName:protected] => catalog/attribute [_resource:protected] => [_resourceCollectionName:protected] => catalog/attribute_collection [_dataSaveAllowed:protected] => 1 [_isObjectNew:protected] => [_data:protected] => Array ( [entity_type_id] => 4 [attribute_code] => condition [attribute_model] => catalog/resource_eav_attribute [backend_model] => eav/entity_attribute_backend_default [backend_type] => int [backend_table] => [frontend_model] => [frontend_input] => select [frontend_label] => Condition [frontend_class] => [source_model] => eav/entity_attribute_source_table [is_required] => 0 [is_user_defined] => 1 [default_value] => 6475 [is_unique] => 0 [note] => [attribute_id] => 152 [frontend_input_renderer] => [is_global] => 1 [is_visible] => 1 [is_searchable] => 1 [is_filterable] => 1 [is_comparable] => 0 [is_visible_on_front] => 1 [is_html_allowed_on_front] => 1 [is_used_for_price_rules] => 0 [is_filterable_in_search] => 1 [used_in_product_listing] => 0 [used_for_sort_by] => 0 [is_configurable] => 1 [apply_to] => [is_visible_in_advanced_search] => 0 [position] => 0 [is_wysiwyg_enabled] => 0 [is_used_for_promo_rules] => 0 ) [_hasDataChanges:protected] => 1 [_origData:protected] => [_idFieldName:protected] => attribute_id [_isDeleted:protected] => [_oldFieldsMap:protected] => Array ( ) [_syncFieldsMap:protected] => Array ( ) ) )

如果有人能为我指明正确的方向,我将不胜感激!

感谢:)

$valueId = 6475; //You can first get the value of label "Exchange". 
//Attribute values are usually stored in eav_attribute_option_value table. 
$_productCollection=$this->getLoadedProductCollection();
$_productCollection->addAttributeToSelect('*')
->addAttributeToFilter('condition', array('eq' => $valueId)); //Use Value Id here instead of the label

最新更新