dsasd12314 2013-06-28 01:51
浏览 17
已采纳

Magento addAttributeToFilter

I'm using attributes to a product, availablepostalcodes. This is a multi-select, there are 3 options per product: 1234 2345 3456

Now after a post (form) on the categorypage i've $_POST['postalcode'], this contains 2345. But when i do this nothing will filter:

$_productCollection=$this->getLoadedProductCollection();
$_productCollection->addAttributeToFilter("availablepostalcodes", array("finset"=>"5021"));


echo $_productCollection->load()->count(); 

The echo still shows 5, however it should be 1, cause one product has that available postalcode.

This is the product-list view /catalog/product/list.phtml

What do i miss or don't see?

Edit:

$_productCollection = Mage::getModel('catalog/product')
                              ->getCollection()
                              ->addAttributeToSelect('availablepostalcodes')
                              ->addAttributeToFilter('entity_id', array('in' => $_productCollection->getAllIds()));  

Then i get all the products again.

But when i do $_productCollection->addAttributeToFilter("availablepostalcodes", array("in" => array(5021'))); it still doesn't work

  • 写回答

2条回答 默认 最新

  • douchixu3686 2013-06-29 09:45
    关注

    you have a multiselect so you need to filter for the multiselect option id not the option value!

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路