Deleting promotions from code

Vote:
 

Hi,

We have a requirement of creating promotions from code based on an API (we receive the price and sku and create a promotion for it)

I managed to create the promotions from code basically following the blod post from: http://vimvq1987.com/2016/06/beauty-episerver-commerce-new-promotion-system/

Now I'm trying to delete/remove the applied/expired promotions (in order to not be taken into consideration when the promotions are applied)

All I could find is to get promotion from the link https://world.episerver.com/documentation/Items/Developers-Guide/Episerver-Commerce/9/Marketing/promotions-engine/

Get promotions and items for campaign

ServiceLocator.Current.GetInstance().GetPromotionItemsForCampaign(campaignLink)
but that doesn't seem to give me if the promotion was redeemed or if is expired.

Do you know of an EPi API that allows me to remove the promotions based on number of redemptions or if they are expired? (I think this is mostly for performance issues and to have a cleaner marketing page)

Or if there is some more documentation could you send me that way?

Thank you,

#179013
May 29, 2017 15:04
Vote:
 

Sounds like you want to create a cleanup job that removes discounts. As long as you set the redemptions and expire date correctly, that should be a pretty easy job to write. 

Something along the lines with a job that:

  1. Get all discounts in the system (get children on campaign root content, or if there is any better way)
  2. Loop through them, check for the conditions you want, redemption limit/expiry date
  3. Use IContentRepository to delete them

Hopefully that helps

#179015
May 29, 2017 15:23
Vote:
 

Campaign or promotion are just normal CMS content, so here's what you can do:

  • Get campaigns as children of SalesCampaignFolder.CampaignRoot
  • For each campaign get promotions as children of it.

Now you have all promotions in the system. Checking the expired promotions should be easy enough. Checking the redeemed promotions can be tricky because there are three types of redemption (per promotion, per orderform, per customer) - but I guess you only care about the first one (per promotion). You can use PromotionInformationRepository.GetRedemptions to get back a list of PromotionRedemption for a list of promotions. For each PromotionRedemption, check for TotalRedemptions and compare it with the redemption setting of the promotion.

However I would say it's not necessary to delete the promotions that way. Promotion engine is smart enough to ignore the expired/redeemed promotions, and you can do the same with your marketing page. Keeping the promotions can be useful later when you look at analystic of how a promotion was used.

#179016
May 29, 2017 15:35
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.