• Publisert
  • 1 min

Limitations in the discounts calculation in EPiServer Commerce

If you want to calculate discounts for products or related catalogs, you'll need to rewrite the default GetDiscountPrice function.

In EPiServer Commerce v7.x up to v8, most developers will likely use the default GetDiscountPrice function (from StoreHelper) for calculating discounts. But if you look at the code more closely, it will only calculate discounts for a variation (or the discount set on the direct parent catalog node for the variant) - not for products.

StoreHelper implements GetDiscountPrice like this:

Notice the if (price == null) check. That means you can only check for discount for a variant, and not the product itself. 

Also, note that the catalog nodes only include the products' parent catalog nodes - not related catalog nodes! For reference, related catalogs are catalog nodes that you link to from the product/variant. 

Another flaw is that the code is combining the catalognode names with a ";" but in the MarketingContext.EvaluatePromotions there is no split on ";". Therefore, if you send in more than one catalog node, you get no promotion hits as a result.

I know EPiServer is aware of the limitations to the promotion system and are working on a brand new promotion engine. Nevertheless, in the meantime you need to rewrite your code to include promotion checks on product level and related catalogs. 

NOTE: Workflows are coded this way also, so you need to rewrite the CalculateDiscountsActivity.CalculateDiscounts as well. You probably only need to do it on the line item level though.