Class BroadleafCartController

java.lang.Object
org.broadleafcommerce.common.web.controller.BroadleafAbstractController
org.broadleafcommerce.core.web.controller.cart.AbstractCartController
org.broadleafcommerce.core.web.controller.cart.BroadleafCartController

public class BroadleafCartController extends AbstractCartController
In charge of performing the various modify cart operations
Author:
Andre Azzolini (apazzolini)
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected static String
     
    protected boolean
     
    protected static String
     
    protected static String
     
    protected static String
     
    protected static String
     
    protected static String
     

    Fields inherited from class org.broadleafcommerce.core.web.controller.cart.AbstractCartController

    catalogService, dtoTranslationService, offerService, orderItemService, orderService, updateCartService
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    add(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest)
    Takes in an item request, adds the item to the customer's current cart, and returns.
    addPromo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, String customerOffer)
    Attempts to add provided Offer to Cart
    addWithPriceOverride(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.AddToCartItem itemRequest)
    Deprecated.
    addWithPriceOverride(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest)
    Takes in an item request, adds the item to the customer's current cart, and returns.
    cart(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model)
    Renders the cart page.
    configure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long productId)
    Takes a product id and builds out a dependant order item tree.
    empty(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model)
    Cancels the current cart and redirects to the homepage
     
     
     
     
     
    handleIllegalCartOpException(org.broadleafcommerce.core.order.service.exception.IllegalCartOperationException ex)
     
    protected boolean
    isCheckoutContext(jakarta.servlet.http.HttpServletRequest request)
     
    protected boolean
    isSafeToAdd(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest itemRequest)
     
    protected boolean
    isUpdateRequest(jakarta.servlet.http.HttpServletRequest request)
     
    reconfigure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long orderItemId)
    Takes an order item id and rebuilds the dependant order item tree with the current quantities and options set.
    remove(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest)
    Takes in an item request, updates the quantity of that item in the cart, and returns
    removePromo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long offerCodeId)
    Removes offer from cart
    protected void
    updateAddRequestQuantities(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest, Long originalOrderItemId)
     
    updateQuantity(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.AddToCartItem itemRequest)
    Deprecated.
    updateQuantity(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest)
    Takes in an item request and updates the quantity of that item in the cart.

    Methods inherited from class org.broadleafcommerce.common.web.controller.BroadleafAbstractController

    addDeepLink, getContextPath, isAjaxRequest, jsonResponse

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • cartView

      protected static String cartView
    • checkoutView

      protected static String checkoutView
    • cartPageRedirect

      protected static String cartPageRedirect
    • configureView

      protected static String configureView
    • configurePageRedirect

      protected static String configurePageRedirect
    • ALL_PRODUCTS_ATTRIBUTE_NAME

      protected static String ALL_PRODUCTS_ATTRIBUTE_NAME
    • automaticallyAddCompleteItems

      @Value("${automatically.add.complete.items}") protected boolean automaticallyAddCompleteItems
  • Constructor Details

    • BroadleafCartController

      public BroadleafCartController()
  • Method Details

    • cart

      public String cart(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model) throws org.broadleafcommerce.core.pricing.service.exception.PricingException
      Renders the cart page.

      If the method was invoked via an AJAX call, it will render the "ajax/cart" template. Otherwise, it will render the "cart" template.

      Will reprice the order if the currency has been changed.

      Parameters:
      request -
      response -
      model -
      Throws:
      org.broadleafcommerce.core.pricing.service.exception.PricingException
    • add

      public String add(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest) throws IOException, org.broadleafcommerce.core.order.service.exception.AddToCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException, NumberFormatException, org.broadleafcommerce.core.order.service.exception.RemoveFromCartException, IllegalArgumentException
      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"

      Parameters:
      request -
      response -
      model -
      itemRequest -
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.AddToCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
      NumberFormatException
      IllegalArgumentException
    • updateAddRequestQuantities

      protected void updateAddRequestQuantities(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest, Long originalOrderItemId)
    • isUpdateRequest

      protected boolean isUpdateRequest(jakarta.servlet.http.HttpServletRequest request)
    • addWithPriceOverride

      public String addWithPriceOverride(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest) throws IOException, org.broadleafcommerce.core.order.service.exception.AddToCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException
      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.

      Parameters:
      request -
      response -
      model -
      itemRequest -
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.AddToCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
    • addWithPriceOverride

      @Deprecated public String addWithPriceOverride(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.AddToCartItem itemRequest) throws IOException, org.broadleafcommerce.core.order.service.exception.AddToCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException
      Deprecated.
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.AddToCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
    • configure

      public String configure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long productId) throws IOException, org.broadleafcommerce.core.order.service.exception.AddToCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException, Exception
      Takes a product id and builds out a dependant order item tree. If it determines the order item is safe to add, it will proceed to calling the "add" method.

      If the method was invoked via an AJAX call, it will render the "ajax/configure" template. Otherwise, it will perform a 302 redirect to "/cart/configure"

      In the case that an "add" happened it will render either the "ajax/cart" or perform a 302 redirect to "/cart"

      Parameters:
      request -
      response -
      model -
      productId -
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.AddToCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      Exception
    • reconfigure

      public String reconfigure(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long orderItemId) throws IOException, org.broadleafcommerce.core.order.service.exception.AddToCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException, Exception
      Takes an order item id and rebuilds the dependant order item tree with the current quantities and options set.

      If the method was invoked via an AJAX call, it will render the "ajax/configure" template. Otherwise, it will perform a 302 redirect to "/cart/configure"

      Parameters:
      request -
      response -
      model -
      orderItemId -
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.AddToCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      Exception
    • updateQuantity

      public String updateQuantity(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest) throws IOException, org.broadleafcommerce.core.order.service.exception.UpdateCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException, org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
      Takes in an item request and updates the quantity of that item in the cart. If the quantity was passed in as 0, it will remove the item.

      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"

      Parameters:
      request -
      response -
      model -
      itemRequest -
      Throws:
      IOException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.order.service.exception.UpdateCartException
      org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
    • updateQuantity

      @Deprecated public String updateQuantity(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.AddToCartItem itemRequest) throws IOException, org.broadleafcommerce.core.order.service.exception.UpdateCartException, org.broadleafcommerce.core.pricing.service.exception.PricingException, org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
      Deprecated.
      Throws:
      IOException
      org.broadleafcommerce.core.order.service.exception.UpdateCartException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
    • remove

      public String remove(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO itemRequest) throws IOException, org.broadleafcommerce.core.pricing.service.exception.PricingException, org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
      Takes in an item request, updates the quantity of that item in the 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"

      Parameters:
      request -
      response -
      model -
      itemRequest -
      Throws:
      IOException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.order.service.exception.RemoveFromCartException
    • empty

      public String empty(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model) throws org.broadleafcommerce.core.pricing.service.exception.PricingException
      Cancels the current cart and redirects to the homepage
      Parameters:
      request -
      response -
      model -
      Throws:
      org.broadleafcommerce.core.pricing.service.exception.PricingException
    • addPromo

      public String addPromo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, String customerOffer) throws IOException, org.broadleafcommerce.core.pricing.service.exception.PricingException
      Attempts to add provided Offer to Cart
      Parameters:
      request -
      response -
      model -
      customerOffer -
      Returns:
      the return view
      Throws:
      IOException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException
    • isCheckoutContext

      protected boolean isCheckoutContext(jakarta.servlet.http.HttpServletRequest request)
    • removePromo

      public String removePromo(jakarta.servlet.http.HttpServletRequest request, jakarta.servlet.http.HttpServletResponse response, org.springframework.ui.Model model, Long offerCodeId) throws IOException, org.broadleafcommerce.core.pricing.service.exception.PricingException
      Removes offer from cart
      Parameters:
      request -
      response -
      model -
      Returns:
      the return view
      Throws:
      IOException
      org.broadleafcommerce.core.pricing.service.exception.PricingException
      org.broadleafcommerce.core.offer.service.exception.OfferMaxUseExceededException
    • getCartView

      public String getCartView()
    • getCartPageRedirect

      public String getCartPageRedirect()
    • getConfigureView

      public String getConfigureView()
    • getConfigurePageRedirect

      public String getConfigurePageRedirect()
    • getCheckoutView

      public String getCheckoutView()
    • handleIllegalCartOpException

      public Map<String,String> handleIllegalCartOpException(org.broadleafcommerce.core.order.service.exception.IllegalCartOperationException ex)
    • isSafeToAdd

      protected boolean isSafeToAdd(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest itemRequest)