Page 1 of 1

Error when updating customer address from site

Posted: Fri Jan 04, 2013 4:08 am
by denis
Hi,

On demo site (BLC 2.1.1-SNAPSHOT) when you update an Address, instead of updating the Address row in database a new Address row is created and the CustomerAddress is updated whith the new Address id.

Is it normal ?

On BroadleafManageCustomerAddressesController you have :

Code: Select all

 public String updateCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId, CustomerAddressForm form, BindingResult result, RedirectAttributes redirectAttributes) throws ServiceException {
       customerAddressValidator.validate(form, result);
       if (result.hasErrors()) {
          return getCustomerAddressesView();
       }
       CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId);
       if (customerAddress == null) {
          throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId");
       }
        //HERE, you should retrieve the current address id
       customerAddress.setAddress(form.getAddress());
       customerAddress.setAddressName(form.getAddressName());
       customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
       if (form.getAddress().isDefault()) {
          customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customerAddress.getCustomer().getId());
       }
       redirectAttributes.addFlashAttribute("successMessage", getAddressUpdatedMessage());
       return getCustomerAddressesRedirect();
    }


The Address id is always null so a new instance of Address is created.

Re: Error when updating customer address from site

Posted: Mon Jan 07, 2013 11:06 am
by phillipuniverse
No, this is intentional. The reason is that if an Order has already shipped, it will reference that old address. If you update the address in-place without creating a new one, you will lose historical data and not be able to retrieve where that previous Order actually went. I would strongly advise against changing this behavior.

Re: Error when updating customer address from site

Posted: Mon Jan 07, 2013 2:25 pm
by denis
I understand, thank you phillipuniverse. But in the admin, when you update a customer address, the address is only updated. There is no new address created like in site.