Try our conversational search powered by Generative AI!

Fetch what LineItems Rewards/Promotions affect in Cart

Vote:
 

When I'm fetching the calculated discounts/rewards/what say you not, I can't seem to find a way of fetching which items in the cart the afformentioned discounts they are for. And, when I'm trying to use the 

promotionsEngine.Evaluate(entryLink, currentMarket, currentMarket.DefaultCurrency, RequestFulfillmentStatus.All);

I'm always getting a NullReferenceException, but only for entryLinks that is supposed to have a discount associated with it, while the ones without any discount/reward just returns an empty List.

Is there a way of fetching what discounts are for what items in the cart?

#200601
Edited, Jan 17, 2019 11:05
Vote:
 

Are you looking for promotions that has been applied to the cart with 

promotionEngine.Run(cart)

?

In that case, the promotions that yielded rewards will be stored in the orderform as IOrderForm.PromotionInformation and there you can find an Entries field which has information about which entries and how much was saved per discount.

#200608
Jan 17, 2019 13:32
Vote:
 

Correction: it's IOrderForm.Promotions, which is a collection of PromotionInformation. 

#200610
Jan 17, 2019 13:47
Vote:
 

I am looking for a way of iterating over the items in the cart and read out their respective promotion. An example look for the site would be:

  • Door 1     Price : 10$
    • 50% off
  • Door 3     Price : 50$
    • 50% off
  • Mailbox    Price : 10$
    • 90% off

  • Total saved 39$
  • Total 31$

I have managed to get the promotions in a single, encapsulated variable, separated from all the items.

I want to see what promotions are added for each of the items, instead of a collection of promotions added to the cart.

#200611
Jan 17, 2019 13:50
Vote:
 

Haven't run this code, but something like this?

var form = cart.GetFirstForm();
var lineItems = cart.GetFirstForm().GetAllLineItems();
foreach (var lineItem in lineItems)
{
    var promotions = form.Promotions.Where(promotionInformation => promotionInformation.Entries.Select(promotionEntry => promotionEntry.EntryCode).Contains(lineItem.Code));
    // This lineitem has been rewarded the above list of promotions
}
#200614
Jan 17, 2019 13:59
Vote:
 

Great, that seemed to do the trick Joel!

#200624
Jan 17, 2019 15:14
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.