SaaS CMS has officially launched! Learn more now.

Promotion Engine - calculating potential saving inside Evaluate



I am working with a custom promotion type, where I want to check the potential saving of the promotion, for each cart line item, inside the processors evaluate method. 

The aim is to check the potential saving, against a separate monetary value stored against the line item - if the potential saving isn't greater than the value stored against the line item, I'm attempting to not pass this RedemptionDescription back from the evaluate method. 

The problem I have is that the calculated savings in those Redemptions aren't available until its applied to the cart. 

How can I do this via the processor? 



May 29, 2019 10:43

Anyone? Even if the answer is no this is not possible :D 

I've tried applying the promotion to the cart to then get the calculated saving, but having trouble then removing it. I'm not really sure if this is the best way to go about this, or if there is a way I'm not aware of - potentially making use of InMemoryOrderGroup's?


May 31, 2019 10:52

Hope this is helpful:

I have a similar case where I had to compare the promotion price against the another price and get the lowest between the two. The idea is to create an in memory order group and then apply the coupon. You then run the promotion and you can then iterate through each line item to see the amount you save by applying the coupon.

Jun 03, 2019 22:21

Hi Siddharth, 

Apologies for the late reply to your post, I've been away on leave. I will take a look! :)



Jun 18, 2019 11:13

In the end I went with a method similar to Siddharth's he referred to in his post - thanks for sharing this!

Mine is a pivate method called from within a custom implementation of the promotion engine. 

We evaluate what redemptions we have available for the current line items (checking the affected entries and matching on current line item).

Our best price is stored against each line item, if that line has a best price available. 

We calculated the promotional saving per line from the redemptions we have available to us.

If the best price offers a greater saving than the promotions, we set the dsicount value for that line to best price discount (using TrySetDiscountValue), and for each promotion matching that line, we zero out the saved amount. 

I then perform some tidying up of existing line item promotions in the cart that yield no saving. 

This seems to work quite well for me as I'm only enabling a couple of line item promotions in the system, but I can imagine that if you are not disabling any of the built in promotions, this solution could become a whole lot trickier - specifically around the invalidation of promotions in the cart, when you have a cheaper price available to you. 



Jun 24, 2019 11:15
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.