Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Customizing the price list stack lookup strategy

Customizing the price list stack lookup strategy

As mentioned in the topic on How pricing is applied, every shopper is given a price list stack, which contains the prices of all catalog items for that specific shopper at that specific time in the given currency. Internally, the system calls the PriceListLookupService's getPriceListStack method to generate and return the price list stack.

The actual process of building the price list stack is delegated to a strategy. Out of the box, Elastic Path Commerce provides one strategy implementation: the PLAStackLookupStrategy. The business logic of this strategy can be summarized as follows:

  • get all price lists assigned to the specified catalog and currency.
  • sort them by priority.
  • remove the price lists that do not match the selling context (based on the conditions in the shopper's tag set).

You can customize how price list stacks are created by creating a custom price list lookup strategy.

First, create a class that implements the PriceListStackLookupStrategy interface (in the com.elasticpath.common.pricing.service package). This interface defines a single method, which you must implement to return the shopper's price list stack:

PriceListStack getPriceListStack(String catalogCode, Currency currency, TagSet tagSet);
  • catalogCode is the GUID of the catalog the shopper is currently browsing
  • currency is the currency
  • tagSet is the set of Tagging Framework assigned to the shopper.

Next, in the com.elasticpath.core project, edit WEB-INF/conf/spring/service/service.xml. Add a bean definition for your custom strategy bean.

<bean id="customPLStackLookupStrategy" class="org.example.CustomPriceListStackLookupStrategy">
...
</bean>

Then, locate the priceListLookupService bean definition. Set the plStackLookupStrategy property to point to your custom strategy.

<bean id="priceListLookupService" class="com.elasticpath.common.pricing.service.impl.PriceListLookupServiceImpl">
    <property name="plStackLookupStrategy" ref="customPLStackLookupStrategy"/commerce-legacy/>
</bean>