Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Shopping cart

Shopping cart

In addition to containing items a customer wants to buy, the shopping cart domain object acts like an order form that contains or calculates most of the information about the order the customer is assembling as they shop and check out.

Key classes and files

  • ShoppingCart - Represents the customer's shopping cart.
  • CartDirector - Responsible for adding and updating items in and persisting the shopping cart.
  • ShoppingItem - Represents a quantity of an item (SKU) in a shopping cart, wish list, order, etc.
  • CartItem - Subclass of ShoppingItem representing a quantity of a SKU in a shopping cart.
  • ShoppingItemConfigControllerImpl - Delegates view and add-to-cart requests to a ProductConfigController implementation to allow Product personalization. Its productTypeNameControllerMap contains the available ProductConfigController objects mapped to the product type name.
  • ShoppingItemFormBean - The interface to implement for a personalized product type.
  • viewCart.vm - Velocity template for displaying the contents of the shopping cart. (For product personalization, an additional template is required for each personalized product type.)
  • viewCart.js - Contains Javascript for AJAX updates to shopping cart data.

Cart items

The products a customer wants to buy are kept in the ShoppingCart as a collection of CartItem objects. A CartItem represents a quantity of a specific product SKU that is to be purchased. A CartItem can also be thought of as a single row or line item on an order form. A CartItem can have "child" cart items that are dependent on it. In this case, the items are to be displayed together and the child cart item cannot exist in the cart independently of its parent. Therefore, child cart items must be removed when the parent cart item is removed. The ShoppingCart contains methods for adding and removing CartItem objects. Dependent cart items typically arise from the targets of ProductAssociation objects, and the cart contains a convenience method for adding a cart item from a product association.

Calculations

A major responsibility of the ShoppingCart is to compute values derived from the set of CartItem objects. Examples include the subtotal, total, taxes, and shipping costs.

Cart persistence

All shopping carts are persisted. After an item is added or removed, clients should request that the ShoppingCartService update the record of the shopping cart. However, only the cart items are saved. Upon retrieval from storage, several values may be recalculated, but selections such as the shipping method and billing address are no longer available. Therefore, a customer can continue shopping with a newly retrieved saved cart, but the checkout process must be restarted during each session.

Wish list

Wish list items are stored in the user's WishList as a collection of ShoppingItem objects. A wish list item's quantity is always equal to one. Wish list items are added to the wish list via the AddToWishListControllerImpl, which calls the addSkuToWishList() method of the CartDirector.

The WishListService is responsible for sending the wish list to others via the EmailService. When a shopper views a WishList, the system uses the viweWishList.vm file to render it.

Product personalization

It is possible to create configurable product types, such that shoppers can provide some customization details, which will be passed along through the checkout process and stored in the database. For more information, see Product personalization.