【问题标题】:Magento: query through customer address with custom fieldMagento:通过自定义字段查询客户地址
【发布时间】:2023-03-03 10:37:01
【问题描述】:

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

我正在执行以下代码:

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

但我遇到了这个错误:

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

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

谢谢。

【问题讨论】:

    标签: magento magento-1.7


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      尝试使用

      Mage::getResourceModel('customer/address_collection')

      而不是

      Mage::getModel('客户/地址') ->getCollection()

      参见/app/code/core/Mage/Customer/Model/Customer.php

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

      【讨论】:

      • 感谢您的建议,但它不起作用:/ - 我可以在没有错误的情况下执行第一行,但是当我尝试添加 #2 或 3# 行时,我提到的错误再次发生。还有其他想法吗?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-02-25
      • 1970-01-01
      • 1970-01-01
      • 2013-08-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多