Passing additional parameters to price rule engine

Customized parameters can pass to the price rule element, by using the request properties in the command context, and the extended data map in the runtime parameters for price rules.

You can customize parameters easily to pass through a price rule element, such as valuePoints.

How to pass a new parameter to a price rule element

Here is an example to show how to pass a new parameter, valuePoints, into a price rule element.

  1. Put the parameter into the request properties map in the command context in a controller/task command. The parameter must be in the request properties map before it calls the price rule engine. An example of customized code is as follows:
    In /WebSphereCommerceServerExtensionsLogic/src/com/mycompany/commerce/price/facade/server/commands/
    // Put extra parameter into request properties in command context
    		TypedProperty reqProps = getCommandContext().getRequestProperties();
    		if (reqProps == null) {
    			reqProps = new TypedProperty();
    		// get value points value from xpath expression
    		int valuePoints = MyFetchEntitledPriceCmdHelper.getValuePointsFromXpathExpression(getSearchExpression());
    		reqProps.put(MyPriceFacadeServerConstants.XPATH_STRING_PRICING_VALUEPOINTS, valuePoints);
  2. In the price rule element command, use similar code similar to retrieve the parameter:
    In /WebSphereCommerceServerExtensionsLogic/src/com/mycompany/commerce/price/rule/commands/element/
    // Get extra parameter
    			Map extDataMap = (Map)getRuntimeParametersMap().get(PriceRuleConstants.PARAMETER_PRICERULE_EXTRA_DATA_MAP);
    			if (extDataMap != null){
    				TypedProperty requestProps = (TypedProperty)extDataMap.get(PriceRuleConstants.PARAMETER_PRICERULE_EXTRA_DATA_REQUEST_PROPERTIES_MAP);
    				if (requestProps != null){
    					int valuePoints = ((Integer)requestProps.get(MyPriceFacadeServerConstants.XPATH_STRING_PRICING_VALUEPOINTS, null)).intValue();
    					if (valuePoints != 0){
    						// Get the original base offer price
    						MonetaryAmount baseOffer = (MonetaryAmount)super.getReturnedObject().get(PriceRuleConstants.RETURNED_OBJECT_OFFERS);
    						BigDecimal priceInOffer = baseOffer.getValue();