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

How do I get a custom promotion to work in episerver commerce 10.7.2

Joe
Joe
Vote:
 

Hi,

I have defined a custom promotion in this manner (please ignore many spaces being stripped out - pasting into this site did this):

[ContentType(DisplayName = "Legacy Entry Promotion",

GUID = "1b2554c6-9f4c-4bb4-abe4-c5dce9c89c95",

AvailableInEditMode = false,

Description = "Used for defining a legacy entry promotion")]

[AdministrationSettings(CodeOnly = true, GroupName = "Marketing")]

[SiteImageUrl(ContentPaths.TemplateIconsFolderPath + "LegacyPromotions-logo-color.png")]

publicclassLegacyEntryPromotion : EntryPromotion

{

[Required]

[BackingType(typeof(PropertyNumber))]

[Enum(typeof(CommerceListValues.PromotionRestrictedToCommerceTransactionType))]

[Display(

Name = "Promotion is restricted to selected product",

Description = "Promotion is restricted to selected product",

Order = 100)]

publicvirtualCommerceListValues.PromotionRestrictedToCommerceTransactionType PromotionRestrictedToCommerceTransactionType { get; set; }

[Required]

[UIHint(UIHint.Textarea)]

[Display(

Name = "Markup for Product Page",

Description = "This is the HTML that gets displayed on the site, on an event page, or a membership page etc.",

Order = 200)]

publicvirtualXhtmlString MarkupForProductPage { get; set; }

[UIHint(UIHint.Textarea)]

[Display(

Name = "Markup for Linked Promo In Checkout",

Description = "This is the HTML that gets displayed to alert the user to the promo during the checkout process. If blank we use the Product Page HTML.",

Order = 300)]

publicvirtualXhtmlString MarkupForLinkedPromoInCheckout { get; set; }

[Required]

[BackingType(typeof(PropertyNumber))]

[Enum(typeof(CommerceListValues.PromotionType))]

[Display(

Name = "Promotion Type",

Description = "What promotion logic is used. If Linked, the promo applies only if all relations are present in the basket. Otherwise it applies to any related product independently.",

Order = 400)]

publicvirtualCommerceListValues.PromotionType PromotionType { get; set; }

//[PromotionRegion(PromotionRegionName.Discount)]

[Display(

Name = "Discount",

Description = "Depending on the Promotion Type chosen above, this will either be a percentage discount (e.g., 25) or an absolute monetary value (5.50). This is not required for TwoForOneCheapestFree offers.",

Order = 500)]

publicvirtualdecimal DiscountLegacy { get; set; }

[Display(

Name = "Extra Qualifiers",

Description = "Optional - used to narrow down the applicability of the promotion, e.g., to a particular membership product code. If a list, separate by commas. Include the code PM_CC or PM_DD to restrict the promotion to credit card or direct debit respectively.",

Order = 600)]

publicvirtualstring ExtraQualifiers { get; set; }

}

and then created a corresponding content item and made sure it satified all the conditions to be active.

I then created my processor:

public class LegacyEntryPromotionProcessor : EntryPromotionProcessorBase

{

protected override RewardDescription Evaluate(LegacyEntryPromotion promotionData, PromotionProcessorContext context)

{

throw new NotImplementedException();

}

protected overridebool CanBeFulfilled(LegacyEntryPromotion promotionData, PromotionProcessorContext context)

{

throw new NotImplementedException();

}

protectedoverridePromotionItems GetPromotionItems(LegacyEntryPromotion promotionData)

{

throw new NotImplementedException();

}

}

I then call the following at the appropriate point in the code.

var Rewards = GetPromotionEngine().Run((IOrderGroup)(EpiserverCommerceData.CartOld));

EpiserverCommerceData.CartOld.AcceptChanges();

At this point, I expected at least one of the functions defined in my LegacyEntryPromotionProcessor class to be called but

no joy - is there anything else that I need to do?

Thanks

#181557
Aug 24, 2017 11:26
Vote:
 

Hey,

Firstly, a tip, you can click on the </> icon in the editor here to get it C# formatted, it was quite a pain to read! :D

Looked through the code and couldn't find anything directly wrong, so just to double check that every requirement for it to be active is there:

  • Is the campaign Active and is not expired? 
  • Does the campaign have any visitor groups or a coupon code that prevents it from evaluating?
  • Is the discount Active and is has the same timespan as the campaign?
  • Is the market on the campaign the same as you have on the site?

You should be seeing a call to CanBeFulfilled when you do the IPromotionEngine.Run, if the PromotionEngine thinks your promotion is active. 

#181561
Aug 24, 2017 13:57
Vote:
 

Did you create a processor for your promotion? See: Custom Promotions

#181565
Aug 24, 2017 14:25
Joe
Vote:
 

Joel,

Thanks for the formatting tip. I'll make sure I use that next time.

One of the items on your checklist solved the problem - it now breaks in the processor - in the CanBeFulfilled function as you mentioned.

I had the campaign market set to the default market (which is what it is in the commerce manager) but when I changed it to ALL markets, it started

to work.

Thanks for your help.

#181566
Aug 24, 2017 14:33
Vote:
 

Jeroen, the processor is in the copy pasted code, albeit a bit hidden due to formatting! :)

Glad it worked! I get the question "why isn't this discount working" a fair bit, so I'm pretty familiar with the resolutions.

#181584
Aug 24, 2017 16:08
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.