magento update customer address programmatically

magento update customer address programmatically

In this post we will show you magento update customer address programmatically, hear for magento update customer address programmatically

.

we will give you code for implement magento update customer address programmatically. we will show you how to update/change customer or user address programmatically. hear we pass customer or user detail like First name, last name, company, postcode and other information. we will show you how to change customer first name, customer middle name, customer last name, customer prefix, customer suffix, customer company, customer street, customer country_id , customer city, customer region_id, customer region, customer postcode , customer country_id, telephone, customer fax


//add your customer id
$customer_id = 017;

$customer_data = array(
'firstname' => 'AddFirstname',
'middlename' => 'Addmiddlename',
'lastname' => 'Addlastname',
'prefix' => 'Addprefix',
'suffix' => 'Addsuffix',
'company' => 'Addcompany',
'street' => 'Addstreet',
'country_id' => 'Addcountry',
'city' => 'Addcity',
'region_id' => 'region_id',
'region' => 'Addregion',
'postcode' => 'Addpostal',
'country_id' => 'Addcountry',
'telephone' => 'Addtelephone',
'fax' => 'fax'
);

// customer data and Build billing address
$customer_shipping_data = array(
'firstname' => $customer_data['firstname'],
'middlename' => $customer_data['middlename'],
'lastname' => $customer_data['lastname'],
'prefix' => $customer_data['prefix'],
'suffix' => $customer_data['suffix'],
'company' => $customer_data['company'],
'street' => $customer_data['street'],
'country_id' => $customer_data['country'],
'city' => $customer_data['city'],
'region_id' => $customer_data['region_id'],
'region' => $customer_data['region'],
'postcode' => $customer_data['postal'],
'country_id' => $customer_data['country'],
'telephone' => $customer_data['telephone'],
'fax' => $customer_data['fax'],
);

$customer_address = Mage::getModel('customer/address');

if ($default_shipping_id = $customer->getDefaultShipping()){
$customer_address->load($default_shipping_id);
} else {
$customer_address
->setCustomerId($customer_id)
->setIsDefaultBilling('0')
->setIsDefaultShipping('1')
->setSaveInAddressBook('1');
}

try {
$customer_address->setData($customer_shipping_data);
$customer_address->save();
}
catch (Exception $exception)
{
Mage::log('Customer Address Save Error::' . $exception->getMessage());
}




Hope this code and post will helped you for implement magento update customer address programmatically. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve onlincode. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs onlincode.org

Leave a Comment

Your email address will not be published. Required fields are marked *

  +  15  =  19

We accept paid advance and paid guest Posting on our Site : Contact US