简体   繁体   English

通过magento中的电子邮件ID获取有关客户的信息

[英]Get information about customer by email id in magento

I want to get information of customer by email id, so i create a method in controller with content: 我希望通过电子邮件ID获取客户信息,因此我在控制器中创建了一个包含内容的方法:

public function showAction(){
    $customer_email = "abc@mail.com";
    $customer = Mage::getModel("customer/customer");
    $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
    $customer->loadByEmail($customer_email);
    echo $customer->getId();
    echo $customer->getFirstName();
    echo $customer->getEmail(); 
}

but when run it return null value, i don't know why?. 但是当它运行时它返回null值,我不知道为什么? please help me 请帮我

In your system configuration, customer accounts are shared by website, so the loadByEmail method needs to be used on a customer model that has a value for website_id , and this website ID must correspond to the website to which the customer is associated. 在您的系统配置中,客户帐户由网站共享,因此需要在具有website_id值的客户模型上使用loadByEmail方法,并且此网站ID必须与客户关联的网站相对应。

Or, as your controller seems to be an admin one, Mage::app()->getWebsite()->getId() returns 0, which does not correspond. 或者,由于您的控制器似乎是管理员, Mage::app()->getWebsite()->getId()返回0,这是不对应的。

So, your solution is either to share customer accounts globally ( System > Configuration > Customers > Customer Configuration > Account Sharing Options ), as it won't change much things if you only run a single website, either to use a website ID that has to be specified by an user, or at least not retrieved by Mage::app()->getWebsite()->getId() . 因此,您的解决方案是要全局共享客户帐户( 系统 > 配置 > 客户 > 客户配置 > 帐户共享选项 ),因为如果您只运行一个网站,要么使用具有的网站ID,它不会改变很多事情由用户指定,或者至少不是由Mage::app()->getWebsite()->getId()检索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM