Class BasicCartProcessor

All Implemented Interfaces:
BusinessObject, BusinessProcessor, CartProcessor

public class BasicCartProcessor extends BaseBusinessProcessor implements CartProcessor
Processes business logic having to do with a user's cart. BasicCartProcessor is the default implementation of the CartProcessor interface for the application.
Author:
David Tobey
See Also:
  • Field Details

    • log

      static org.apache.commons.logging.Log log
    • addItemStatus

      public static String addItemStatus
    • initializedStatus

      public static String initializedStatus
    • addressAddedStatus

      public static String addressAddedStatus
    • pendingStatus

      public static String pendingStatus
    • receivedStatus

      public static String receivedStatus
    • corruptedStatus

      public static String corruptedStatus
    • skipDiscountsAndShipping

      public boolean skipDiscountsAndShipping
  • Constructor Details

    • BasicCartProcessor

      public BasicCartProcessor()
  • Method Details

    • processAddItems

      public Map processAddItems(Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Processes a request to add items to a user's cart. If the user's cart has not been initialized, this method initializes it first by calling CartProcessor.initializeCart() to create a new instance of Order in the User instance for the user. It then adds an OrderDelivery instance under the Order and OrderItem instances under the OrderDelivery.

      This method manages the parsing of incoming parameters that identify the products, quantities, and attribute values of the items to be added. It populates OrderItem objects with the incoming information and then hands off the processing to the CartProcessor.processAddItems(Collection) method.

      The incoming Map must have the following keys:

      • orderProductCodes (aString[] holding the codes of the product(s) to add)
      • orderProductQuantities (aString[] holding the quantities of the product(s) to add)
      • and orderAttributes (aHashMap holding attribute keys and values, where the attribute keys are in the form of 'productCode|attributeCode')
      Specified by:
      processAddItems in interface CartProcessor
      Parameters:
      parameters - A Map representing the items and attributes being added to the user's cart.
      Returns:
      A Map representing the results of the processing. The Map may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs".
      Throws:
      Exception
      See Also:
    • processAddItems

      public Map processAddItems(Collection newOrderItems) throws Exception
      Description copied from interface: CartProcessor
      Given a Collection of initialized OrderItem objects, adds the items to the user's cart. Manages the processing of inventory and discounting, updates the user's cart totals, and manages synchronizing the objects with the database.
      Specified by:
      processAddItems in interface CartProcessor
      Parameters:
      newOrderItems - The Collection containing the OrderItem objects to be added to the user's cart.
      Returns:
      A Map containing information on the results of the processing. The Map may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs".
      Throws:
      Exception
    • initializeCart

      public void initializeCart() throws Exception
      Description copied from interface: CartProcessor
      Initializes a user's cart. Creates new instances of Order and OrderDelivery representing a user's cart. Sets the current User object's order property with the newly created Order. Synchronizes the new cart with the database.
      Specified by:
      initializeCart in interface CartProcessor
      Throws:
      Exception
    • initializeCart

      public void initializeCart(Map parameters) throws Exception
      Throws:
      Exception
    • processQuantities

      public void processQuantities(Collection newOrderItems) throws Exception
      Description copied from interface: CartProcessor
      Given a Collection of OrderItems in the user's cart whose quantities have been set, updates the totals and weights of each OrderItem based on the (new) quantity.
      Specified by:
      processQuantities in interface CartProcessor
      Parameters:
      newOrderItems - The Collection containing the OrderItem objects whose quantities and totals are to be set.
      Throws:
      Exception
    • processTotalsAndFormatting

      public void processTotalsAndFormatting(Collection orderItems) throws Exception
      Description copied from interface: CartProcessor
      Given a Collection of OrderItems in the user's cart whose totals have been set, updates the totals and weights of each OrderDelivery and Order they are under, and applies formatting to the totals.
      Specified by:
      processTotalsAndFormatting in interface CartProcessor
      Parameters:
      orderItems - The OrderItems whose totals must be added to the order and order delivery.
      Throws:
      Exception
    • updateOrderAndDeliveryTotals

      public void updateOrderAndDeliveryTotals(OrderDelivery orderDelivery, OrderItem orderItem)
      Given an OrderItem, updates the totals of the user's Order and the OrderDelivery the OrderItem is under. Calculates new totals for the quantity, price total, and weight total.
      Parameters:
      orderDelivery - The order delivery that contains the new OrderItem.
      orderItem - The newly-added order item whose price must be added to the order's total and the delivery's total.
    • getOrderAttribute

      public String getOrderAttribute(Map parameters, String productCode, String attributeCode, int index) throws Exception
      Retrieves the value submitted for an attribute of a given product, as part of a request to add or edit an item in the user's cart. Uses the orderAttributes property (which is a HashMap) of the incoming Map to look up the attribute's value. The key for the attribute is formed like so: productCode|attributeCode.
      Parameters:
      parameters - A Map representing the items and properties submitted to add or edit items in the user's cart.
      productCode - The code of the product corresponding to the attribute.
      attributeCode - The code of the attribute whose value is being looked up.
      index - The index of the submitted array of product codes corresponding to the item being added.
      Returns:
      The submitted value of the attribute corresponding to the attibuteCode, or null, if the attribute is not found.
      Throws:
      Exception
    • processItemAttributes

      public void processItemAttributes(Map parameters, Product product, Collection missingAttributes, Collection newOrderItems, OrderItem orderItem, int index) throws Exception
      Finds the attributes identified in the incoming parameters and creates OrderItemAttributes to be added to the OrderItem.
      Parameters:
      parameters -
      product -
      missingAttributes -
      newOrderItems -
      orderItem -
      index -
      Throws:
      Exception
    • processItemAttribute

      public void processItemAttribute(OrderItem orderItem, Attribute attribute, Option option, String attributeValue) throws Exception
      Adds an attribute to a given OrderItem. Adds the attribute's total and weight to the order item's.
      Parameters:
      orderItem - The OrderItem that is having an attribute added to it.
      attribute - The Attribute being added to the order item
      option - The Option of the above attribute that is being added to the order item. If no option is relevant, this parameter may be null.
      attributeValue - The value of the attribute being added to the OrderItem. Corresponds to the option's code, or a free form value if no option is relevant.
      Throws:
      Exception
    • getOrderItemQuantity

      public int getOrderItemQuantity(Map parameters, int index) throws Exception
      Looks up the submitted quantity of a given product contained in a request to add or edit a user's cart item. Uses the orderProductQuantities property (which is a String[]) of the incoming Map to look up the value.
      Parameters:
      parameters - A Map representing the items and properties being added or edited.
      index - The index of the submitted array of product quantities corresponding to the item being added.
      Returns:
      An int representing the submitted quantity of the user's cart item
      Throws:
      Exception
    • processEditItem

      public Map processEditItem(Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Processes a request to edit a given item in a user's cart. The incoming Map must have the same keys required by CartProcessor.processAddItems(Map), plus a key named orderItem, which identifies the order item being edited.
      Specified by:
      processEditItem in interface CartProcessor
      Parameters:
      parameters - A Map identifying the item being edited and specifying the item's new properties.
      Returns:
      A Map containing information on the results of the processing. The Map may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs".
      Throws:
      Exception
      See Also:
    • processRemoveItem

      public Map processRemoveItem(OrderItem orderItem) throws Exception
      Description copied from interface: CartProcessor
      Removes a given OrderItem from the user's cart, updating the cart totals in the process.
      Specified by:
      processRemoveItem in interface CartProcessor
      Parameters:
      orderItem - The OrderItem being removed.
      Throws:
      Exception
    • processCheckoutAddresses

      public Map processCheckoutAddresses(Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Processes a request to add address information to a user's cart. Originates from the checkout process in the Struts layer.
      Specified by:
      processCheckoutAddresses in interface CartProcessor
      Parameters:
      parameters - A Map representing the address information of the current user.
      Throws:
      Exception
      See Also:
    • processOrderComplete

      public Map processOrderComplete(Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Handles processing at the end of the checkout process, after payments have been processed. Decrements inventory, marks discounts as having been used and updates the order totals.
      Specified by:
      processOrderComplete in interface CartProcessor
      Returns:
      A Map representing the results of the processing.
      Throws:
      Exception
      See Also:
    • markOrderComplete

      public Map markOrderComplete(Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Marks an order as complete at the very end of the checkout process, after payments have been processed. Sets the order's completed field with the current time. Sets the user's order with a status of "Received" and assigns an order number to the order. The "Received" status is given to all orders that have been successfully completed by the user. In other words, orders whose payments succeeded.

      The order number is an integer given to each completed order, starting at the "orderNumberFloor" database setting (whose default is 1,000).

      Specified by:
      markOrderComplete in interface CartProcessor
      Returns:
      A Map representing the results of the processing.
      Throws:
      Exception
      See Also:
    • createGiftCertificates

      public void createGiftCertificates(OrderItem oi) throws Exception
      Throws:
      Exception
    • computeGiftCertificateExpDate

      public String computeGiftCertificateExpDate()
    • postProcessAddItems

      public Map postProcessAddItems(Collection newOrderItems) throws Exception
      Throws:
      Exception
    • postProcessCartChanged

      public Map postProcessCartChanged() throws Exception
      Description copied from interface: CartProcessor
      Hook method which is called any time an item or items changes in the cart.
      Specified by:
      postProcessCartChanged in interface CartProcessor
      Returns:
      A Map representing the results of the processing.
      Throws:
      Exception
    • sendOrderCompleteEmails

      public Map sendOrderCompleteEmails(Order order, Map parameters) throws Exception
      Description copied from interface: CartProcessor
      Called when an order is completed. Sends an order confirmation email to the customer and an order notification email to store admins.
      Specified by:
      sendOrderCompleteEmails in interface CartProcessor
      Returns:
      A Map representing the results of the processing.
      Throws:
      Exception