Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Get promotions associated with a line item

Vote:
 

I have a requirement to show a little bit of copy for promotions which are applied to each line item in a given cart.

I feel like I am missing something obvious, this is the best I can come up with at present.

    var cart = this.orderRepository.LoadCart(contactId, DefaultCartType);

    var rewards = cart.ApplyDiscounts().ToList();

    var lineItemPromotions = rewards.SelectMany(x => x.Redemptions)
        .Select(x => x.AffectedEntries)
        .SelectMany(x => x.PriceEntries)
        .Select(x => new { x.ParentItem.LineItemId, x.Promotion.Name })
        .GroupBy(x => x.LineItemId)
        .ToDictionary(x => x.Key, y => y.Select(x => x.Name));

Can someone please inform me of a simpler way to get promotions which affect a given line item.

#192510
May 17, 2018 17:45
Vote:
 

Found my answer by browsing EPiServer QuickSilver codebase, nice serializable model for promotions can be found by using

var promotions = cart.GetFirstForm().Promotions;
#192551
May 18, 2018 11:51
Vote:
 

That is not exactly what you asked for. IOrderForm.Promotions contains all promotions applied for that form. If you want to know which promotions applied to a specific line item, you would have to do more, getting the Entries from Promotions, then map them to each lineitem to find out what (entry-level) promotions have been applied. 

#192553
May 18, 2018 12:16
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.