Example: Surcharge

This example shows how you can implement a surcharge by using the calculation framework.

Example description

When a shopper buys a product (for example, SKU FUOF-0101), extra $5 Special Handling and Shipping fee is charged along with other monetary amounts of the order (including total product, shipping, tax, and so on). Product detail in the development environment sample store:

  • Product Name: White Fabric Roll Arm Chaise
  • SKU (part number): FUOF-0101
  • Catentry_id: 10252
  • Special Shipping/handling fee (surcharge): $5.00 per item

Sample surcharge configuration data for the scenario:

  1. Create a calcode to represent 'special handling fee' under surcharge calculation usage. You can also change the description.

    insert into calcode (CALCODE_ID,CODE,CALUSAGE_ID,STOREENT_ID,GROUPBY,PUBLISHED,SEQUENCE,CALMETHOD_ID,CALMETHOD_ID_APP,CALMETHOD_ID_QFY,DESCRIPTION,DISPLAYLEVEL,FLAGS,PRECEDENCE) values (66666,'surcharge for special handling calcode',-6,-1,0,1,0,-707060103,-707060104,-707060102,'surcharge for special handling calculation code description',0,0,0)

  2. Create language-dependent description for calcode. It is used only for display purpose. You can also change the description. insert into CALCODEDSC (CALCODE_ID,LANGUAGE_ID,DESCRIPTION,LONGDESCRIPTION) values(66666,-1,'surcharge for special handling calculation code description in description table','longer version of surcharge for special handling calculation code description in the description table')
  3. Connect the calculation code with the product. You need to add a similar entry into your database for every product (catentry_id) that you want to have the surcharge associated with.

    insert into catencalcd (STORE_ID,CATENCALCD_ID,CATENTRY_ID,CALCODE_ID) values(10101,66671,10252,66666)

  4. Create the calculation rule for the calculation code. It represents charge rates.

    insert into calrule (CALRULE_ID,CALCODE_ID,SEQUENCE,COMBINATION,CALMETHOD_ID,CALMETHOD_ID_QFY,FLAGS,IDENTIFIER) values(66667,66666,0,2,-707060107,-707060106,0,1)

  5. Create the calculation scale properties.

    insert into calscale (CALSCALE_ID,QTYUNIT_ID,CODE,STOREENT_ID,CALUSAGE_ID,CALMETHOD_ID) values(66668,'C62','scale-surcharge for special handling',-1,-6,-707060108)

  6. Associate the calculation scale properties to the calculation rules.

    insert into CRULESCALE (CALSCALE_ID,CALRULE_ID) values(66668,66667)

  7. Create the ranges for the calculations.

    insert into calrange (CALRANGE_ID,CALSCALE_ID,CALMETHOD_ID,RANGESTART) values(66669,66668,-707060110,0)

  8. Create the surcharge value and associate it with the calculations. You can change the value of the surcharge with this SQL statement.

    insert into CALRLOOKUP (CALRLOOKUP_ID,CALRANGE_ID,VALUE) values(66670,66669,5)

  9. Change your storefront JSPs to display the surcharge. The Surcharge Adjustment example is taken from .../Stores/WebContent/ConsumerDirect/Snippets/Order/Inventory/CurrentAndTotalCharges.jsp
    <tr>
       <td colspan="5" class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_9">
       <fmt:message key="OrderSummary_TOTAL_PRODUCT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_DISCOUNT" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_SURCHARGE" bundle="${orderText}"
          />
       <br />
       <fmt:message key="OrderSummary_TOTAL_TAX" bundle="${orderText}" />
       <br
          />
       <c:if test="${showBaseShipAndAdjust}" >
          <fmt:message key="OrderSummary_TOTAL_ORIGINAL_SHIPPING"
             bundle="${orderText}" />
          <br />
          <fmt:message key="OrderSummary_TOTAL_SHIPPING_ADJUSTMENT"
             bundle="${orderText}" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <fmt:message key="OrderSummary_TOTAL_SHIPPING" bundle="${orderText}"
             />
          <br />
       </c:if>
       <fmt:message key="OrderSummary_TOTAL_SHIPPINGTAX"
          bundle="${orderText}" />
       </td>
       <td class="
       <c:out value="${rowClass}"/>
       price t_td"
       id="WC_CurrentAndTotalCharges_TableCell_10">
       <c:out value="${order_OrderDataBean.formattedTotalProductPrice}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalDiscountAdjustment}"
          escapeXml="false" />
       <br />
       <c:out
          value="${order_OrderDataBean.formattedTotalSurchargeAdjustment}"
          escapeXml="false" />
       <br />
       <c:out value="${order_OrderDataBean.formattedTotalTax}"
          escapeXml="false" />
       <br />
       <c:if test="${showBaseShipAndAdjust}" >
          <c:out value="${order_OrderDataBean.formattedShippingCharge}"
             escapeXml="false"/>
          <br />
          <c:out
             value="${order_OrderDataBean.formattedTotalShippingAdjustment}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:if test="${showAdjustedShipCharges}">
          <c:out value="${order_OrderDataBean.formattedTotalShippingCharge}"
             escapeXml="false" />
          <br />
       </c:if>
       <c:out value="${order_OrderDataBean.formattedTotalShippingTax}"
          escapeXml="false" />
       </td>
    </tr>
  10. You can get the surcharge value from OrderDataBean.getFormattedTotalSurchargeAdjustment().