首页 文章

Magento:使用自定义字段查询客户地址

提问于
浏览
0

我已经向客户地址添加了自定义文件,但我不知道如何使用此字段进行查询 .

我正在执行以下代码:

$ collection = Mage :: getModel('customer / address') - > getCollection() - > addAttributeToSelect('custom_field') - > addFieldToFilter('custom_field','1'); echo var_dump($ collection);

但是我面临这个错误:

致命错误:在816行的app \ code \ core \ Mage \ Eav \ Model \ Entity \ Abstract.php中的非对象上调用成员函数getBackend()

我的问题是:我如何通过这个字段查询?

谢谢 .

2 回答

  • 0

    经过几次测试,我可以解决问题 . 这是代码:

    $collection = Mage::getResourceModel('customer/address_collection')
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('custom_field', 1)
                    ->getItems();
    echo print_r($collection, true);
    
  • 0

    尝试使用

    Mage :: getResourceModel('customer / address_collection')

    代替

    Mage :: getModel('customer / address') - > getCollection()

    请参阅/app/code/core/Mage/Customer/Model/Customer.php

    $collection = Mage::getResourceModel('customer/address_collection')
                       ->addAttributeToSelect('custom_field') 
                       ->addAttributeToFilter('custom_field', '1')
                       ->getItems();
    

相关问题