Domanda

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.

È stato utile?

Soluzione

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

    */
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top