Dynamic Pricing Configuration

Dynamic Pricing enables you to control pricing for SKUs based on external criteria specifc to a given request instead of simply reading from the BLC_SKU table. For example, you may have location based pricing determined by a user's currently selected store.

This pricing model is based on ThreadLocal attributes that are set up in a filter in the request and then utilized later.

The first step is to create our filter that will add certain attributes to the current request's sku pricing considerations

@Component("myDynamicSkuPricingFilter")publicclassMyDynamicSkuPricingFilterextendsAbstractDynamicSkuPricingFilter{@Resource(name="myDynamicSkuPricingService")protectedDynamicSkuPricingServiceskuPricingService;@OverridepublicDynamicSkuPricingServicegetDynamicSkuPricingService(ServletRequestarg0){returnskuPricingService;}@SuppressWarnings({"rawtypes","unchecked"})@OverridepublicHashMapgetPricingConsiderations(ServletRequestrequest){HashMappricingConsiderations=newHashMap();// Put some attribute into this map for use. For example, the current// customer or the currently selected storereturnpricingConsiderations;}}

Secondly, you will need to implement the DynamicSkuPricingService interface. Here is a sample implementation

@Service("myDynamicSkuPricingService")publicclassMyDynamicSkuPricingServiceImplimplementsDynamicSkuPricingService{@OverridepublicDynamicSkuPricesgetSkuPrices(Skusku,@SuppressWarnings("rawtypes")HashMapskuPricingConsiderations){MoneyretailPrice;MoneysalePrice;// Code here to determine what the retail price should be based on the// current sku and the skuPricingConsiderationsDynamicSkuPricesprices=newDynamicSkuPrices();prices.setRetailPrice(retailPrice);prices.setSalePrice(salePrice);returnprices;}}

Lastly, we need to instruct the application to use our filter, which means that we need to add it to all applicable filter chains. First, let's take a look at the blPostSecurityFilterChain. This filter chain is configured in applicationContext-filter.xml in the site project, and will typically look something like this: