To calculate or display a price in a Java Server Page, we used /atg/commerce/pricing/PriceItem. Three different types of prices are available: listPrice, salePrice, and amount. The amount price is the personalized price that is calculated dynamically by the pricing engine for a particular user at a particular time.

The PriceItem component calculates different prices for the same item depending on whether that item is displayed alone (for example, in the product template page of the catalog) or in the context of the shopping cart.

In the Pioneer Cycling store, we made a distinction between the list price for a product and the user’s price:

ATG Consumer Commerce enables you to set up pricing models in which a special price on one item depends on the purchase of another item (for example, buy a bike, get a helmet at half price). When the helmet is displayed alone, its full price (minus any single-item discounts) is displayed. Even if the customer has a bike in his shopping cart, entitling him to the helmet at half price, the helmet still displays outside the cart at list price because there is no way to know whether or not he will keep the bike in his cart. Therefore, promotional prices that depend on other purchases are only displayed in the shopping cart.

Here’s another example: on Mother’s Day the Pioneer Cycling store offers all women 20% off. The list price of a helmet is $100; the user’s price (for women) would be $80. The store also offers 50% off the price of a helmet with the purchase of a bike. However, the user’s price displayed on the product template page does not show this 50% discount, even if the she is purchasing a bike. This order-level discount is displayed on the Shopping Cart page. Order-level discounts and promotions are calculated with the pricing calculators and are discussed in the Promotions section of the Merchandising chapter.

PriceItem takes a SKU repository item as its item parameter. It outputs an element parameter that is of type CommerceItemImpl that we have renamed to SKU using the elementName parameter. This SKU parameter contains a personalized PriceInfo object with an amount property that is the lowest price available to the user at that time.

The Switch component invoked on the Format parameter allows many ways of displaying prices using a single JSP fragment. Site developers who do not require this flexibility may want to remove this Switch for improved performance.

The following example shows how we used the /atg/commerce/pricing/PriceItem component in the Pioneer Cycling Store to display prices in an extremely personalized way.

<!-- Display the price of the SKU: -->
  <dsp:droplet name="PriceItem">
  <dsp:param name="item" param="Product.childSkus[0]"/>
  <dsp:param name="elementName" value="Sku"/>
  <dsp:oparam name="output">

    <!-- Check which Format caller wants: -->
    <dsp:droplet name="Switch">
      <dsp:param name="value" param="Format"/>

      <!-- Displays the List Price: -->
      <dsp:oparam name="ListPrice">
        <dsp:valueof converter="currency"
             param="Sku.priceInfo.ListPrice"/>
      </dsp:oparam>

      <!-- Displays the SALE Price. Doesn't check if Item is on sale: -->
      <dsp:oparam name="SalePrice">
        <dsp:valueof converter="currency"
             param="Sku.priceInfo.SalePrice"/>
      </dsp:oparam>

      <!-- Displays the YOUR Price: -->
      <dsp:oparam name="YourOnly">
        <dsp:valueof converter="currency" param="Sku.priceInfo.amount"/>
      </dsp:oparam>

      <dsp:oparam name="All">
        <br><b>All price info (for debug):</b>
        <br><b>OnSale: </b><dsp:valueof param="Sku.priceInfo.onSale"/>
        <br><b>ListPrice: </b><dsp:valueof converter="currency"
               param="Sku.priceInfo.ListPrice"/>
        <br><b>SalePrice: </b><dsp:valueof converter="currency"
               param="Sku.priceInfo.SalePrice"/>
        <br><b>Amount: </b><dsp:valueof converter="currency"
               param="Sku.priceInfo.amount"/>
      </dsp:oparam>

      <dsp:oparam name="default">
        <!-- Check if Product is on sale: -->
        <dsp:droplet name="Switch">
          <dsp:param name="value" param="Sku.priceInfo.onSale"/>
          <dsp:oparam name="false"><dsp:valueof converter="currency"
               param="Sku.priceInfo.amount">
               no price</dsp:valueof></dsp:oparam>
          <dsp:oparam name="true">On Sale for <dsp:valueof
               converter="currency" param="Sku.priceInfo.salePrice">
               no price</dsp:valueof>
          </dsp:oparam>
        </dsp:droplet>
      </dsp:oparam>
    </dsp:droplet>
  </dsp:oparam>
  </dsp:droplet> <!-- PriceItem -->

The example above is an extremely resource-intensive way to display prices. If your site does not require dynamic generation of personalized pricing, you can remove any invocations to the PriceItem component for a large performance improvement.

The example below shows how you can use static pricing and still display listPrice or salePrice using the onSale property.

<dsp:droplet name="Switch">
  <dsp:param name="value" value="product.childSkus[0].onSale"/>
  <dsp:oparam name="false">
    <dsp:valueof param="product.childSkus[0].listPrice">
  </dsp:oparam>
  <dsp:oparam name="true">
    <dsp:valueof param="product.childSkus[0].salePrice">
  </dsp:oparam>
</dsp:droplet>
 
loading table of contents...