Money cannot represent non numberic value NaN and discount for order line with 0 quantity #3008
Labels
contributions welcome
P3: minor
Non-critical, no workarounds exist
type: bug 🐛
Something isn't working
@vendure/core
Describe the bug
When try to modify orderline quantity to 0, it show error Money cannot represent non numberic value NaN
Demo Video:
Screen.Recording.2024-08-13.at.12.52.06.PM.1.mov
To Reproduce
Steps to reproduce the behavior:
Expected behavior
Environment (please complete the following information):
Additional context
I am writing my own resolver that remove certain items when some condition are met (like, customer want to remove the item and the item is yet to be fulfilled). When doing this flow without any promotion that’s on the order level, it works as expected, the error arise when we want to remove the item. Which causes an error of NaN because i am running the modifyOrder without the dryRun.
I have discovered a potential root cause that might solve this issue. In the applyOrderPromotion in OrderCalculator, there’s a code to get the share of amount of discount that each order line get which is the
const shareOfAmount = distribution[i]
; However, I noticed that for order line that dont have any quantity, the distribution will result in the value of undefined, to solve this, I found out that adding?? 0
after theconst shareOfAmount = distribution[i];
which becomesconst shareOfAmount = distribution[i] ?? 0;
solves the issue.The text was updated successfully, but these errors were encountered: