Hello,
We have a use case were we have an order which contains order lines, and each of those order lines may or may not have 1 or more “applied discounts” in a nested array. For example, here is a snippet from the output order:
products:
1:
id: 79
code: a
base_total: $10
applied_discounts:
1:
amount: $1
2:
amount: $2
2:
id: 80
code: b
base_total: $5
applied_discounts:
1:
amount: $5
3:
id: 80
code: c
base_total: $10
applied_discounts:
When we use the loop from lines functionality, it would show the above input value as:
p“1”,”2”],“5”],null
However, when we actually loop though the lines, it treats it like “1,2,5,”. As you can imagine, this creates problems, because we only have 3 products, and each discount can easily become misaligned with it’s correct pairing.
Ultimately, we want to add values together for each product to get a total discount amount, then pass those values to line items, which seems to be achievable with some JavaScript. However, when we use JavaScript, the input value seems to not preserve the nested arrays, ie, no matter what we do, even though the applied discounts look like this when being selected for formatting using JavaScript:
The formatter seems to always see the input data like this:
How do we parse out each array for each product? Are we missing something? Is there a simpler solution?
Please help, thank you!