Search in sources :

Example 46 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafUpdateAccountController method viewUpdateAccount.

public String viewUpdateAccount(HttpServletRequest request, Model model, UpdateAccountForm form) {
    Customer customer = CustomerState.getCustomer();
    form.setEmailAddress(customer.getEmailAddress());
    form.setFirstName(customer.getFirstName());
    form.setLastName(customer.getLastName());
    return getUpdateAccountView();
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 47 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafOrderConfirmationController method displayOrderConfirmationByOrderId.

public String displayOrderConfirmationByOrderId(Long orderId, Model model, HttpServletRequest request, HttpServletResponse response) {
    Customer customer = CustomerState.getCustomer();
    if (customer != null) {
        Order order = orderService.findOrderById(orderId);
        if (order != null && customer.equals(order.getCustomer())) {
            extensionManager.getProxy().processAdditionalConfirmationActions(order);
            model.addAttribute("order", order);
            return getOrderConfirmationView();
        }
    }
    return "redirect:/";
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 48 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafOrderConfirmationController method displayOrderConfirmationByOrderNumber.

public String displayOrderConfirmationByOrderNumber(String orderNumber, Model model, HttpServletRequest request, HttpServletResponse response) {
    Customer customer = CustomerState.getCustomer();
    if (customer != null) {
        Order order = orderService.findOrderByOrderNumber(orderNumber);
        if (order != null && customer.equals(order.getCustomer())) {
            extensionManager.getProxy().processAdditionalConfirmationActions(order);
            model.addAttribute("order", order);
            return getOrderConfirmationView();
        }
    }
    return "redirect:/";
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer)

Example 49 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafPaymentInfoController method savePaymentInfo.

/**
 * Processes the request to save an {@link OrderPayment} based on an existing or new {@link CustomerPayment}.
 *
 * Note: this default Broadleaf implementation will create a CustomerPayment if one does not exist,
 *  and copy it's data to a new OrderPayment.
 *
 * @param request
 * @param response
 * @param model
 * @param paymentForm
 * @return the return path
 * @throws ServiceException
 */
public String savePaymentInfo(HttpServletRequest request, HttpServletResponse response, Model model, PaymentInfoForm paymentForm, BindingResult result) throws PricingException, ServiceException {
    Order cart = CartState.getCart();
    Customer customer = CustomerState.getCustomer();
    preProcessBillingAddress(paymentForm, cart);
    paymentInfoFormValidator.validate(paymentForm, result);
    if (!result.hasErrors()) {
        if (paymentForm.getShouldSaveNewPayment() && !paymentForm.getShouldUseCustomerPayment()) {
            if (paymentForm.getCustomerPaymentId() != null) {
                savedPaymentService.updateSavedPayment(customer, paymentForm);
            } else if (paymentForm.getCustomerPaymentId() == null) {
                Long customerPaymentId = savedPaymentService.addSavedPayment(customer, paymentForm);
                paymentForm.setCustomerPaymentId(customerPaymentId);
                paymentForm.setShouldUseCustomerPayment(true);
            }
        }
        if (paymentForm.getShouldUseCustomerPayment()) {
            CustomerPayment customerPayment = customerPaymentService.readCustomerPaymentById(paymentForm.getCustomerPaymentId());
            if (!cartStateService.cartHasCreditCardPaymentWithSameToken(customerPayment.getPaymentToken())) {
                orderService.removePaymentsFromOrder(cart, PaymentType.CREDIT_CARD);
                orderPaymentService.createOrderPaymentFromCustomerPayment(cart, customerPayment, cart.getTotalAfterAppliedPayments());
            }
        }
    }
    if (isAjaxRequest(request)) {
        // Add module specific model variables
        checkoutControllerExtensionManager.getProxy().addAdditionalModelVariables(model);
        return getCheckoutView();
    } else {
        return getCheckoutPageRedirect();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) CustomerPayment(org.broadleafcommerce.profile.core.domain.CustomerPayment)

Example 50 with Customer

use of org.broadleafcommerce.profile.core.domain.Customer in project BroadleafCommerce by BroadleafCommerce.

the class UpdateAccountValidator method validate.

public void validate(UpdateAccountForm form, Errors errors) {
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "emailAddress", "emailAddress.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "firstName", "firstName.required");
    ValidationUtils.rejectIfEmptyOrWhitespace(errors, "lastName", "lastName.required");
    if (!errors.hasErrors()) {
        // is this a valid email address?
        if (!GenericValidator.isEmail(form.getEmailAddress())) {
            errors.rejectValue("emailAddress", "emailAddress.invalid");
        }
        // check email address to see if it is already in use by another customer
        Customer customerMatchingNewEmail = customerService.readCustomerByEmail(form.getEmailAddress());
        if (customerMatchingNewEmail != null && !CustomerState.getCustomer().getId().equals(customerMatchingNewEmail.getId())) {
            // customer found with new email entered, and it is not the current customer
            errors.rejectValue("emailAddress", "emailAddress.used");
        }
    }
}
Also used : Customer(org.broadleafcommerce.profile.core.domain.Customer)

Aggregations

Customer (org.broadleafcommerce.profile.core.domain.Customer)98 Order (org.broadleafcommerce.core.order.domain.Order)41 Transactional (org.springframework.transaction.annotation.Transactional)34 Test (org.testng.annotations.Test)33 Address (org.broadleafcommerce.profile.core.domain.Address)14 Rollback (org.springframework.test.annotation.Rollback)11 HashMap (java.util.HashMap)9 CustomerAddress (org.broadleafcommerce.profile.core.domain.CustomerAddress)9 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)8 MergeCartResponse (org.broadleafcommerce.core.order.service.call.MergeCartResponse)6 ArrayList (java.util.ArrayList)5 Money (org.broadleafcommerce.common.money.Money)5 Category (org.broadleafcommerce.core.catalog.domain.Category)5 Product (org.broadleafcommerce.core.catalog.domain.Product)5 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)5 CommonSetupBaseTest (org.broadleafcommerce.test.CommonSetupBaseTest)5 CustomerImpl (org.broadleafcommerce.profile.core.domain.CustomerImpl)4 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)3 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)3