Search in sources :

Example 6 with NullOrderImpl

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

the class BroadleafCartController method addWithPriceOverride.

/**
 * Takes in an item request, adds the item to the customer's current cart, and returns.
 *
 * Calls the addWithOverrides method on the orderService which will honor the override
 * prices on the OrderItemRequestDTO request object.
 *
 * Implementors must secure this method to avoid accidentally exposing the ability for
 * malicious clients to override prices by hacking the post parameters.
 *
 * @param request
 * @param response
 * @param model
 * @param itemRequest
 * @throws IOException
 * @throws AddToCartException
 * @throws PricingException
 */
public String addWithPriceOverride(HttpServletRequest request, HttpServletResponse response, Model model, OrderItemRequestDTO itemRequest) throws IOException, AddToCartException, PricingException {
    Order cart = CartState.getCart();
    // and provision a fresh cart for the current customer upon the first cart add
    if (cart == null || cart instanceof NullOrderImpl) {
        cart = orderService.createNewCartForCustomer(CustomerState.getCustomer(request));
    }
    updateCartService.validateAddToCartRequest(itemRequest, cart);
    cart = orderService.addItemWithPriceOverrides(cart.getId(), itemRequest, false);
    cart = orderService.save(cart, true);
    return isAjaxRequest(request) ? getCartView() : getCartPageRedirect();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Example 7 with NullOrderImpl

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

the class BroadleafCartController method add.

/**
 * Takes in an item request, adds the item to the customer's current cart, and returns.
 *
 * If the method was invoked via an AJAX call, it will render the "ajax/cart" template.
 * Otherwise, it will perform a 302 redirect to "/cart"
 *
 * @param request
 * @param response
 * @param model
 * @param itemRequest
 * @throws IOException
 * @throws AddToCartException
 * @throws PricingException
 * @throws RemoveFromCartException
 * @throws NumberFormatException
 */
public String add(HttpServletRequest request, HttpServletResponse response, Model model, OrderItemRequestDTO itemRequest) throws IOException, AddToCartException, PricingException, NumberFormatException, RemoveFromCartException, IllegalArgumentException {
    Order cart = CartState.getCart();
    // and provision a fresh cart for the current customer upon the first cart add
    if (cart == null || cart instanceof NullOrderImpl) {
        cart = orderService.createNewCartForCustomer(CustomerState.getCustomer(request));
    }
    // Validate the add to cart
    updateCartService.validateAddToCartRequest(itemRequest, cart);
    // if this is an update to an existing order item, remove the old before proceeding
    if (isUpdateRequest(request)) {
        String originalOrderItem = request.getParameter("originalOrderItem");
        if (StringUtils.isNotEmpty(originalOrderItem)) {
            Long originalOrderItemId = Long.parseLong(originalOrderItem);
            updateAddRequestQuantities(itemRequest, originalOrderItemId);
            cart = orderService.removeItem(cart.getId(), originalOrderItemId, false);
            cart = orderService.save(cart, true);
        }
    }
    cart = orderService.addItem(cart.getId(), itemRequest, false);
    cart = orderService.save(cart, true);
    return isAjaxRequest(request) ? getCartView() : getCartPageRedirect();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Example 8 with NullOrderImpl

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

the class NamedOrderProcessor method populateModelVariables.

@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
    Customer customer = CustomerState.getCustomer();
    String orderVar = tagAttributes.get("orderVar");
    String orderName = tagAttributes.get("orderName");
    Order order = orderService.findNamedOrderForCustomer(orderName, customer);
    Map<String, Object> newModelVars = new HashMap<>();
    if (order != null) {
        newModelVars.put(orderVar, order);
    } else {
        newModelVars.put(orderVar, new NullOrderImpl());
    }
    return newModelVars;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Customer(org.broadleafcommerce.profile.core.domain.Customer) HashMap(java.util.HashMap) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Example 9 with NullOrderImpl

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

the class OnePageCheckoutProcessor method populateModelVariables.

@Override
public Map<String, Object> populateModelVariables(String tagName, Map<String, String> tagAttributes, BroadleafTemplateContext context) {
    // Pre-populate the command objects
    OrderInfoForm orderInfoForm = context.parseExpression(tagAttributes.get("orderInfoForm"));
    ShippingInfoForm shippingInfoForm = context.parseExpression(tagAttributes.get("shippingInfoForm"));
    BillingInfoForm billingInfoForm = context.parseExpression(tagAttributes.get("billingInfoForm"));
    String orderInfoHelpMessage = context.parseExpression(tagAttributes.get("orderInfoHelpMessage"));
    String billingInfoHelpMessage = context.parseExpression(tagAttributes.get("billingInfoHelpMessage"));
    String shippingInfoHelpMessage = context.parseExpression(tagAttributes.get("shippingInfoHelpMessage"));
    prepopulateCheckoutForms(CartState.getCart(), orderInfoForm, shippingInfoForm, billingInfoForm);
    // Add PaymentRequestDTO to the model in the case of errors or other cases
    Map<String, Object> newModelVars = new HashMap<>();
    Order cart = CartState.getCart();
    if (cart != null && !(cart instanceof NullOrderImpl)) {
        newModelVars.put("paymentRequestDTO", orderToPaymentRequestDTOService.translateOrder(cart));
    }
    // Initialize Fulfillment Group Vars
    int numShippableFulfillmentGroups = calculateNumShippableFulfillmentGroups();
    newModelVars.put("numShippableFulfillmentGroups", numShippableFulfillmentGroups);
    populateFulfillmentOptionsAndEstimationOnModel(newModelVars);
    // Initialize View States
    newModelVars.put("orderInfoHelpMessage", orderInfoHelpMessage);
    newModelVars.put("billingInfoHelpMessage", billingInfoHelpMessage);
    newModelVars.put("shippingInfoHelpMessage", shippingInfoHelpMessage);
    populateSectionViewStates(newModelVars);
    // Helpful lists to populate dropdowns on a checkout page
    newModelVars.put("states", stateService.findStates());
    newModelVars.put("countries", countryService.findCountries());
    newModelVars.put("expirationMonths", populateExpirationMonths());
    newModelVars.put("expirationYears", populateExpirationYears());
    // Populate any Payment Processing Errors
    populateProcessingError(newModelVars);
    return newModelVars;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderInfoForm(org.broadleafcommerce.core.web.checkout.model.OrderInfoForm) ShippingInfoForm(org.broadleafcommerce.core.web.checkout.model.ShippingInfoForm) HashMap(java.util.HashMap) BillingInfoForm(org.broadleafcommerce.core.web.checkout.model.BillingInfoForm) NullOrderImpl(org.broadleafcommerce.core.order.domain.NullOrderImpl)

Example 10 with NullOrderImpl

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

the class CartStateRefresher method onApplicationEvent.

/**
 * <p>Resets {@link CartState} with the newly persisted Order. If {@link CartState} was empty, this will only update it if
 * the {@link Order} that has been persisted is the {@link OrderStatus#IN_PROCESS} {@link Order} for the active
 * {@link Customer} (as determined by {@link CustomerState#getCustomer()}. If {@link CartState} was <b>not</b> empty,
 * then it will be replaced only if this newly persisted {@link Order} has the same id.</p>
 *
 * <p>This ensures that whatever is returned from {@link CartState#getCart()} will always be the most up-to-date
 * database version (meaning, safe to write to the DB).</p>
 */
@Override
public void onApplicationEvent(final OrderPersistedEvent event) {
    WebRequest request = BroadleafRequestContext.getBroadleafRequestContext().getWebRequest();
    if (request != null) {
        Order dbOrder = event.getOrder();
        // Update the cart state ONLY IF the IDs of the newly persisted order and whatever is already in CartState match
        boolean emptyCartState = CartState.getCart() == null || CartState.getCart() instanceof NullOrderImpl;
        if (emptyCartState) {
            // If cart state is empty, set it to this newly persisted order if it's the active Customer's cart
            if (CustomerState.getCustomer() != null && CustomerState.getCustomer().getId().equals(dbOrder.getCustomer().getId()) && OrderStatus.IN_PROCESS.equals(dbOrder.getStatus())) {
                CartState.setCart(dbOrder);
            }
        } else if (CartState.getCart().getId().equals(dbOrder.getId())) {
            CartState.setCart(dbOrder);
        }
    }
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) WebRequest(org.springframework.web.context.request.WebRequest) 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