November Happy Hour will be moved to Thursday December 5th.

Custom Promotions and finding their custom type

Vote:
 

Ihave two custom promotions setup which apply two seperate Episerver abstract classes; both of which I have also inheriting from an interface:

    public class PromoA: BuyQuantityGetOrderDiscount, ICustomPromo

    public class PromoB: BuyQuantityGetSelectedItemsDiscount, ICustomPromo

When I get to the point of checkout I get the generic PromotionData back but it doesn't tell me what custom promotion it is.

Does anyone know of a way to get this information.

Ie I need to know if the PromotionData is based on Promo A or Promo B.

Otherwise I have to go down the route of trying to cast the PromotionData to either of these type - and that will get very messy.

#250924
Mar 18, 2021 16:26
Vote:
 

Could you load the PromotionData up and then check the FullName of the type? Something like:

var appliedPromotion = ContentLoader.Get<PromotionData>(PromotionGuid)
var promotionFullName = appliedPromotion.GetType().FullName

if(FullName.Contains("PromoA")) doSomething()
if(FullName.Contains("PromoB")) doSomethingElse()
#250955
Edited, Mar 19, 2021 2:36
Dan Butcher - Mar 19, 2021 8:34
Investigating this option - thanks for the suggestion :)
Vote:
 

Can't you just check

if (promoA is BuyQuantityGetOrderDiscount) 

{

}

else if (promoA is BuyQuantityGetSelectedItemsDiscount)

{

}

#250966
Mar 19, 2021 8:29
Dan Butcher - Mar 19, 2021 8:34
I didn't want to do it this way because it we would have to have if statements for all our Custom promotions which felt messy.
Quan Mai - Mar 19, 2021 8:47
well, it's up to you, but you have compile time type check, and clear intention of what you are trying to do.
You might also want to move certain logic into your processors
* 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.