Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

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



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()
                                     .Where(x => x.CouponCode == code)


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


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";

                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?



Nov 15, 2018 18:27

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

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

Nov 15, 2018 20:40

@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"?

Nov 15, 2018 21:00

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

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

Edited, Nov 15, 2018 21:03

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!

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.