ShoppingCart
component stores a user’s current and saved shopping carts. You can use
the ShoppingCart component’s properties and handle methods to create a
new shopping cart or retrieve one of the user’s saved shopping carts and
make it the user’s current shopping cart. Shopping cart is an Order in
an INCOMPLETE state. The shopping cart stores the information about the
items a given customer wants to order and their associated quantities
and prices. In addition, it stores the shipping and payment information
for the order.
ShoppingCart Component
The
ShoppingCart component is responsible for storing and managing a
customer’s shopping carts. It maintains the customer’s current shopping
cart that is used during the purchase process, and it stores any other
shopping carts that have been persisted by that customer. These shopping
carts are represented as atg.commerce.order.Order objects in the Oracle
ATG Web Commerce object model, and represented as order items in the
Order Repository.
By default, the /atg/commerce/ShoppingCart component is a session-scoped instance of atg.commerce.order.OrderHolder.
Managing Shopping Carts
Creating and Retrieving Shopping Carts
Adding Items to Shopping Carts
Adding Shipping Information to Shopping Carts
Adding Payment Information to Shopping Carts
Repricing Shopping Carts
Saving Shopping Carts
ShoppingCart.savedEmpty
property is checked to determine whether the current user has any saved
shopping carts. If the user doesn’t have any saved shopping carts, the
user can be given the option to create one. If the user has saved
shopping carts, the user can be given the option to select one of the
saved shopping carts.
OrderLookup servlet bean used to
retrieve a user’s incomplete orders (that is, shopping carts).
OrderLookup enables to retrieve a single order, all orders assigned to a
particular cost center , all orders placed by a particular user, or all
orders placed by a particular user that are in specific state, such as
INCOMPLETE. Once the desired shopping cart is moved to
ShoppingCart.current, you can use a ForEach servlet bean to iterate over
the commerce items in the cart and display them.
When
the user clicks the Add To Cart submit button, the form is processed,
the properties of CartModifierFormHandler are set, and the
handleAddItemToOrder method of CartModifierFormHandler is invoked. The
handleAddItemToOrder method adds the quantity (specified in
CartModifierFormHandler.quantity) of the selected SKU (specified in
CartModifierFormHandler.catalogRefIds and identified by repository ID)
to the current Order and then re-prices the Order.
Adding Multiple Items at Once
You
can create pages that allow users to add multiple items to the current
shopping cart in a single form submission. The items can refer to
different products, different SKUs, and have different quantities. The
CartModifierFormHandler contains an items property that allows you to
set per-item property values.
When the user clicks the
Add To Cart submit button, the form is processed, the properties of
CartModifierFormHandler are set, and the handleAddItemToOrder method of
CartModifierFormHandler is invoked. The handleAddItemToOrder method
iterates through the CartModifierFormHandler.items elements and adds an
item for each element quantity, using that element’s productId and
catalogRefId for the new item.
The
CartModifierFormHandler must be told how many elements to allocate for
the items array. This is done by setting the
CartModifierFormHandler.addItemCount property.
Overriding the Default Commerce Item Type
By
default, Oracle ATG Web Commerce supports three types of commerce
items. One corresponds to regular SKUs. The other two correspond to
configurable SKUs and their subproperties
The
commerceItemType property of CartModifierFormHandler determines what
type of commerce item is created by addItemToOrder. Normally,
commerceItemType is set to “default.” You can specify a different
commerce item type in the CartModifierFormHandler configuration file or
in a form input field. If you add multiple items in a single form
submission, you can override the
CartModifierFormHandler.commerceItemType setting for an individual item
by including a hidden input field to set
CartModifierFormHandler.items[n].commerceItemType.
Values for commerceItemType must match keys in /atg/commerce/order/OrderTools.commerceItemTypeClassMap.
The
CartModifierFormHandler.addItemToOrder method has built-in support for
some types of commerce item extensions. If your sites have extended
commerce items with primitive data type properties, you can supply
values for those properties by associating form fields with the
CartModifierFormHandler.value Dictionary.
Removing Items from the Shopping Cart
The
CartModifierFormHandler.deleteItems method deletes items that have
their CommerceItemIds in the RemovalCommerceIds array. The quantity of
the line item that contains the removal request is compared with the
total quantity of the commerce item on the page. If the quantities
match, the CommerceItemIds is kept in the RemovalCatalogRefIds array to
be removed from the page. If the quantities do not match, the system
adjusts the quantity accordingly and removes the CommerceItemId from the
RemovalCommerceIds array.
Before the deleteItems
method removes all items with IDs in the removalCommerceIds array, it
runs the prepareLineItemsForRemoval method to return the valid array of
IDs to remove, as well as verify if the IDs require partial or complete
removal. The prepareLineItemsForRemoval method populates the
removalLineItem map that contains a set of IDs and reduction-quantity.
The reduction-quantity is subtracted from the original quantity to
provide the new quantity available in the shopping cart. Once the
deleteItems method removes the necessary elements, it processes the
removalLineItems map to adjust the quantities of items that were
partially removed.
Adding Shipping Information to Shopping Carts
Creating
a list of shipping groups for potential use in the current order. The
user can select from among these shipping groups when checking out the
order.
- Specifying the shipping groups to use with the current order.
- Selecting the shipping methods, such as Ground or Next Day, for the order’s shipping groups.
ShippingGroupFormHandler form handler and
AvailableShippingMethods servlet bean, do not re-price a given Order.
Consequently, if you enable customers to make order changes that affect
order price through either mechanism, you should reprice the given Order
using the RepriceOrderDroplet servlet bean before displaying its price
to the customer.
If an order contains any gift items,
ShippingGroupDroplet and ShippingGroupFormHandler treat those items and
their shipping information differently from other items.
Creating Potential Shipping Groups
Shipping groups for potential use in an Order in one of two ways:
- from information gathered from the user via forms
- from information stored in the user’s profile
To create shipping groups from
information obtained from the user via forms, use
CreateHardgoodShippingGroupFormHandler and
CreateElectronicShippingGroupFormHandler. These form handlers create,
respectively, hard good and electronic shipping groups. Additionally, if
the addToContainer property of the form handlers is set to true (which
it is by default), they add the new shipping group to the
ShippingGroupMapContainer and make it the default shipping group in the
container. The ShippingGroupMapContainer stores the shipping groups
available for use in the current order. Once the shipping group is added
to the ShippingGroupMapContainer, the user can use it when checking out
the current order.
Adding Payment Information to Shopping Carts
Adding payment information to shopping carts involves the following sub-processes:
- Creating a list of payment groups for potential use in the current
order. The user can select from among these payment groups when checking
out the order.
- Specifying the payment groups to use with current order.
Creating Potential Payment Groups
You can create a list of payment groups for potential use in an Order in one of two ways:
- from information gathered from the user via forms
- from information stored in the user’s profile
To create payment groups from
information obtained from the user via forms, use
CreateCreditCardFormHandler and CreateInvoiceRequestFormHandler. These
form handlers create, respectively, CreditCard and InvoiceRequest
payment groups. Additionally, if the addToContainer property of the form
handlers is true (which it is by default), they add the new payment
group to the PaymentGroupMapContainer and make it the default payment
group in the container. The PaymentGroupMapContainer stores the payment
groups available for use in the current order. Once the payment group is
added to the PaymentGroupMapContainer, the user can use it when
checking out the current order.
Repricing Shopping Carts
Adding
Items to Shopping Carts, CartModifierFormHandler automatically reprices
a shopping cart when it is used to add items to the cart. (Note that it
also reprices the cart when it is used to remove items from the cart.)
However,
you’ll need to reprice shopping carts via some other mechanism if
customers can make changes that affect order price through other form
handlers that do not reprice shopping carts (for example, by making
shipping changes via the form handlers that create and manage shipping
groups), or if the shopping carts are modified through some other means
in ways that affect order price, such as the delivery of a promotion via
a scenario.
Any pages where you need to reprice a
shopping cart, but you cannot do so through a form action and
corresponding handle method, use the RepriceOrderDroplet servlet bean.
In fact, you can use the RepriceOrderDroplet servlet bean to reprice a
customer’s shopping cart every time the customer accesses a shopping
cart page. This ensures that the customer always views accurate pricing
information as he or she makes changes to cart.
The
RepriceOrderDroplet servlet bean takes one required input parameter,
pricingOp, that should be set to the pricing operation to execute. The
possible pricing operations are defined in
atg.commerce.pricing.PricingConstants, and they include the following:
ORDER_TOTAL
ORDER_SUBTOTAL
ORDER_SUBTOTAL_SHIPPING
ORDER_SUBTOTAL_TAX
ITEMS
SHIPPING
ORDER
TAX
NO_REPRICE
Typically, the pricingOp input parameter is the only parameter you need to specify when using RepriceOrderDroplet.
<dsp:droplet name="RepriceOrderDroplet">
<dsp:param value="ORDER_SUBTOTAL" name="pricingOp"/>
</dsp:droplet>
Saving Shopping Carts
SaveOrderFormHandler
to save the user’s current shopping cart, add the shopping cart to the
user’s list of saved carts in ShoppingCart.saved, and construct a new,
empty cart as the user’s current shopping cart in ShoppingCart.current.
Additionally,
you can use the description property of SaveOrderFormHandler to set the
description property of the Order; this enables users to name their
shopping carts with meaningful names. If the user doesn’t provide a
descriptive name, then the SaveOrderFormHandler automatically creates
one using the user’s locale and the current date and time.
The following JSP code illustrates the use of SaveOrderFormHandler.
<dsp:importbean bean="/atg/commerce/order/purchase/SaveOrderFormHandler"/>
Order # <dsp:valueof bean="ShoppingCart.current.id"/>
<dsp:form action="saved_orders.jsp">
Enter a name to identify this order:<p>
<dsp:input bean="SaveOrderFormHandler.description" type="text"/>
<dsp:input bean="SaveOrderFormHandler.saveOrder" value="Save order"
type="submit"/>
<dsp:input bean="SaveOrderFormHandler.saveOrderSuccessURL"
value="../user/saved_orders.jsp" type="hidden"/>
<dsp:input bean="SaveOrderFormHandler.saveOrderErrorURL"
value="../user/save_order.jsp" type="hidden"/>
</dsp:form>