1

I can load an address using the following code:

$addresses = $addressObj->getCollection()
        ->addAttributeToSelect('*')
        ->addAttributeToFilter('firstname', $addressData['firstname'])
        ->addAttributeToFilter('lastname', $addressData['lastname'])
        ->addAttributeToFilter('city', $addressData['city'])
        ->addAttributeToFilter('postcode', $addressData['postcode'])
        ->addAttributeToFilter('telephone', $addressData['telephone'])
        ->load();

The issue is that street is an array when returned in the address object so how can I add street into my filters above?

I know I could load all the addresses and loop through them in code then compare the array with my data but I would like to avoid this step if possible a it's extra overhead.

2

This should work:

->addAttributeToFilter('street', 'somewhere');

or this, if you want like filter

->addAttributeToFilter('street', array('like'=>'%somewhere%'));

Even if the street is returned as an array, in the database is kept as a single field. The values in the array are concatenated by \n.
If you are looking for an exact address that is on 2 lines this should do it:

->addAttributeToFilter('street', 'somewhere\nelse');
  • Ahhh, right. I didn't think to look at the actual database field (long day I guess). Many thanks Marius. – webnoob Aug 7 '13 at 14:30

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.