use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerAddressesController method viewCustomerAddress.
public String viewCustomerAddress(HttpServletRequest request, Model model, Long customerAddressId) {
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId);
if (customerAddress == null) {
throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId");
}
validateCustomerOwnedData(customerAddress);
CustomerAddressForm form = new CustomerAddressForm();
form.setAddress(customerAddress.getAddress());
form.setAddressName(customerAddress.getAddressName());
form.setCustomerAddressId(customerAddress.getId());
model.addAttribute("customerAddressForm", form);
return getCustomerAddressesView();
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerAddressesController method updateCustomerAddress.
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();
}
if ((form.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(form.getAddress().getPhonePrimary().getPhoneNumber()))) {
form.getAddress().setPhonePrimary(null);
}
if ((form.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(form.getAddress().getPhoneSecondary().getPhoneNumber()))) {
form.getAddress().setPhoneSecondary(null);
}
if ((form.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(form.getAddress().getPhoneFax().getPhoneNumber()))) {
form.getAddress().setPhoneFax(null);
}
CustomerAddress customerAddress = customerAddressService.readCustomerAddressById(customerAddressId);
if (customerAddress == null) {
throw new IllegalArgumentException("Customer Address not found with the specified customerAddressId");
}
validateCustomerOwnedData(customerAddress);
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();
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutFormServiceImpl method prePopulateShippingInfoForm.
@Override
public ShippingInfoForm prePopulateShippingInfoForm(ShippingInfoForm shippingInfoForm, Order cart) {
FulfillmentGroup firstShippableFulfillmentGroup = fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart);
if (firstShippableFulfillmentGroup != null) {
// if the cart has already has fulfillment information
if (firstShippableFulfillmentGroup.getAddress() != null) {
shippingInfoForm.setAddress(firstShippableFulfillmentGroup.getAddress());
} else {
// check for a default address for the customer
CustomerAddress defaultAddress = customerAddressService.findDefaultCustomerAddress(CustomerState.getCustomer().getId());
if (defaultAddress != null) {
shippingInfoForm.setAddress(defaultAddress.getAddress());
shippingInfoForm.setAddressName(defaultAddress.getAddressName());
}
}
FulfillmentOption fulfillmentOption = firstShippableFulfillmentGroup.getFulfillmentOption();
if (fulfillmentOption != null) {
shippingInfoForm.setFulfillmentOption(fulfillmentOption);
shippingInfoForm.setFulfillmentOptionId(fulfillmentOption.getId());
}
}
return shippingInfoForm;
}
use of org.broadleafcommerce.profile.core.domain.CustomerAddress in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutFormServiceImpl method determineIfSavedAddressIsSelected.
@Override
public void determineIfSavedAddressIsSelected(Model model, ShippingInfoForm shippingInfoForm, PaymentInfoForm paymentInfoForm) {
Customer customer = CustomerState.getCustomer();
boolean isSavedShippingAddress = false;
boolean isSavedBillingAddress = false;
for (CustomerAddress customerAddress : customer.getCustomerAddresses()) {
if (addressesContentsAreEqual(shippingInfoForm.getAddress(), customerAddress.getAddress())) {
isSavedShippingAddress = true;
break;
}
}
for (CustomerAddress customerAddress : customer.getCustomerAddresses()) {
if (addressesContentsAreEqual(paymentInfoForm.getAddress(), customerAddress.getAddress())) {
isSavedBillingAddress = true;
break;
}
}
model.addAttribute("isSavedShippingAddress", isSavedShippingAddress);
model.addAttribute("isSavedBillingAddress", isSavedBillingAddress);
}
Aggregations