vendure-ecommerce/vendure

Add new product with variant price lower than 0.01

brunoslalmeida opened this issue · 2 comments

Describe the bug
Is possible to add products with price lower the 1 cent, but it is save as 0. The same behavior is not allowed at Product Variant Management Page. It's important to make it consistent between these two different pages.

chrome-capture-2024-6-20 (1)

To Reproduce
Steps to reproduce the behavior:

  1. Go to new product page
  2. Fill name and slug
  3. Scroll down to product variants
  4. Fill product variant with price 0.001

Expected behavior
Either notify the user with the error "Price can be lower then 0.01" or similar message OR allow the user to save smaller prices and show them correctly.

Environment (please complete the following information):

  • @vendure/core version: 2.2.6
  • Nodejs version 20.11.0
  • Database (mysql/postgres etc): sqlite

@michaelbromley is there any label "good for start" etc to indicate that this bug is a good starting point for new contributors ?

Also, what would be the ideal solution ? In case someone tries to fix it :)

@brunoslalmeida sorry for the slow reply. I added the "contributions welcome" label.

In terms of the actual solution, we need to take into account the configured MoneyStrategy.precision setting. This is exposed to the Admin UI via the globalSettings.serverConfig.moneyStrategyPrecision field in the Admin API.

Looking at the existing implementation of the currency input component, this value is already being accounted for, see:

So the data we need should already be available in the component. It looks like there is just some validation step missing to enforce the precision when entering the value.