Evaluate promotion for entry with couponcode applied

Vote:
 

Is there anyway to evaluate a promotion for a single entry but with a couponcode applied?

Say i want to compare the price given by the coupon-discount and another price.
Or if i want to display "Price with coupon REA2022: 650kr 800kr".



Commerce v.13.31

#287705
Sep 20, 2022 9:38
Vote:
 

Hi Anton,

Try this:

var InMemoryOrderGroup = new InMemoryOrderGroup(cart);
var rewardDescription = InMemoryOrderGroup.ApplyDiscounts(_promotionEngine, new PromotionEngineSettings(RequestFulfillmentStatus.Fulfilled, true));

This will copy you cart to an in memory one. Combined with the PromotionEngineSettings you'll be able to see what discount is being applied.

You can get the placed price and the discounted price from the rewardDescription OR the InMemoryOrderGroup from the code above.

#287744
Sep 20, 2022 19:23
Vote:
 

This is how you can do it

        public IEnumerable<RewardDescription> Evaluate(IEnumerable<ContentReference> entryLinks,
            IMarket market,
            Currency currency,
            string couponCode,
            RequestFulfillmentStatus requestFulfillmentStatus)
        {
            Validator.ThrowIfNull("entryLinks", entryLinks);
            Validator.ThrowIfNull("market", market);

            var rewardDescriptions = new List<RewardDescription>();
            var promotionEngineSettings = new PromotionEngineSettings() { ApplyReward = false, RequestedStatuses = requestFulfillmentStatus };

            foreach (var entryLink in entryLinks)
            {
                var orderGroup = _promotionEngineContentLoader.CreateInMemoryOrderGroup(entryLink, market, currency);
                orderGroup.Forms.First().CouponCodes.Add(couponCode);
                var entryLinkRewardDescriptions = _promotionEngine.Run(orderGroup, promotionEngineSettings);
                rewardDescriptions.AddRange(entryLinkRewardDescriptions);
            }

            return rewardDescriptions;
        }
#287795
Edited, Sep 21, 2022 10:25
Surjit Bharath - Sep 21, 2022 11:07
Well you learn something new everyday...I did not know there was a service for creating in memory carts!
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.