0

I am going to add some addresses in my customer account via CSV but at that time I want to check any of the addresses i.e. in CSV is exist in my address book? I Know, I need to compare whole row, Is there any way rather than custom query? Please Suggest.

2

Assuming you have separate columns in sheet for street address, state/region and country etc, you can use below code to compare address of customer.

$customer = Mage::getModel('customer/customer')->load($customerId);

foreach ($customer->getAddresses() as $address) {    
    $addressDetails = $address->getData();
    $name = $address->getFirstname().' '.$address->getLastname();
    $company = $address->getCompany();
    $postCode = $address->getPostcode();
    $city = $address->getCity();
    $street = $address->getStreet();
    $streetAddress = $street[0]." ".$street[1] ;
    $telephone = $address->getTelephone();
    $fax = $address->getFax();
    $country = Mage::getModel('directory/country')->loadByCode($address->getCountry());
    $countryName= $country->getName();

    /*

    Now here you can check csv column data of respective values with above variables
    and check if same address exists or not

    */
}
1
  • It would be cleaner to have two arrays, and do a array_diff – Fran Mayers Jul 7 '17 at 13:47

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.