Search in sources :

Example 1 with NullOrderImpl

use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class DefaultPaymentGatewayCheckoutService method initiateCheckout.

@Override
public String initiateCheckout(Long orderId) throws Exception {
    Order order = orderService.findOrderById(orderId, true);
    if (order == null || order instanceof NullOrderImpl) {
        throw new IllegalArgumentException("Could not order with id " + orderId);
    }
    CheckoutResponse response;
    try {
        response = checkoutService.performCheckout(order);
    } catch (CheckoutException e) {
        throw new Exception(e);
    }
    if (response.getOrder().getOrderNumber() == null) {
        LOG.error("Order Number for Order ID: " + order.getId() + " is null.");
    }
    return response.getOrder().getOrderNumber();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) CheckoutResponse(org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) CheckoutException(org.broadleafcommerce.core.checkout.service.exception.CheckoutException) CheckoutException(org.broadleafcommerce.core.checkout.service.exception.CheckoutException)

Example 2 with NullOrderImpl

use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafRegisterController method processRegister.

public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
    if (useEmailForLogin) {
        Customer customer = registerCustomerForm.getCustomer();
        customer.setUsername(customer.getEmailAddress());
    }
    registerCustomerValidator.validate(registerCustomerForm, errors, useEmailForLogin);
    if (!errors.hasErrors()) {
        Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
        assert (newCustomer != null);
        // The next line needs to use the customer from the input form and not the customer returned after registration
        // so that we still have the unencoded password for use by the authentication mechanism.
        loginService.loginCustomer(registerCustomerForm.getCustomer());
        // Need to ensure that the Cart on CartState is owned by the newly registered customer.
        Order cart = CartState.getCart();
        if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
            cart.setEmailAddress(newCustomer.getEmailAddress());
            orderService.save(cart, false);
        }
        String redirectUrl = registerCustomerForm.getRedirectUrl();
        if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
            redirectUrl = null;
        }
        return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
    } else {
        return getRegisterView();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Example 3 with NullOrderImpl

use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafCartController method addPromo.

/**
 * Attempts to add provided Offer to Cart
 *
 * @param request
 * @param response
 * @param model
 * @param customerOffer
 * @return the return view
 * @throws IOException
 * @throws PricingException
 * @throws OfferMaxUseExceededException
 */
public String addPromo(HttpServletRequest request, HttpServletResponse response, Model model, String customerOffer) throws IOException, PricingException {
    Order cart = CartState.getCart();
    Boolean promoAdded = false;
    String exception = "";
    if (cart != null && !(cart instanceof NullOrderImpl)) {
        List<OfferCode> offerCodes = offerService.lookupAllOfferCodesByCode(customerOffer);
        if (CollectionUtils.isNotEmpty(offerCodes)) {
            for (OfferCode offerCode : offerCodes) {
                if (offerCode != null) {
                    try {
                        orderService.addOfferCode(cart, offerCode, false);
                        promoAdded = true;
                    } catch (OfferException e) {
                        if (e instanceof OfferMaxUseExceededException) {
                            exception = "Use Limit Exceeded";
                        } else if (e instanceof OfferExpiredException) {
                            exception = "Offer Has Expired";
                        } else if (e instanceof OfferAlreadyAddedException) {
                            exception = "Offer Has Already Been Added";
                        } else {
                            exception = "An Unknown Offer Error Has Occurred";
                        }
                    }
                } else {
                    exception = "Invalid Code";
                }
            }
            cart = orderService.save(cart, true);
        } else {
            exception = "Unknown Code";
        }
    } else {
        exception = "Invalid Cart";
    }
    if (isAjaxRequest(request)) {
        Map<String, Object> extraData = new HashMap<>();
        extraData.put("promoAdded", promoAdded);
        extraData.put("exception", exception);
        model.addAttribute("blcextradata", new ObjectMapper().writeValueAsString(extraData));
    } else {
        model.addAttribute("exception", exception);
    }
    return isCheckoutContext(request) ? getCheckoutView() : getCartView();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) HashMap(java.util.HashMap) OfferException(org.broadleafcommerce.core.offer.service.exception.OfferException) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) OfferMaxUseExceededException(org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException) OfferCode(org.broadleafcommerce.core.offer.domain.OfferCode) OfferExpiredException(org.broadleafcommerce.core.offer.service.exception.OfferExpiredException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OfferAlreadyAddedException(org.broadleafcommerce.core.offer.service.exception.OfferAlreadyAddedException)

Example 4 with NullOrderImpl

use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class OnePageCheckoutProcessor method populateFulfillmentOptionsAndEstimationOnModel.

/**
 * A helper method to retrieve all fulfillment options for the cart and estimate the cost of applying
 * fulfillment options on the first shippable fulfillment group.
 */
protected void populateFulfillmentOptionsAndEstimationOnModel(Map<String, Object> localVars) {
    List<FulfillmentOption> fulfillmentOptions = fulfillmentOptionService.readAllFulfillmentOptions();
    Order cart = CartState.getCart();
    if (!(cart instanceof NullOrderImpl) && cart.getFulfillmentGroups().size() > 0 && hasPopulatedShippingAddress(cart)) {
        Set<FulfillmentOption> options = new HashSet<>();
        options.addAll(fulfillmentOptions);
        FulfillmentEstimationResponse estimateResponse = null;
        try {
            estimateResponse = fulfillmentPricingService.estimateCostForFulfillmentGroup(fulfillmentGroupService.getFirstShippableFulfillmentGroup(cart), options);
        } catch (FulfillmentPriceException e) {
        }
        localVars.put("estimateResponse", estimateResponse);
    }
    localVars.put("fulfillmentOptions", fulfillmentOptions);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) FulfillmentPriceException(org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException) FulfillmentEstimationResponse(org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse) FulfillmentOption(org.broadleafcommerce.core.order.domain.FulfillmentOption) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl) HashSet(java.util.HashSet)

