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?
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:
Hopefully that helps
Campaign or promotion are just normal CMS content, so here's what you can do:
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.