Get information about customer by email id in magento

﹥>﹥吖頭↗ 提交于 2019-12-23 14:57:01

问题


I want to get information of customer by email id, so i create a method in controller with content:

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?. please help me


回答1:


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.

Or, as your controller seems to be an admin one, Mage::app()->getWebsite()->getId() returns 0, which does not correspond.

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



来源:https://stackoverflow.com/questions/17149256/get-information-about-customer-by-email-id-in-magento

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!