Passing additional parameters to price rule engine

Customized parameters can simply pass to the price rule element, 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

This 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 needs to be in the request properties map before calling the price rule engine. An example of customized code is as follows:
    In /WebSphereCommerceServerExtensionsLogic/src/com/mycompany/commerce/price/facade/server/commands/ExtFetchEntitledPriceByCatentryIdCmdImpl.java:
    // Put extra parameter into request properties in command context
    		TypedProperty reqProps = getCommandContext().getRequestProperties();
    		if (reqProps == null) {
    			reqProps = new TypedProperty();
    			getCommandContext().setRequestProperties(reqProps);
    		}
    		
    		// 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 code similar to this to retrieve the parameter:
    In /WebSphereCommerceServerExtensionsLogic/src/com/mycompany/commerce/price/rule/commands/element/MyPriceListElementCmdImpl.java:
    // 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(PriceRule
    Constants.RETURNED_OBJECT_OFFERS);
    						BigDecimal priceInOffer = baseOffer.getValue();