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}"/>
</wcf:getData>

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.

http://www-01.ibm.com/support/knowledgecenter/SSZLC2_7.0.0/com.ibm.commerce.admin.doc/tasks/tpisetupjsps.htm?lang=en

<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}" />
</wcf:getData>

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.

<client-facade>
		<data-type-name>DisplayPrice</data-type-name>
		<class>com.ibm.commerce.price.facade.client.PriceFacadeClient</class>
		<method>getDisplayPrice</method>
</client-facade>
<expression-builder>
		<name>getDisplayPriceByCatalogEntryIdandPriceRuleName</name>
		<data-type-name>DisplayPrice</data-type-name>
		<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>
		<param>
			<name>accessProfile</name>
			<value>IBM_Store_DisplayPrice</value>
		</param>
		<param>
			<name>currency</name>
			<value></value>
		</param>
		<param>
			<name>quantity</name>
			<value>1</value>
		</param>
		<param>
			<name>uom</name>
			<value>C62</value>
		</param>
</expression-builder>

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(this.getCatalogEntryID());
strBufExpression.append("'] and PriceRuleIdentifier[ExternalIdentifier[Name='");
strBufExpression.append(LIST_PRICE_RULE_NAME);
strBufExpression.append("']] and UnitPrice[Price[@currency='");
strBufExpression.append(this.getCommandContext().getCurrency());
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.

References:

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s