Customization of the PunchOut message

KonaKart contains a PunchOut manager which can be configured in order to customize the XML message or HTML parameters sent by KonaKart. An example of how to do this can be found under the directory KonaKart\java_api_examples\src\com\konakart\apiexamples in a file called MyPunchOutMgr.java . The methods that must be overriden are called getData_OCI_XML and getData_OCI_HTML . An example is shown below. In order to use MyPunchOutMgr instead of the standard PunchOutMgr, you must add it to the KonaKart\custom\appn\src\com\konakart\bl directory; compile it and then replace konakart_custom.jar with the new jar created in the KonaKart\custom\jar directory. The konakart.properties file must also be edited to pick up the new manager:

konakart.manager.PunchOutMgr = com.konakart.bl.MyPunchOutMgr


/**
 * In your own implementation of the PunchOut manager you can override this method to provide
 * your own data for the various tags and tag attributes.
 * 
 * @param tagName
 *            The name of the tag as it appears in the XML
 * @param attrName
 *            The name of the attribute as it appears in the XML
 * @param orderProduct
 *            The OrderProduct object. In most cases it will have an attached Product object
 * @param options
 *            The PunchOut options
 * @return Returns the data that will be added to the message. Default values are used if null
 *         is returned
 */
protected String getData_OCI_XML(String tagName, String attrName, OrderProductIf orderProduct,
        PunchOutOptionsIf options)
{
    if (tagName.equals("Price") && attrName == null)
    {
        /*
         * Return an empty string to not display the price
         */
        return "";
    } else if (tagName.equals("ItemText") && attrName == null)
    {
        /*
         * The product description isn't returned in the standard implementation
         */
        if (orderProduct.getProduct() != null)
        {
            return "" + orderProduct.getProduct().getDescription() + "";
        }
    } else if (tagName.equals("LeadTime") && attrName == null)
    {
        /*
         * The lead time isn't returned in the standard implementation. It could be saved in one
         * of the Product custom fields.
         */
        if (orderProduct.getProduct() != null)
        {
            return orderProduct.getProduct().getCustom1();
        }
    }

    return null;

}


The OCI specification states that many of the possible XML tags are optional. By implementing the getData_OCI_XML() method as shown above, you can configure which tags are returned and can alter the data within them.


/**
 * In your own implementation of the PunchOut manager you can override this method to customize
 * the data being returned. The parameters are set using code similar to:
 * nvList.add(new NameValue("NEW_ITEM-DESCRIPTION[" + index + "]", op.getName()));
 * 
 * @param order
 *            The order
 * @param op
 *            The order product
 * @param nvList
 *            List of NameValue pairs. New data is added to the list.
 * @param index
 *            Index used for creating the name value pairs
 * @param scale
 *            Scale used for formatting the currency
 * @param options
 *            PunchOutOptions
 */
protected void getData_OCI_HTML(OrderIf order, OrderProductIf op, List<NameValue> nvList,
        int index, int scale, PunchOutOptionsIf options)
{

    // NEW_ITEM-DESCRIPTION
    nvList.add(new NameValue("NEW_ITEM-DESCRIPTION[" + index + "]", op.getName()));

    // NEW_ITEM-VENDORMAT
    if (op.getSku() != null)
    {
        nvList.add(new NameValue("NEW_ITEM-VENDORMAT[" + index + "]", op.getSku()));
    }

    // NEW_ITEM-EXT_PRODUCT_ID
    nvList.add(new NameValue("NEW_ITEM-EXT_PRODUCT_ID[" + index + "]", op.getProductId()));

    // NEW_ITEM-QUANTITY
    nvList.add(new NameValue("NEW_ITEM-QUANTITY[" + index + "]", op.getQuantity()));

    // NEW_ITEM-UNIT
    nvList.add(new NameValue("NEW_ITEM-UNIT[" + index + "]", "EA"));

    // NEW_ITEM-CURRENCY
    nvList.add(new NameValue("NEW_ITEM-CURRENCY[" + index + "]", order.getCurrencyCode()));

    // NEW_ITEM-PRICE Price of an item per price unit
    BigDecimal opPrice = op.getPrice().setScale(scale, BigDecimal.ROUND_HALF_UP);
    if (op.getQuantity() > 1)
    {
        opPrice = opPrice.divide(new BigDecimal(op.getQuantity()), BigDecimal.ROUND_HALF_UP);
    }

    nvList.add(new NameValue("NEW_ITEM-PRICE[" + index + "]", opPrice.toPlainString()));

    // NEW_ITEM-PRICEUNIT
    nvList.add(new NameValue("NEW_ITEM-PRICEUNIT[" + index + "]", "1"));

}


This method returns all of the name value pairs for a single Order Product object. It can be customized to return more or less attributes and to use custom attributes when required.