Search This Blog

Tuesday, 22 January 2013

Save customer address programatically

                ### Save Address Info for the Customer ###
                $customerData = $this->getRequest()->getPost();
                $address = Mage::getModel("customer/address");
                if($customer->getDefaultBilling())
                {
                    $address->load($customer->getDefaultBilling()); // Updating the default billing address if customer already have
                }
                $address->setCustomerId($customer->getId());
                $address->setData($customerData);
                $address->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false)); // Make it as default billing address
                $address->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false)); // Make it as default shipping address
                $address->save();
                $customer->default_billing = $address->getId();  // Make it as default billing address
                $customer->default_shipping = $address->getId(); // Make it as default shipping address
                $customer->save();
                ### Save Address Info for the Customer ###

No comments:

Post a Comment