Extending Sitecore Commerce Pricing Pipeline

VP, Sitecore Practice
  • Twitter
  • LinkedIn

Extending Sitecore Commerce Pricing Pipeline

During a recent project, I was involved in creating a connector for Sitecore Commerce and Insite Commerce (External Commerce System). There were a number of pipelines where I had to make a design choice based on how Insite works.

In this blog, I am going to talk about the pricing pipeline in sitecore Commerce. Pricing pipeline has three methods GetProductPrices, GetBulkProductPrices, GetCartTotal.

GetCartTotal is pretty straightforward if the external commerce system gives you the cart total and you don t have to calculate or write an algorithm to calculate it. You may have to use custom properties because Sitecore commerce Cart s Total object model does not have a property for Shipping and handling total.

And by custom property, I mean adding a property in the Total object. Something like:

cart.Total.Properties["ShippingAndHandling"] = GetShippingAndHandlingTotalFromExternalCommerceSystem();

GetProductPrices allows you to query the ECS and get the price of an individual product. Now, what to do if you have multiple prices for a single product. The prices could vary based on the customer. There could be a price matrix associated with the product.

With Insite Commerce as ECS, I did not have to worry about Customer based pricing. Insite commerce has a solid pricing engine that returns customer based price (Actual Price or Customer Price).

So, that leaves us with two questions:

  1. How do I get a list price and a customer price in one method call?
  2. How do I translate any product price matrix data from ECS to sitecore commerce?

How do I get a list price and a customer price in one method call?

Thanks to sitecore commerce! With one call to GetProductPrices, I get all the different prices (List, Actual, Customer, Discount , etc). Here s how:

When you are preparing the GetProductPricesRequest request, add the price types to PriceTypeIds property. Let s say you pass Customer and List as the price types.

The implementation of the processor should read the PriceTypeIds as string array, get the prices from ECS and prepare a result object with a dictionary of prices, the key being the price type.

So, if the ECS has a customer price of 10 and a list price of 12, the result object will have a price dictionary with two entries, { Customer , 10} and { List , 12 }.

If you don t pass any price type in the request, default the implementation to return the List price.

All the SetPricingResult method has to do is, prepare a dictionary of pricing data.

On the website, I can call the pricing provider with both the price types. I used Actual and Regular prices

You can see that the commerce connect didn t have a property to accept unit of measure and the prices vary by unit of measure. So a custom property was used.

How do I translate any product price matrix data from ECS to sitecore commerce?

There could be break prices or a price matrix for a product. Let s say if you buy 10, you get it at 20% discount and the price is USD 80 instead of USD 100.

If you pass the correct quantity, the price engine returns you the correct discounted price. But what if you want to show the price matrix on the website?

Use the PriceConditions model in the Price model to populate any conditional pricing you want to return to the website.

GetBulkProductPrices allows you to get pricing data for multiple products in a single call. This is mostly used on a catalog page. Here s the catch: You can query only one type of price type.

The key difference between individual price and bulk price processor is that you can query only one type of product price (Customer or List, etc) in bulk product price.

The result of Bulk Product Price is of type IDictionary. The key in this case is the product id and the value is the price. So, the dictionary is a list of products with its price. The price depends on the price type you set in the request. You cannot have multiple price types returning from the same product in this case.

Related Blogs

Latest Blogs