按自定义字段过滤客户

发布于 2024-12-22 22:28:17 字数 85 浏览 8 评论 0原文

我使用magento 1.6.1

我只有客户的手机号码和姓名。我需要加载这些客户。

如何在 magento 中选择这些客户。

I using magento 1.6.1

I have only mobile number and name of the customers. I need to load those customers.

How it is possible to select those customers in magento.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

我纯我任性 2024-12-29 22:28:17

下面的代码帮助我过滤客户。

$customers  = Mage::getResourceModel('customer/customer_collection')
                 ->addAttributeToSelect('*')
                 ->addAttributeToFilter('firstname', $firstName)

The below code helps me to filter the customers.

$customers  = Mage::getResourceModel('customer/customer_collection')
                 ->addAttributeToSelect('*')
                 ->addAttributeToFilter('firstname', $firstName)
回眸一遍 2024-12-29 22:28:17

$customers = Mage::getResourceModel('customer/customer_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('firstname', $firstName)

上面的代码只会加载集合。

要按名字获取客户详细信息,我们需要循环访问客户集合对象,然后获取客户 ID。最后只需加载单个客户对象

$model = Mage::getSingleton('customer/customer');

$customerCollection = $model->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('firstname', array('like' => $variableFirstName));

foreach($customerCollection as $customerObject) 
{       
    $customer = $model->load($customerObject->getId());
    echo '<b>'.$customer->getFirstname() . $customer->getLastname().'</b><br/>';
}

,如下所示如果我们想按姓氏过滤,只需更改为

->addAttributeToFilter('lastname', array('like' => $variableLastName))

$customers = Mage::getResourceModel('customer/customer_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('firstname', $firstName)

The above code will only load the collection.

To get customer details by firstname, we need to loop through customer collection object and then get customer id. Finally just load the individual customer object as below

$model = Mage::getSingleton('customer/customer');

$customerCollection = $model->getCollection()
    ->addAttributeToSelect('*')
    ->addAttributeToFilter('firstname', array('like' => $variableFirstName));

foreach($customerCollection as $customerObject) 
{       
    $customer = $model->load($customerObject->getId());
    echo '<b>'.$customer->getFirstname() . $customer->getLastname().'</b><br/>';
}

In case, if we want to filter by lastname, just change to

->addAttributeToFilter('lastname', array('like' => $variableLastName))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文