Don't miss out Virtual Happy Hour today (April 26).

Try our conversational search powered by Generative AI!

Episerver 10.8.0.0: Is there a way to retrieve the original promotion data for the promotion that is applied for a order.

Vote:
 

Hi Can we retrive the promotion data that is saved in CMS.

When you use a promotion on a order, and if it is a percentage discount, we want to retrieve the percentage value. Liek 10% or 40%. The PromotionInformation and PromotionInformationEntry has teh dollar amount only.

#183351
Oct 11, 2017 22:52
Vote:
 

Hm. Good question.

You can check if the applied promotion had the rewardtype "percentage" by looking at PromotionInformation.Percentage. But exactly which percentage that was used at that point in time is probably not accessable. But it's a good point, it should actually be accessible. You can do some tricky workarounds tho:

  • (not recommended) Load the promotion from PromotionInformation.PromotionGuid and read the values from there. If you change the promotion after it was applied the values will be faulty, hence why I don't recommend it.
  • (recommended) Add it yourself in the PromotionInformation.AdditionalInformation. Create your data model and serialize it to JSON and store it by registering an instance of IAdditionalPromotionInformationCreator and implementing the logic in CreateAdditionalInformation. In that you have the AdditionalPromotionInformationContext as a param where you can get the actual promotion (that was being applied, no risk of differences) in AdditionalPromotionInformationContext.PromotionData.
#183365
Oct 12, 2017 6:31
Vote:
 

Hi,

What would you use that information for?

#183366
Oct 12, 2017 8:07
Vote:
 

A use case that comes to mind is the order confirmation mail, where you would want to maybe generate a "-20%" graphic from the promotion to show that you bought it during maybe some exclusive discount period or something like that. Sure, might be covered in the name/description, but if you want to do that use case you would have to extract the % from there or something

#183367
Oct 12, 2017 8:11
Vote:
 

Joel!

We are doing some workaround on our end. The work around we have is we calculate the percentage based on SavedAmount against the original price. But our client uses promotions heavily and they combine multiple coupons. And in seom scenarios our workaround breaks. 

Hence we were trying to access the original data.

Storing the promotion actual percentage with the PromotionInformation would be ideal. But for now if am able to retrieve the promotion object with promotion GUID then that would work for now as well. We can make sure the promotion doesn't change once its out there. And it usually doesn't change. We create a new one if needed.

But  in epi 10+ there is no data in promotion  as this is stored on the  CMS side. Are we able to access this data by any means?

We have normal carts. We are using non serialised carts.

#183385
Oct 12, 2017 15:35
Vote:
 

Quan!

Our client {Mud pie} has a complex bacckoffice system. They use Aprise and have their own logic of processing the orders. When an order is placed on our epi website we export these orders in text file to their apprise backoffice system.

They have a very complex business rules for this file. And they need the actual percentage value for any promotion used in this file vs the dollar amount that epi saves. So we do need this.

#183386
Oct 12, 2017 15:38
Vote:
 

Seems to be just 

IContentLoader.Get<PromotionData>(promotionGuid)

if that was your question?

#183387
Oct 12, 2017 15:42
Vote:
 

YEs, that was exactly my question. And I have searched for this so much, but couldn't find anything.

Will try this.

Thank you!

#183388
Oct 12, 2017 15:44
Vote:
 

Oh sorry! I lied. Actually how do we get the percentage value from this object is the question.

#183389
Oct 12, 2017 15:55
Vote:
 

When you get back the PromotionData, you can try to cast it to your promotion type, and get the percentage value here.

If you just need the percentage, store it in AdditionalInformation. But that would not be very future proof because you might need to store something else in the future.

There is no easy, nice and future proof way here, unless you can make sure that a promotion is never changed or deleted, but disabled. 

#183390
Oct 12, 2017 16:01
Vote:
 

Well it can be future proof if you serialize it and manage the data class in C#! You can't really change the properties in the class without migration and you'd need to do checks if it's null or not depending if it's a new property, but somewhat managable future proofiness :P

#183391
Oct 12, 2017 16:08
Vote:
 

Quan 

To make sure I understand, we are using epi promotion. Nothing cutomised. Do I still need to cast? Cast it to what object?

What I believe here is I need access to RewardDescription so I can get UnitPercentage Value. But unfortunately this is not acessible. I am right?

#183404
Oct 12, 2017 17:25
Vote:
 

The object you're getting, PromotionData, is the base class for all promotions in epi. So it won't have anything specific. You need to find out which promotion you're using, including the epi built in, and then cast to that one, make sure it isn't null and get the values from there.

You can find a list of epi promotions in the EPiServer.Commerce.Marketing.Promotions namespace, check http://world.episerver.com/documentation/class-library/?documentId=commerce/10/C42F6B08.

#183407
Oct 12, 2017 17:35
Vote:
 

Ah Okay! That would be tedious though to check for each promotion type. It can be any promotion.

Will try it to work with that. And also make sure to make it future proof (hopefully)

Thank you both!

#183411
Oct 12, 2017 17:58
Vote:
 

Here's how you can access promotion data

var promotionInfo = purchaseOrder.GetFirstForm().Promotions.FirstOrDefault();

#292863
Dec 08, 2022 22:17
* 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.