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

[Commerce 8.16.1 -> 12.10] Workflow doesn't apply discount

Vote:
 

Hi,

Having upgraded from Commerce v8.16.1 to v12.10, I am seeing some issues regarding the application of discount codes (we're using the legacy promotion system still).

Having followed through the code comparing it to the process of the original. It seems that after running the 'cart.RunWorkflow' method, where the workflow passed as a parameter is 'ValidateCart', the discount has not been applied in the OrderForm post-workflow.

The code looks like this (removed some unimportant parts for brevity) -

var ch = new CartHelper(Cart.DefaultName);

var matchedDiscount = PromotionManager.GetPromotionDto()
                                     .Promotion.AsEnumerable()
                                     .ToList()
                                     .Where(x => x.CouponCode == code)
                                     .ToList()
                                     .FirstOrDefault();

MarketingContext.Current.AddCouponToMarketingContext(code);
                        ch.OrderForm.EnsureLineItemsOnShipment();

messages += RunWorkflowAndReturnFormattedMessage(ch.Cart, OrderGroupWorkflowManager.CartValidateWorkflowName);

ch.Cart.AcceptChanges();

With the event method doing the following -

public static string RunWorkflowAndReturnFormattedMessage(Cart cart, string workflowName)
        {
            if (cart == null)
            {
                return string.Empty;
            }

            var returnString = string.Empty;

            cart.ProviderId = "FrontEnd";

            try
            {
                var results = cart.RunWorkflow(workflowName);
                var resultsMessages = GetWarningsFromWorkflowResult(results);
                var enumerable = resultsMessages as string[] ?? resultsMessages.ToArray();
                if (enumerable.Any())
                {
                    returnString = enumerable.Aggregate((current, result) => current + (result + "
")); } if (returnString.IndexOf("exception") >= 0) { returnString = ValidationMessage.Error; } else if (returnString.Contains("lineitemremoved")) { returnString = ValidationMessage.StockChange; } else if (!string.IsNullOrEmpty(returnString)) { returnString = ValidationMessage.Other; } return returnString; } catch (Exception aore) { return aore.FormatMessageRecursive(Environment.NewLine); } }

Is there anything obvious I've missed, it was a large upgrade so there's a chance I've missed some kind of breaking change/rework?

Cheers,

James

#199112
Nov 15, 2018 18:27
Vote:
 

Are you using the new promotion system or the old one?

It might have something to do with the breaking changes in version 11:

https://world.episerver.com/documentation/upgrading/episerver-commerce/commerce-11/breaking-changes-commerce-11/

#199117
Nov 15, 2018 20:40
Vote:
 

@Jafet, The OP mentions that he is using the legacy promotion system still.
@James, To follow up on Jafet's comments, did you review this part of that page in particular: "New promotion system enabled by default"?

#199119
Nov 15, 2018 21:00
Vote:
 

Ah, read a bit too quickly it seems. :)

So yeah, @James, take a look at that section, if you haven't already.

#199120
Edited, Nov 15, 2018 21:03
Vote:
 

Ah, that was the issue. I was aware of it but I'd only added that config section to the config of CommerceManager. It's now in both CM and Web and looks to be applying discounts.

Thanks for the push in the right direction guys!

#199131
Nov 16, 2018 10:25
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.