I have a custom attribute called rms_id. It's a unique account number that's associated with our customers in another database. I need a way to lookup the customer by this id, without hitting the database manually.
As of now, I can load the customer by email address like so:
$customer->loadByEmail($data['email']);
This is great, however the email is not always available. The RMS id is. Is there any way to load a user by the custom attribute?
In theory, the following would work:
$customer->loadByRmsId($data['account_id']);
However it errors out. Any help would be much appreciated.
but in practice you have to come up with your own method similar to loadByEmail()
in app/code/core/Mage/Customer/Model/Resource/Customer.php
or get the e-mail from collection
Mage::getModel('customer/customer')->getCollection()->addFieldToFilter('rms_id', 'youremailhere')->load();
There is a good example of this in the core; see Mage_Catalog_Model_Abstract::loadByAttribute()
[link]. It involves using a data model to retrieve a collection, joining the attribute in, and filtering by that attribute. This is necessary if the attribute is not static i.e. not a part of the entity table.
$result = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('rms_id')
->addAttributeToFilter('rms_id',{Val})->load();
if (is_object($result)) {
/* Logic */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With