Fetching prices from pricerule in java

This week I've looked into fetching list prices using the list price rule defined in commerce. There isn't any GUI to set the rule used for your list prices. And if you just fetch the value from CatalogEntryDataBean getListPrice you will get the value in the table LISTPRICE which should be deprecated in FEP6.

You could try to use the CatalogEntryType to fetch values from the web service in your JSP pages

<wcf:getData type="com.ibm.commerce.catalog.facade.datatypes.CatalogEntryType" var="catentryItem1" expressionBuilder="getStoreCatalogEntryAttributesByID">
    <wcf:contextData name="storeId" data="${param.storeId}"/>
    <wcf:param name="catEntryId" value="${itemEntry.itemID}"/>
    <wcf:param name="dataLanguageIds" value="${WCParam.langId}"/>

Even when you use this newer interface the ComposeListPrice function will still go back and fetch the price from the LISTPRICE table. So I looked into what the recommended way was to fetch list prices from a price rule and found that IBM has a page describing how to customize JSP store pages and fetch the list price of an catalog entry using the DisplayPriceType.


<wcf:getData type="com.ibm.commerce.price.facade.datatypes.DisplayPriceType" var="displayPriceType" expressionBuilder="getDisplayPriceByCatalogEntryIdandPriceRuleName">
	<wcf:contextData name="storeId" data="${param.storeId}"/>
    <wcf:param name="catEntryId" value="${catalogEntryIdForPriceRule}" />
	<wcf:param name="priceRuleName" value="${defaultDisplayPriceRuleName}" />

But when you want to do the same in java you need to look at the configuration of the web service. In this case we look for the expression builder "getDisplayPriceByCatalogEntryIdandPriceRuleName" inside of Stores/WebContent/WEB-INF/config/com.ibm.commerce.price-fep/get-data-config.xml.

		<expression-template>{_wcf.ap=$accessProfile$}/DisplayPrice[(CatalogEntryIdentifier[UniqueID='$catEntryId$'] and PriceRuleIdentifier[ExternalIdentifier[Name='$priceRuleName$']] and UnitPrice[Price[@currency='$currency$'] and (Quantity='$quantity$' and Quantity[@uom='$uom$'])])]</expression-template>

By checking this configuration we should look for some keys. First of we have the expression template that we use to build our expression. The params defined here could be set to the template statically or you could fetch some dynamic values depending on your need. The values defined above are the static values used by this expression builder.

Then we look at the client facade tag to check what implementing class and method to use to fetch our data. This makes it a straight forward process to rebuild this configuration into java.

StringBuffer strBufExpression = new StringBuffer("{_wcf.ap=IBM_Store_DisplayPrice}/DisplayPrice[(CatalogEntryIdentifier[UniqueID='");
strBufExpression.append("'] and PriceRuleIdentifier[ExternalIdentifier[Name='");
strBufExpression.append("']] and UnitPrice[Price[@currency='");
strBufExpression.append("'] and (Quantity='1' and Quantity[@uom='C62'])])]");

PriceFacadeClient pfc = new PriceFacadeClient();
List priceList = pfc.getDisplayPrice("_wcf:XPath", strBufExpression.toString());

Above we use the PriceFacadeClient to fetch data with the getDisplayPrice method. We give this method a template type in this case _wcf:XPath and an expression build from the configuration above. You'll get an list of DisplayPriceImpl class defined by the data type above. The rest to fetch the actual value is navigating this list of values fetching your data for future processing.

Another thing to notice here is that it will fetch the prices for the unit C62 and all conversions that could be made in the QTYCONVERT.


Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.