Thursday, April 26, 2012

Adding address programmatically in magento

$addressData =  array (
                    [prefix] => test
                    [firstname] => test
                    [middlename] => test
                    [lastname] => test
                    [suffix] => tes
                    [company] => test
                    [street] => 34
24
                    [city] => 234
                    [country_id] => US
                    [region] => Alabama
                    [region_id] => 1
                    [postcode] => 234
                    [telephone] => 234
                    [fax] => 234
                    [is_default_billing] => 1
                    [is_default_shipping] => 
                );
 
 $customer = Mage::getModel('customer/customer');
 $customer->loadByEmail('test@test.com');
 $address   = Mage::getModel('customer/address');
 $address->addData($addressData);
 $customer->addAddress($address);
 
 $customer->save();