1

How can I set address as default billing address when a radio button is added in customer address book without going to edit address page. Please find the below screenshot,

https://prnt.sc/ihngmf

Thanks

1 Answer 1

1

If you open app/code/core/Mage/Customer/controllers/AddressController.php You can see following code


$address->setCustomerId($customer->getId())
    ->setIsDefaultBilling($this->getRequest()->getParam('default_billing', false))
    ->setIsDefaultShipping($this->getRequest()->getParam('default_shipping', false));

So in your case


$address->setCustomerId($customer->getId())
    ->setIsDefaultBilling($addressId)
    ->setIsDefaultShipping($addressId);
$address->save();

[Update]

Pass id as address_id and your controller code should be following:


$customer = Mage::getSingleton('customer/session')->getCustomer();
/* @var $address Mage_Customer_Model_Address */
$address  = Mage::getModel('customer/address');
$addressId = $this->getRequest()->getParam('id');
if ($addressId) {
    $existsAddress = $customer->getAddressById($addressId);
    if ($existsAddress->getId() && $existsAddress->getCustomerId() == $customer->getId()) {
        $address = $existsAddress;
    }
}

if(!$address->getId()) {
    return;
}

$address->setCustomerId($customer->getId())
    ->setIsDefaultBilling($addressId)
    ->setIsDefaultShipping($addressId);
$address->save();
8
  • thanks @sohel in the code how can i check radio button?
    – Raghu
    Feb 21, 2018 at 5:42
  • You can use by ajax for save them and for checked radio button use simple if-else logic like if($customer->->getDefaultBilling() == $addressId) { checked}.
    – Sohel Rana
    Feb 21, 2018 at 5:46
  • so it should be like---- new Ajax.Request('<?php echo $this->getUrl("customer/address/formpost")?>', {------
    – Raghu
    Feb 21, 2018 at 5:49
  • formpost action require more field-value combination. If you pass all of them then yes. or create your own.
    – Sohel Rana
    Feb 21, 2018 at 5:52
  • i have created another controller and little bit confused how to set exactly
    – Raghu
    Feb 21, 2018 at 6:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.