store.war/cart/gadgets/cartItems.jsp is responsible for rendering the line items that appear on the shopping cart page for the cart contents. This JSP page works similarly to the store.war/cart/json/cartItems.jsp page in that it iterates over each CommerceItem in the cart, passing the current CommerceItem to the /atg/commerce/promotion/GiftwithPurchaseSelectionsDroplet, to determine if the item has a gift with purchase marker. If there isn’t one, the current CommerceItem is not a gift and the GiftWithPurchaseSelectionsDroplet’s empty open parameter is rendered. This is where the code for rendering standard CommerceItem objects resides.

If the current CommerceItem does have a gift with purchase marker, the GiftWithPurchaseSelectionsDroplet produces a GiftWithPurchaseSelection bean for it. store.war/cart/gadgets/cartItems.jsp uses the same logic as store.war/cart/json/cartItems.jsp to calculate the portion of the CommerceItem that is free versus the portion that is not. It adds the automaticQuantity, targetedQuantity, and selectedQuantity values provided by the bean to arrive at a total gift quantity, then it subtracts the total gift quantity from the overall CommerceItem quantity. cartItems.jsp stores this value in a missedQty variable and renders a line in the shopping cart for the CommerceItem, using the missedQty value in the Quantity column. This line represents the portion of the CommerceItem that is not a gift.

To handle the automaticQuantity portion of the CommerceItem, cartItems.jsp uses a forEach loop with a begin attribute of 1 and an end attribute of automaticQuantity. Each pass through the loop calls the store.war/cart/gadget/giftItem.jsp once to render an individual line in the shopping cart. In this way, cartItems.jsp renders, for example, three lines in the shopping cart for an automaticQuantity of three. cartItems.jsp repeats this process for the targetedQuantity and selectedQuantity portions of the CommerceItem. These lines together represent the gift portion of the CommerceItem that has been selected (i.e., that is tied to a SKU and is not represented by a gift placeholder).

To render the gift placeholders, cartItems.jsp includes the store.war/cart/gadgets/giftPlaceholders.jsp page. giftPlaceholders.jsp calls the GiftWithPurchaseSelectionsDroplet again, but this time it passes in the order without the current CommerceItem, so the GiftWithPurchaseSelectionsDroplet returns GiftWithPurchaseSelection beans for any gifts in the entire order. giftPlaceholders.jsp also passes in the onlyOutputAvailableSelections parameter so that the GiftWithPurchaseSelectionsDroplet returns only those GiftWithPurchaseSelection beans whose quantityAvailableForSelection is not zero. These are the beans for which gift placeholders need to be rendered.

Next, giftPlaceholders.jsp iterates through each GiftWithPurchaseSelection bean and retrieves the quantity of gifts still to be selected from the bean’s quantityAvailableForSelection property. giftPlaceholders.jsp uses this value as the end attribute in a forEach loop that renders an individual gift placeholder, on its own line in the shopping cart, for each outstanding gift selection. For example, two gift placeholders are rendered on two separate lines for a GiftWithPurchaseSelection bean whose quantityAvailableForSelection value is two.

The following illustration shows a customer’s shopping cart after she has added the suede blazer and qualified for two free gifts. Notice that each gift placeholder resides on its own line:

This illustration is described in the preceding text.

In Commerce Reference Store, each gift placeholder in the shopping cart represents a single gift selection. Note that this behavior is different from how the rich cart behaves, where gift placeholders are aggregated into a single line item to conserve on space. The shopping cart, however, is where the user interface for choosing, editing, or removing free gifts resides, so the gift placeholders themselves must be tied to a single gift selection. The gift selection interface is described in the following section, Choosing Gifts in Commerce Reference Store.

Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices