use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafBillingInfoController method saveBillingAddress.
/**
* Processes the request to save a billing address.
*
* Note: this default Broadleaf implementation will create an OrderPayment of
* type CREDIT_CARD if it doesn't exist and save the passed in billing address
*
* @param request
* @param response
* @param model
* @param billingForm
* @return the return path
* @throws org.broadleafcommerce.common.exception.ServiceException
*/
public String saveBillingAddress(HttpServletRequest request, HttpServletResponse response, Model model, BillingInfoForm billingForm, BindingResult result) throws PricingException, ServiceException {
Order cart = CartState.getCart();
CustomerPayment customerPayment = null;
if (billingForm.isUseShippingAddress()) {
copyShippingAddressToBillingAddress(cart, billingForm);
}
Boolean useCustomerPayment = billingForm.getUseCustomerPayment();
if (useCustomerPayment && billingForm.getCustomerPaymentId() != null) {
customerPayment = customerPaymentService.readCustomerPaymentById(billingForm.getCustomerPaymentId());
if (customerPayment != null) {
Address address = customerPayment.getBillingAddress();
if (address != null) {
billingForm.setAddress(addressService.copyAddress(address));
}
}
}
addressService.populateAddressISOCountrySub(billingForm.getAddress());
billingInfoFormValidator.validate(billingForm, result);
if (result.hasErrors()) {
return getCheckoutView();
}
if ((billingForm.getAddress().getPhonePrimary() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhonePrimary().getPhoneNumber()))) {
billingForm.getAddress().setPhonePrimary(null);
}
if ((billingForm.getAddress().getPhoneSecondary() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhoneSecondary().getPhoneNumber()))) {
billingForm.getAddress().setPhoneSecondary(null);
}
if ((billingForm.getAddress().getPhoneFax() != null) && (StringUtils.isEmpty(billingForm.getAddress().getPhoneFax().getPhoneNumber()))) {
billingForm.getAddress().setPhoneFax(null);
}
boolean found = false;
String paymentName = billingForm.getPaymentName();
Boolean saveNewPayment = billingForm.getSaveNewPayment();
for (OrderPayment p : cart.getPayments()) {
if (PaymentType.CREDIT_CARD.equals(p.getType()) && p.isActive()) {
if (p.getBillingAddress() == null) {
p.setBillingAddress(billingForm.getAddress());
} else {
Address updatedAddress = addressService.copyAddress(p.getBillingAddress(), billingForm.getAddress());
p.setBillingAddress(updatedAddress);
}
found = true;
}
}
if (!found) {
// A Temporary Order Payment will be created to hold the billing address.
// The Payment Gateway will send back any validated address and
// the PaymentGatewayCheckoutService will persist a new payment of type CREDIT_CARD when it applies it to the Order
OrderPayment tempOrderPayment = orderPaymentService.create();
tempOrderPayment.setType(PaymentType.CREDIT_CARD);
tempOrderPayment.setPaymentGatewayType(PaymentGatewayType.TEMPORARY);
tempOrderPayment.setBillingAddress(billingForm.getAddress());
tempOrderPayment.setOrder(cart);
cart.getPayments().add(tempOrderPayment);
}
orderService.save(cart, true);
if (isAjaxRequest(request)) {
// Add module specific model variables
checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
return getCheckoutView();
} else {
return getCheckoutPageRedirect();
}
}
use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafManageCustomerAddressesController method addCustomerAddress.
public String addCustomerAddress(HttpServletRequest request, Model model, CustomerAddressForm form, BindingResult result, RedirectAttributes redirectAttributes) throws ServiceException {
addressService.populateAddressISOCountrySub(form.getAddress());
customerAddressValidator.validate(form, result);
if (result.hasErrors()) {
return getCustomerAddressesView();
}
removeUnusedPhones(form);
Address address = addressService.saveAddress(form.getAddress());
CustomerAddress customerAddress = customerAddressService.create();
customerAddress.setAddress(address);
customerAddress.setAddressName(form.getAddressName());
customerAddress.setCustomer(CustomerState.getCustomer());
customerAddress = customerAddressService.saveCustomerAddress(customerAddress);
if (form.getAddress().isDefault()) {
customerAddressService.makeCustomerAddressDefault(customerAddress.getId(), customerAddress.getCustomer().getId());
}
form.setCustomerAddressId(customerAddress.getId());
if (!isAjaxRequest(request)) {
List<CustomerAddress> addresses = customerAddressService.readActiveCustomerAddressesByCustomerId(CustomerState.getCustomer().getId());
model.addAttribute("addresses", addresses);
}
redirectAttributes.addFlashAttribute("successMessage", getAddressAddedMessage());
return getCustomerAddressesRedirect();
}
use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafPaymentInfoController method copyShippingAddressToBillingAddress.
/**
* This method will copy the shipping address of the first fulfillment group on the order
* to the billing address on the PaymentInfoForm that is passed in.
*/
protected void copyShippingAddressToBillingAddress(Order order, PaymentInfoForm paymentInfoForm) {
if (order.getFulfillmentGroups().get(0) != null) {
Address shipping = order.getFulfillmentGroups().get(0).getAddress();
if (shipping != null) {
Address billing = addressService.copyAddress(shipping);
paymentInfoForm.setAddress(billing);
}
}
}
use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.
the class BroadleafShippingInfoController method removeUnusedPhones.
public void removeUnusedPhones(ShippingInfoForm form) {
Address address = form.getAddress();
Phone primaryPhone = address.getPhonePrimary();
Phone secondaryPhone = address.getPhoneSecondary();
Phone faxPhone = address.getPhoneFax();
if ((primaryPhone != null) && (StringUtils.isEmpty(primaryPhone.getPhoneNumber()))) {
address.setPhonePrimary(null);
}
if ((secondaryPhone != null) && (StringUtils.isEmpty(secondaryPhone.getPhoneNumber()))) {
address.setPhoneSecondary(null);
}
if ((faxPhone != null) && (StringUtils.isEmpty(faxPhone.getPhoneNumber()))) {
address.setPhoneFax(null);
}
}
use of org.broadleafcommerce.profile.core.domain.Address in project BroadleafCommerce by BroadleafCommerce.
the class BandedShippingModule method calculateShipping.
private void calculateShipping(FulfillmentGroup fulfillmentGroup) {
if (!isValidModuleForService(fulfillmentGroup.getService()) && !isDefaultModule()) {
LOG.info("fulfillment group (" + fulfillmentGroup.getId() + ") with a service type of (" + fulfillmentGroup.getService() + ") is not valid for this module service type (" + getServiceName() + ")");
return;
}
if (fulfillmentGroup.getFulfillmentGroupItems().size() == 0) {
LOG.warn("fulfillment group (" + fulfillmentGroup.getId() + ") does not contain any fulfillment group items. Unable to price banded shipping");
fulfillmentGroup.setShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
fulfillmentGroup.setSaleShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
fulfillmentGroup.setRetailShippingPrice(BroadleafCurrencyUtils.getMoney(BigDecimal.ZERO, fulfillmentGroup.getOrder().getCurrency()));
return;
}
Address address = fulfillmentGroup.getAddress();
String state = null;
if (StringUtils.isNotBlank(address.getStateProvinceRegion())) {
state = address.getStateProvinceRegion();
} else if (address.getState() != null) {
state = address.getState().getAbbreviation();
}
BigDecimal retailTotal = new BigDecimal(0);
String feeType = feeTypeMapping.get(fulfillmentGroup.getMethod());
String feeSubType = ((feeSubTypeMapping.get(state) == null) ? feeSubTypeMapping.get("ALL") : feeSubTypeMapping.get(state));
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
BigDecimal price = (fulfillmentGroupItem.getRetailPrice() != null) ? fulfillmentGroupItem.getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity())) : null;
if (price == null) {
price = fulfillmentGroupItem.getOrderItem().getRetailPrice().getAmount().multiply(BigDecimal.valueOf(fulfillmentGroupItem.getQuantity()));
}
retailTotal = retailTotal.add(price);
}
ShippingRate sr = shippingRateService.readShippingRateByFeeTypesUnityQty(feeType, feeSubType, retailTotal);
if (sr == null) {
throw new NotImplementedException("Shipping rate " + fulfillmentGroup.getMethod() + " not supported");
}
BigDecimal shippingPrice = new BigDecimal(0);
if (sr.getBandResultPercent().compareTo(0) > 0) {
BigDecimal percent = new BigDecimal(sr.getBandResultPercent() / 100);
shippingPrice = retailTotal.multiply(percent);
} else {
shippingPrice = sr.getBandResultQuantity();
}
fulfillmentGroup.setShippingPrice(BroadleafCurrencyUtils.getMoney(shippingPrice, fulfillmentGroup.getOrder().getCurrency()));
fulfillmentGroup.setSaleShippingPrice(fulfillmentGroup.getShippingPrice());
fulfillmentGroup.setRetailShippingPrice(fulfillmentGroup.getSaleShippingPrice());
}
Aggregations