4

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

public function showAction(){
    $customer_email = "[email protected]";
    $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

6
  • Do you run multiple websites ? If so, are customer accounts shared globally or by website ?
    – blmage
    Jun 17, 2013 at 13:57
  • Not run multiple websites
    – rocky
    Jun 17, 2013 at 14:05
  • Mage::app()->getWebsite()->getId() always return value 0
    – rocky
    Jun 17, 2013 at 14:05
  • Are you sure that a customer with this email address exists ? What does it give when you comment out the setWebsiteId() call ?
    – blmage
    Jun 17, 2013 at 14:14
  • 1
    @rocky: Did you try to fetch customer information through another email id ? As i can see there is no error in code except getFirstName() should be getFirstname(). Jun 17, 2013 at 14:16

1 Answer 1

10

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

1
  • Clearly answer. Thanks you so much
    – rocky
    Jun 17, 2013 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.