Question

Consider the following code

$customer_email = "customer@example.com";
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($customer_email);

When looking through Mage_Customer_Model_Customer I could not find a loadByEmail method anywhere in it's inheritance chain. Then I looked at it's resource model, Mage_Customer_Model_Resource_Customer, and there it was.

My question is: how is it possible, that I load the model itself and get access to this method through the $customer_email variable?

Was it helpful?

Solution

I think you missed something. The method loadByEmail exists in the Mage_Customer_Model_Customer class: For Magento 1.7.0.2 it starts at line 180 and looks like this:

public function loadByEmail($customerEmail)
{
    $this->_getResource()->loadByEmail($this, $customerEmail);
    return $this;
}

It's just a wrapper for Mage_Customer_Model_Resource_Customer::loadByEmail but it exists.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top