Class BasicInventoryProcessor
java.lang.Object
com.softslate.commerce.businessobjects.core.BaseBusinessObject
com.softslate.commerce.businessobjects.core.BaseBusinessProcessor
com.softslate.commerce.businessobjects.order.BasicInventoryProcessor
- All Implemented Interfaces:
BusinessObject,BusinessProcessor,InventoryProcessor
Processes business logic having to do with SKUs and inventory levels.
BasicInventoryProcessor is the default implementation of the
InventoryProcessor interface for the application.- Author:
- David Tobey
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) static org.apache.commons.logging.LogString[]The settings keys dealing with inventory. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiondefineInventorySettings(Product product, Collection attributeSKUCollection) Inspects a Product and returns a Map of useful variables related to the state of the product's inventory.loadProductSettings(Collection orderItems, Collection productIDs) Loads inventory settings for each of the products corresponding to a givenCollectionofOrderItems.protected voidpostToEventBus(Map results) processAddItems(Collection orderItems) Processes inventory as newOrderItems are added to a user's cart.processInventory(Collection orderItems, Map productSettings, Collection matchingSkus, String behavior) Generically processes inventory, returning a Map with information about items and skus.processOnCheckout(Map parameters) Checks inventory for a user's cart during checkout.processOrderComplete(Map parameters) Processes inventory for a user's cart as an order is completed.voidprocessOrderItemAndSKU(OrderItem oi, Map sku) 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, utilsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.softslate.commerce.businessobjects.core.BusinessObject
initializeMethods 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 -
productSettingsKeys
The settings keys dealing with inventory. These keys correspond both to global settings stored in thesscSettingdatabase table, and product-specific settings defined in thesscProductSettingtable.
-
-
Constructor Details
-
BasicInventoryProcessor
public BasicInventoryProcessor()
-
-
Method Details
-
processAddItems
Description copied from interface:InventoryProcessorProcesses inventory as newOrderItems are added to a user's cart. Decrements inventory levels (in the memory objects) if products are set to be decremented upon being added to a cart. (Objects are updated in the database byBasicCartProcessor.processAddItems(Collection), which is what calls this method.)The default implementation of this method does the following:
- Loads the inventory settings in effect for each of the products
corresponding to the
OrderItems being added. - Calls
BaseBusinessProcessor.loadMatchingSkus(Collection, Collection, Collection)to load the skus corresponding to theOrderItems. - Calls
InventoryProcessor.processInventory(Collection, Map, Collection, String)to process the inventory. - Removes any order items that were rejected because one of their corresponding SKUs are out of stock.
- Adjusts the quantities of any order items whose quantities exceed the quantity in stock.
- Calls
CartProcessor.processQuantities(Collection)to update the cart with the new quantities.
- Specified by:
processAddItemsin interfaceInventoryProcessor- Parameters:
orderItems- TheCollectionofOrderItemobjects being added to the cart.- Returns:
- A
Mapcontaining results of the processing. In the default implementation, theMapis the same as the one returned byInventoryProcessor.processInventory(Collection, Map, Collection, String)(which this method calls). - Throws:
Exception- See Also:
- Loads the inventory settings in effect for each of the products
corresponding to the
-
processOnCheckout
Description copied from interface:InventoryProcessorChecks inventory for a user's cart during checkout. This step takes places as the user passes through checkout, but before submitting payment information. Makes sure that if products are to be decremented on checkout, no skus are out of stock. Inventory does not get decremented with this method.The default implementation of this method largely follows the same steps as
InventoryProcessor.processAddItems(Collection).- Specified by:
processOnCheckoutin interfaceInventoryProcessor- Parameters:
parameters- The most recent parameters submitted by the user.- Returns:
- A
Mapcontaining results of the processing. In the default implementation, theMapis the same as the one returned byInventoryProcessor.processInventory(Collection, Map, Collection, String)(which this method calls). - Throws:
Exception- See Also:
-
processOrderComplete
Description copied from interface:InventoryProcessorProcesses inventory for a user's cart as an order is completed. This step takes place after a successful payment processing. Inventory is decremented at this point for products set to be decremented on checkout.- Specified by:
processOrderCompletein interfaceInventoryProcessor- Parameters:
parameters- The most recent parameters submitted by the user.- Returns:
- A
Mapcontaining results of the processing. In the default implementation, theMapis the same as the one returned byInventoryProcessor.processInventory(Collection, Map, Collection, String)(which this method calls). - Throws:
Exception
-
loadProductSettings
Loads inventory settings for each of the products corresponding to a givenCollectionofOrderItems. Inventory settings are defined globally in thesscSettingdatabase table. They can be overridden product-by-product by settings defined in thesscProductSettingstable. This method resolves which products are set to override the global settings, and the resultingMapreflects the overridden settings. -
processInventory
public Map processInventory(Collection orderItems, Map productSettings, Collection matchingSkus, String behavior) throws Exception Description copied from interface:InventoryProcessorGenerically processes inventory, returning a Map with information about items and skus. Does not change the order items being checked.- Specified by:
processInventoryin interfaceInventoryProcessor- Parameters:
orderItems- ACollectionofOrderItemobjects being processed.productSettings- AMapofCollectionsrepresenting the inventory settings in effect for the products in theOrderItems.matchingSkus- ACollectionofMaps representing all the SKUs associated with theOrderItems.behavior- AStringrepresenting when inventory is to be decremented. Either "onAddingToCart" or "onOrderCompletion".- Returns:
- A
Mapcontaining results of the processing. In the default implementation, the keys of theMapinclude:skusToDecrement: ACollectionofMaps, each representing aSKUthat is to be decremented as result of the processing.decrementedSKUs: AMapwhose keys areOrderItemobjects and whose values are comma-separatedStrings representing the ids of theSKUobjects corresponding to theOrderItemthat are to be decremented. (Used to populate theOrderItem'sdescrementedSKUsproperty.)rejectedOrderItems: ACollectionofOrderItemobjects that have been removed from the user's cart due to their being out of stock.adjustedQuantities: AMapwhose keys areOrderItemobjects and whose values areStrings representing theOrderItems new quantity, after being adjusted because not enough inventory is available.newOOSSKUs: ACollectionofMaps, each representing aSKUthat has just reached its out of stock level as result of the processing.productsToDeactivate: ACollectionofStrings, each representing the id of aProductobject that should now be deactivated because aSKUassociated with it has just gone out of stock.lowStockEmails: ACollectionofMaps, each representing aSKUthat has reached its 'low stock' level, and should trigger a low stock email as a result.
- Throws:
Exception
-
processOrderItemAndSKU
-
defineInventorySettings
Description copied from interface:InventoryProcessorInspects a Product and returns a Map of useful variables related to the state of the product's inventory.- Specified by:
defineInventorySettingsin interfaceInventoryProcessorattributeSKUCollection- An optional Collection of attribute-only SKUs used to define the inventory settings that are returned.- Returns:
- A Map of variables related to the product's inventory.
-
postToEventBus
- Throws:
Exception
-