com.softslate.commerce.businessobjects.order
Class BasicCartProcessor

java.lang.Object
  extended bycom.softslate.commerce.businessobjects.core.BaseBusinessObject
      extended bycom.softslate.commerce.businessobjects.core.BaseBusinessProcessor
          extended bycom.softslate.commerce.businessobjects.order.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:
CartProcessor

Field Summary
(package private) static org.apache.commons.logging.Log log
           
 
Fields inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
 
Constructor Summary
BasicCartProcessor()
           
 
Method Summary
 java.lang.String getOrderAttribute(java.util.Map parameters, java.lang.String productCode, java.lang.String attributeCode)
          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.
 int getOrderItemQuantity(java.lang.String productCode, java.util.Map parameters)
          Looks up the submitted quantity of a given product contained in a request to add or edit a user's cart item.
 void initializeCart()
          Initializes a user's cart.
 java.util.Map processAddItems(java.util.Map parameters)
          Processes a request to add items to a user's cart.
 java.util.Map processCheckoutAddresses(java.util.Map parameters)
          Processes a request to add address information to a user's cart.
 java.util.Map processEditItem(java.util.Map parameters)
          Processes a request to edit a given item in a user's cart.
 void processItemAttribute(OrderItem orderItem, java.util.Map productInfoMap, java.lang.String attributeValue)
          Adds an attribute to a given OrderItem.
 java.util.Map processOrderComplete(java.util.Map parameters)
          Handles processing at the very end of the checkout process, after payments have been processed.
 java.util.Map processRemoveItem(OrderItem orderItem)
          Removes a given OrderItem from the user's cart, updating the cart totals in the process.
 void updateOrderAndDeliveryTotals(OrderDelivery orderDelivery, OrderItem orderItem)
          Given a newly-added OrderItem, updates the totals of the user's Order and the OrderDelivery the OrderItem is under.
 void updateOrderItemQuantity(OrderItem orderItem, int quantity)
          Given an OrderItem in the user's cart and a new quantity for that item, updates the totals of the user's Order and the OrderDelivery the OrderItem is under.
 
Methods inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
formatPrice, getBusinessObjectFactory, getDaoFactory, getSettingsBean, getUser, initialize, setBusinessObjectFactory, setDaoFactory, setSettingsBean, setUser
 
Methods inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessObject
formatDateTime, parseDateTime, prepareRequestData, sendHTTPPost
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.softslate.commerce.businessobjects.core.BusinessObject
initialize
 

Field Detail

log

static org.apache.commons.logging.Log log
Constructor Detail

BasicCartProcessor

public BasicCartProcessor()
Method Detail

processAddItems

public java.util.Map processAddItems(java.util.Map parameters)
                              throws java.lang.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 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.

The 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.
Throws:
java.lang.Exception

updateOrderAndDeliveryTotals

public void updateOrderAndDeliveryTotals(OrderDelivery orderDelivery,
                                         OrderItem orderItem)
Given a newly-added 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 java.lang.String getOrderAttribute(java.util.Map parameters,
                                          java.lang.String productCode,
                                          java.lang.String attributeCode)
                                   throws java.lang.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.
Returns:
The submitted value of the attribute corresponding to the attibuteCode, or null, if the attribute is not found.
Throws:
java.lang.Exception

processItemAttribute

public void processItemAttribute(OrderItem orderItem,
                                 java.util.Map productInfoMap,
                                 java.lang.String attributeValue)
Adds an attribute to a given OrderItem. Attributes under an order item are each represented as a Map within the orderItemAttributes property of the OrderItem.

Parameters:
orderItem - The OrderItem that is having an attribute added to it.
productInfoMap - A Map representing information about a product, attribute, and option. The map represents one row of a database query joining the npcProduct, npcProductAttribute,npcAttribute, and npcOption tables.
attributeValue - The value of the attribute being added to the OrderItem.

getOrderItemQuantity

public int getOrderItemQuantity(java.lang.String productCode,
                                java.util.Map parameters)
                         throws java.lang.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:
productCode - The code of the product corresponding to the OrderItem being added or edited.
parameters - A Map representing the items and properties being added or edited.
Returns:
An int representing the submitted quantity of the user's cart item
Throws:
java.lang.Exception

processEditItem

public java.util.Map processEditItem(java.util.Map parameters)
                              throws java.lang.Exception
Description copied from interface: CartProcessor
Processes a request to edit a given item in a user's cart. The incoming Map must have keys named orderItem (which identifies the order item being edited) and orderProductQuantities (which holds the new quantity for the order item).

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 representing the results of the processing.
Throws:
java.lang.Exception

processRemoveItem

public java.util.Map processRemoveItem(OrderItem orderItem)
                                throws java.lang.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:
java.lang.Exception

updateOrderItemQuantity

public void updateOrderItemQuantity(OrderItem orderItem,
                                    int quantity)
Given an OrderItem in the user's cart and a new quantity for that item, updates the totals of the user's Order and the OrderDelivery the OrderItem is under.

Parameters:
orderItem - The OrderItem whose quantity is being changed.
quantity - The new quantity for the item.

initializeCart

public void initializeCart()
                    throws java.lang.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 setOrder(Order order) with the newly created Order.

Specified by:
initializeCart in interface CartProcessor
Throws:
java.lang.Exception

processCheckoutAddresses

public java.util.Map processCheckoutAddresses(java.util.Map parameters)
                                       throws java.lang.Exception
Description copied from interface: CartProcessor
Processes a request to add address information to a user's cart. Originates usually 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:
java.lang.Exception

processOrderComplete

public java.util.Map processOrderComplete(java.util.Map parameters)
                                   throws java.lang.Exception
Description copied from interface: CartProcessor
Handles processing at the very end of the checkout process, after payments have been processed. 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:
processOrderComplete in interface CartProcessor
Returns:
A Map representing the results of the processing.
Throws:
java.lang.Exception


Copyright © SoftSlate, Inc. 2003–2005