-
Notifications
You must be signed in to change notification settings - Fork 3
Description
User reported example does work as written/pulled into the docs, and provided a suggestion for how to fix.
See https://github.com/Shopify/shopify-dev/issues/61273 for original issue.
The example template is wrong as the end goal is to discount the highest subtotal lineitem. The example is comparing the cost of these but as strings, not numbers. It should actually be
const maxCartLine = input.cart.lines.reduce((maxLine, line) => {
if (Number(line.cost.subtotalAmount.amount) > Number(maxLine.cost.subtotalAmount.amount)) {
return line;
}
return maxLine;
}, input.cart.lines[0]);
How I interpret:
Lines 24 to 29 in 09c22fb
| const maxCartLine = input.cart.lines.reduce((maxLine, line) => { | |
| if (line.cost.subtotalAmount.amount > maxLine.cost.subtotalAmount.amount) { | |
| return line; | |
| } | |
| return maxLine; | |
| }, input.cart.lines[0]); |
User's suggestion:
const maxCartLine = input.cart.lines.reduce((maxLine, line) => {
if (Number(line.cost.subtotalAmount.amount) > Number(maxLine.cost.subtotalAmount.amount)) {
return line;
}
return maxLine;
}, input.cart.lines[0]);to compare as numbers rather than strings.
Closing the original docs issue in favor of this one.