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.

1 Answer 1

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');
1
  • Ahhh, right. I didn't think to look at the actual database field (long day I guess). Many thanks Marius.
    – webnoob
    Commented Aug 7, 2013 at 14:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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