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

Best way to find ALL promotions?

Vote:
 

Hi,

I know how to retrieve one promotion (using IContentLoader)... But, how can I easily get a collection of ALL promotions at runtime?

Thanks,

 - Ken

#183581
Edited, Oct 17, 2017 22:09
Vote:
 

Using the same APIs. Discounts (=promotions) are children of Campaigns (or SalesCampaigns). And you cannot create a SalesCampaign with another SalesCampaign as parent, hence it's only two levels. So just interate all the campaigns and then get the children of all of them. Like so

var salesCampaigns = _contentLoader.GetChildren<SalesCampaign>(SalesCampaignFolder.CampaignRoot);
var allPromotions = new List<PromotionData>();
foreach (var salesCampaign in salesCampaigns)
  allPromotions.AddRange(_contentLoader.GetChildren<PromotionData>(salesCampaign.ContentLink));
#183582
Oct 17, 2017 23:05
Vote:
 

Ah, I see.  That had crossed my mind after your answer on my other question ;)  But, wasn't sure if it's the preferred way so I decided to ask :)

Thanks again Joel,

 - Ken

#183584
Oct 17, 2017 23:14
Vote:
 

PromotionEngineContentLoader.GetPromotions should do that for you. But if you want to write some code yourself, then Joel's answer is correct.

#183586
Oct 17, 2017 23:23
Vote:
 

Sounds good to me!

#183588
Oct 17, 2017 23:39
Vote:
 

Isn't that one internal? Reason I didn't recommend it is that I thought it was internal :P

https://world.episerver.com/documentation/class-library/?documentId=commerce/9/16DE8B32

#183620
Oct 18, 2017 12:43
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.