The JSON you display in the first code block doesn't match what you are creating in the second block.
You are actually trying to create two rule configs with the second being a child of the first so you'll need something more like this.
var excludeRule = new DiscountRuleConfig("orderLineProductExclude", new new Dictionary<string, string>
{
{ "nodeId", "umb://document/84487eb8cfe5473cb2cc169495ddaab1" }
});
var groupRule = new DiscountRuleConfig("groupDiscountRule", new Dictionary<string, string>
{
{ "matchType", MatchType.All.ToString() }
},
new[]{ excludeRule });
discount.SetRules(groupRule, true, true);
Notice that the inner rule is defined separately and passed as a child rule to the group rule. With what you had before, you were basically trying to push all the config values into the settings of the group rule, which isn't what the first code block was doing.
Adding discount programmatically and setting product to exclude
Hi,
I'm trying to create a discount programmatically and add a rule to exclude the discount on a specific product.
If I create the discount manually, I can see the following JSON for the rule which I'm trying to match:
and I'm adding this rule in code as follows:
but that doesn't seem to work.
Thanks in advance
Ben
Hi Ben,
The JSON you display in the first code block doesn't match what you are creating in the second block.
You are actually trying to create two rule configs with the second being a child of the first so you'll need something more like this.
Notice that the inner rule is defined separately and passed as a child rule to the group rule. With what you had before, you were basically trying to push all the config values into the settings of the group rule, which isn't what the first code block was doing.
Hope that helps
Matt
Works perfectly and makes sense Matt. Thank you!
is working on a reply...