问题
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