I need to retrieve the customer object belonging to a certain (mobile) phone number. How can I do this in Magento?
And how can I get a customer by phone number when a phone number was entered by end users and can be written in different ways?
For instance:
- +1 310-954-8012
- 1 (310) 954-8012
- 1-310-954-8012
- 13109548012
Best Answer
You can do this via the customer address collection as the phone number is part of a customer's address.
If the phone number given by
$phoneNumber
and the one in the customer's address literally match, you can simply do:If you need to filter out miscellaneous characters, you need to do this on both sides, input and SQL, so you could do: