I am looking to something similar to this one (thats works with email), But instead of get the customer by email, i want to get him by the Tax/VAT number.

$customer = Mage::getModel('customer/customer')->setWebsiteId($website->getWebsiteId())->loadByEmail($customerEmail);

I found this example but its doesn't work.

$customer = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*')->addFieldToFilter('taxvat',  $ss_5_last)->load();

Thank you.


Try using this approach

$result = Mage::getModel('customer/customer')

if (is_object($result)) {
    /* Logic */

Keep in mind vat_id is not unique and the code below can load multiple customers without ->getFirstItem().

  • Tried it, dosent work
    – BenB
    Jul 8 '15 at 22:33
  • Well, it does't work is quite broad. What are you trying and what are you getting? The answer was accepted a while ago, are you sure this is not braking somewhere else?
    – mbalparda
    Jul 8 '15 at 22:35
  • Get empty results if i do "var_dump" on the object
    – BenB
    Jul 8 '15 at 22:38
  • That does not actually count as "it doesn't work". Are you sure you have at least one customer matching your filter criteria? How about the var you are passing to the model? Are you sure it is correctly formatted or even filed?
    – mbalparda
    Jul 8 '15 at 22:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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