Class BasicCartProcessor
java.lang.Object
com.softslate.commerce.businessobjects.core.BaseBusinessObject
com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
com.softslate.commerce.businessobjects.order.BasicCartProcessor
- All Implemented Interfaces:
BusinessObject
,BusinessProcessor
,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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
getOrderAttribute
(Map parameters, String productCode, String attributeCode, int index) 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
(Map parameters, int index) Looks up the submitted quantity of a given product contained in a request to add or edit a user's cart item.void
Initializes a user's cart.void
initializeCart
(Map parameters) markOrderComplete
(Map parameters) Marks an order as complete at the very end of the checkout process, after payments have been processed.postProcessAddItems
(Collection newOrderItems) Hook method which is called any time an item or items changes in the cart.processAddItems
(Collection newOrderItems) Given aCollection
of initializedOrderItem
objects, adds the items to the user's cart.processAddItems
(Map parameters) Processes a request to add items to a user's cart.processCheckoutAddresses
(Map parameters) Processes a request to add address information to a user's cart.processEditItem
(Map parameters) Processes a request to edit a given item in a user's cart.void
processItemAttribute
(OrderItem orderItem, Attribute attribute, Option option, String attributeValue) Adds an attribute to a givenOrderItem
.void
processItemAttributes
(Map parameters, Product product, Collection missingAttributes, Collection newOrderItems, OrderItem orderItem, int index) Finds the attributes identified in the incoming parameters and creates OrderItemAttributes to be added to the OrderItem.processOrderComplete
(Map parameters) Handles processing at the end of the checkout process, after payments have been processed.void
processQuantities
(Collection newOrderItems) Given a Collection ofOrderItems
in the user's cart whose quantities have been set, updates the totals and weights of eachOrderItem
based on the (new) quantity.processRemoveItem
(OrderItem orderItem) Removes a given OrderItem from the user's cart, updating the cart totals in the process.void
processTotalsAndFormatting
(Collection orderItems) Given a Collection ofOrderItems
in the user's cart whose totals have been set, updates the totals and weights of eachOrderDelivery
andOrder
they are under, and applies formatting to the totals.sendOrderCompleteEmails
(Order order, Map parameters) Called when an order is completed.void
updateOrderAndDeliveryTotals
(OrderDelivery orderDelivery, OrderItem orderItem) Given anOrderItem
, updates the totals of the user'sOrder
and theOrderDelivery
theOrderItem
is under.Methods inherited from class com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
formatDateTime, formatPrice, getAppComponents, getAppSettings, getAttributeIDs, getBusinessObjectFactory, getDaoFactory, getEventBus, getInjector, getProductIDs, getSettings, getUser, initialize, isProcessorClassActive, loadMatchingSkus, parseDateTime, parseResponseData, prepareRequestData, sendHTTPGet, sendHTTPPost, sendHTTPPost, setAppComponents, setAppSettings, setBusinessObjectFactory, setDaoFactory, setEventBus, setInjector, setSettings, setUser, updateOrderTotals, updateOrderTotals, updateOrderTotals, utils
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
Methods inherited from interface com.softslate.commerce.businessobjects.core.BusinessProcessor
getAppComponents, getAppSettings, getBusinessObjectFactory, getDaoFactory, getEventBus, getInjector, getSettings, getUser, setAppComponents, setAppSettings, setBusinessObjectFactory, setDaoFactory, setEventBus, setInjector, setSettings, setUser, utils
-
Field Details
-
log
static org.apache.commons.logging.Log log -
addItemStatus
-
initializedStatus
-
addressAddedStatus
-
pendingStatus
-
receivedStatus
-
corruptedStatus
-
skipDiscountsAndShipping
public boolean skipDiscountsAndShipping
-
-
Constructor Details
-
BasicCartProcessor
public BasicCartProcessor()
-
-
Method Details
-
processAddItems
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 callingCartProcessor.initializeCart()
to create a new instance ofOrder
in theUser
instance for the user. It then adds anOrderDelivery
instance under theOrder
andOrderItem
instances under theOrderDelivery
.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 theCartProcessor.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 interfaceCartProcessor
- Parameters:
parameters
- AMap
representing the items and attributes being added to the user's cart.- Returns:
- A
Map
representing the results of the processing. TheMap
may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs". - Throws:
Exception
- See Also:
-
-
processAddItems
Description copied from interface:CartProcessor
Given aCollection
of initializedOrderItem
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 interfaceCartProcessor
- Parameters:
newOrderItems
- TheCollection
containing theOrderItem
objects to be added to the user's cart.- Returns:
- A
Map
containing information on the results of the processing. TheMap
may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs". - Throws:
Exception
-
initializeCart
Description copied from interface:CartProcessor
Initializes a user's cart. Creates new instances ofOrder
andOrderDelivery
representing a user's cart. Sets the currentUser
object's order property with the newly createdOrder
. Synchronizes the new cart with the database.- Specified by:
initializeCart
in interfaceCartProcessor
- Throws:
Exception
-
initializeCart
- Throws:
Exception
-
processQuantities
Description copied from interface:CartProcessor
Given a Collection ofOrderItems
in the user's cart whose quantities have been set, updates the totals and weights of eachOrderItem
based on the (new) quantity.- Specified by:
processQuantities
in interfaceCartProcessor
- Parameters:
newOrderItems
- TheCollection
containing theOrderItem
objects whose quantities and totals are to be set.- Throws:
Exception
-
processTotalsAndFormatting
Description copied from interface:CartProcessor
Given a Collection ofOrderItems
in the user's cart whose totals have been set, updates the totals and weights of eachOrderDelivery
andOrder
they are under, and applies formatting to the totals.- Specified by:
processTotalsAndFormatting
in interfaceCartProcessor
- Parameters:
orderItems
- TheOrderItems
whose totals must be added to the order and order delivery.- Throws:
Exception
-
updateOrderAndDeliveryTotals
Given anOrderItem
, updates the totals of the user'sOrder
and theOrderDelivery
theOrderItem
is under. Calculates new totals for the quantity, price total, and weight total.- Parameters:
orderDelivery
- The order delivery that contains the newOrderItem
.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 theorderAttributes
property (which is aHashMap
) of the incomingMap
to look up the attribute's value. The key for the attribute is formed like so:productCode|attributeCode
.- Parameters:
parameters
- AMap
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
, ornull
, 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 givenOrderItem
. Adds the attribute's total and weight to the order item's.- Parameters:
orderItem
- TheOrderItem
that is having an attribute added to it.attribute
- TheAttribute
being added to the order itemoption
- TheOption
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 theOrderItem
. Corresponds to the option's code, or a free form value if no option is relevant.- Throws:
Exception
-
getOrderItemQuantity
Looks up the submitted quantity of a given product contained in a request to add or edit a user's cart item. Uses theorderProductQuantities
property (which is aString[]
) of the incomingMap
to look up the value.- Parameters:
parameters
- AMap
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
Description copied from interface:CartProcessor
Processes a request to edit a given item in a user's cart. The incomingMap
must have the same keys required byCartProcessor.processAddItems(Map)
, plus a key namedorderItem
, which identifies the order item being edited.- Specified by:
processEditItem
in interfaceCartProcessor
- Parameters:
parameters
- AMap
identifying the item being edited and specifying the item's new properties.- Returns:
- A
Map
containing information on the results of the processing. TheMap
may have one or more of the following keys related to inventory processing: "lowStockEmails", "missingAttributes", "rejectedOrderItems", "adjustedOrderItems", and "newOOSSKUs". - Throws:
Exception
- See Also:
-
processRemoveItem
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 interfaceCartProcessor
- Parameters:
orderItem
- TheOrderItem
being removed.- Throws:
Exception
-
processCheckoutAddresses
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 interfaceCartProcessor
- Parameters:
parameters
- AMap
representing the address information of the current user.- Throws:
Exception
- See Also:
-
processOrderComplete
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 interfaceCartProcessor
- Returns:
- A
Map
representing the results of the processing. - Throws:
Exception
- See Also:
-
markOrderComplete
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 interfaceCartProcessor
- Returns:
- A
Map
representing the results of the processing. - Throws:
Exception
- See Also:
-
createGiftCertificates
- Throws:
Exception
-
computeGiftCertificateExpDate
-
postProcessAddItems
- Throws:
Exception
-
postProcessCartChanged
Description copied from interface:CartProcessor
Hook method which is called any time an item or items changes in the cart.- Specified by:
postProcessCartChanged
in interfaceCartProcessor
- Returns:
- A
Map
representing the results of the processing. - Throws:
Exception
-
sendOrderCompleteEmails
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 interfaceCartProcessor
- Returns:
- A
Map
representing the results of the processing. - Throws:
Exception
-