Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/magento/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Magento:通过自定义字段查询客户地址_Magento_Magento 1.7 - Fatal编程技术网

Magento:通过自定义字段查询客户地址

Magento:通过自定义字段查询客户地址,magento,magento-1.7,Magento,Magento 1.7,我已经在客户地址中添加了一个自定义字段,但我不知道如何使用此字段进行查询 我正在执行以下代码: $collection=Mage::getModel('客户/地址') ->getCollection() ->addAttributeToSelect('custom_field') ->addFieldToFilter('custom_field','1'); echo var_dump($collection) 但我面临着这个错误: 致命错误:对中的非对象调用成员函数getBackend() 第

我已经在客户地址中添加了一个自定义字段,但我不知道如何使用此字段进行查询

我正在执行以下代码:

$collection=Mage::getModel('客户/地址') ->getCollection() ->addAttributeToSelect('custom_field') ->addFieldToFilter('custom_field','1'); echo var_dump($collection)

但我面临着这个错误:

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

我的问题是:如何通过该字段进行查询

谢谢。

尝试使用

Mage::getResourceModel('客户/地址\集合')

而不是

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

经过几次测试,我可以解决这个问题。代码如下:

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

感谢您的建议,但它没有起作用:/-我可以执行第一行,但当我尝试添加#2或3#行时,我提到的错误再次发生。还有别的想法吗?