Example 5 with NullOrderImpl

use of org.broadleafcommerce.core.order.domain.NullOrderImpl in project BroadleafCommerce by BroadleafCommerce.

the class BroadleafSocialRegisterController method processRegister.

// Calls ProviderSignInUtils.handlePostSignUp() after a successful registration
public String processRegister(RegisterCustomerForm registerCustomerForm, BindingResult errors, HttpServletRequest request, HttpServletResponse response, Model model) throws ServiceException, PricingException {
    if (isUseEmailForLogin()) {
        Customer customer = registerCustomerForm.getCustomer();
        customer.setUsername(customer.getEmailAddress());
    }
    registerCustomerValidator.validate(registerCustomerForm, errors, isUseEmailForLogin());
    if (!errors.hasErrors()) {
        Customer newCustomer = customerService.registerCustomer(registerCustomerForm.getCustomer(), registerCustomerForm.getPassword(), registerCustomerForm.getPasswordConfirm());
        assert (newCustomer != null);
        ProviderSignInUtils.handlePostSignUp(newCustomer.getUsername(), new ServletWebRequest(request));
        // The next line needs to use the customer from the input form and not the customer returned after registration
        // so that we still have the unencoded password for use by the authentication mechanism.
        loginService.loginCustomer(registerCustomerForm.getCustomer());
        // Need to ensure that the Cart on CartState is owned by the newly registered customer.
        Order cart = CartState.getCart();
        if (cart != null && !(cart instanceof NullOrderImpl) && cart.getEmailAddress() == null) {
            cart.setEmailAddress(newCustomer.getEmailAddress());
            orderService.save(cart, false);
        }
        String redirectUrl = registerCustomerForm.getRedirectUrl();
        if (StringUtils.isNotBlank(redirectUrl) && redirectUrl.contains(":")) {
            redirectUrl = null;
        }
        return StringUtils.isBlank(redirectUrl) ? getRegisterSuccessView() : "redirect:" + redirectUrl;
    } else {
        return getRegisterView();
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Aggregations

NullOrderImpl (org.broadleafcommerce.core.order.domain.NullOrderImpl)10 Order (org.broadleafcommerce.core.order.domain.Order)10 HashMap (java.util.HashMap)3 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 HashSet (java.util.HashSet)1 FulfillmentPriceException (org.broadleafcommerce.common.vendor.service.exception.FulfillmentPriceException)1 CheckoutException (org.broadleafcommerce.core.checkout.service.exception.CheckoutException)1 CheckoutResponse (org.broadleafcommerce.core.checkout.service.workflow.CheckoutResponse)1 OfferCode (org.broadleafcommerce.core.offer.domain.OfferCode)1 OfferAlreadyAddedException (org.broadleafcommerce.core.offer.service.exception.OfferAlreadyAddedException)1 OfferException (org.broadleafcommerce.core.offer.service.exception.OfferException)1 OfferExpiredException (org.broadleafcommerce.core.offer.service.exception.OfferExpiredException)1 OfferMaxUseExceededException (org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException)1 FulfillmentOption (org.broadleafcommerce.core.order.domain.FulfillmentOption)1 FulfillmentEstimationResponse (org.broadleafcommerce.core.pricing.service.fulfillment.provider.FulfillmentEstimationResponse)1 BillingInfoForm (org.broadleafcommerce.core.web.checkout.model.BillingInfoForm)1 OrderInfoForm (org.broadleafcommerce.core.web.checkout.model.OrderInfoForm)1 ShippingInfoForm (org.broadleafcommerce.core.web.checkout.model.ShippingInfoForm)1 ServletWebRequest (org.springframework.web.context.request.ServletWebRequest)1