cancel
Showing results for 
Search instead for 
Did you mean: 

How to load a single customer record from a custom attribute

How to load a single customer record from a custom attribute

HI all,

 

is it possible to load a single customer record from a custom attribute without loading the entire customer collection and looping through?

Our customers have a ERP ID attribute (erp_id)

I'd like to be able to simply pass the erp_id and the $value into a customer model object and load that single customer?

 

$erp_id is a unique value

the code is for a CLI script, so there is no customer session info available.

 

I can get my stuff to work if I load the collection and loop, but that doesn't seem optimal?

any help / guidance would be appreciated Smiley Happy

cheers

 

1 REPLY 1

Re: How to load a single customer record from a custom attribute

Yes this is quite a simple procedure

 

You will need to have your Magento customer id, I would recommend writing this to your ERP as the key between the two

 

$customer_id = 1; // set this to the ID of the customer.
$customer_data = Mage::getModel('customer/customer')->load($customer_id);

Now you have a single customer loaded and you can do anything you want with them!

Magento Moderator since 2009
Keep Calm and Clear Cache!