Search in sources :

Example 16 with CustomerAddress

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();
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 17 with CustomerAddress

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();
}
Also used : CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 18 with CustomerAddress

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;
}
Also used : FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Example 19 with CustomerAddress

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);
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerAddress(org.broadleafcommerce.profile.core.domain.CustomerAddress)

Aggregations

CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)19 Customer (org.broadleafcommerce.profile.core.domain.Customer)8 Address (org.broadleafcommerce.profile.core.domain.Address)7 Transactional (org.springframework.transaction.annotation.Transactional)5 CustomerAddressImpl (org.broadleafcommerce.profile.core.domain.CustomerAddressImpl)4 Test (org.testng.annotations.Test)4 Order (org.broadleafcommerce.core.order.domain.Order)3 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)3 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)2 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)2 Query (javax.persistence.Query)1 TypedQuery (javax.persistence.TypedQuery)1 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 CriteriaQuery (javax.persistence.criteria.CriteriaQuery)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 Status (org.broadleafcommerce.common.persistence.Status)1 OrderPayment (org.broadleafcommerce.core.payment.domain.OrderPayment)1 Entity (org.broadleafcommerce.openadmin.dto.Entity)1 DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)1