Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent number formatting while talking to API #10556

Open
fauno opened this issue Oct 23, 2020 · 2 comments
Open

Inconsistent number formatting while talking to API #10556

fauno opened this issue Oct 23, 2020 · 2 comments

Comments

@fauno
Copy link

fauno commented Oct 23, 2020

Context

Sorry to revisit #6480 but I'm working with an API only Spree and just found it expects me to send the price in the locale format (so 1.0 with Spanish locale will be converted to 10 by Spree::LocalizedNumber), but will return it in the English format when I ask for it back ("1.0"), so I have to deal with the inconsistency, what do you think?

Expected Behavior

Send and receive numbers in a single format (ideally not localized)

Actual Behavior

I have to juggle numbering formats to talk to the API

Steps to Reproduce

  1. Store is in Spanish
  2. Create a product via /api/v1/products.json sending Float as String ("1.0")
  3. Query API for product price and get "10.0"

Your Environment

spree_api 4.1.11

@fauno
Copy link
Author

fauno commented Oct 23, 2020

Using <input type="number" step="0.01" /> on spree_backend may help users write numbers in their own locales and browsers would send consistent (aka English) formatting, so Spree::LocalizedNumber wouldn't be necessary. At least I tested it with Firefox in Spanish and it lets me use comma as decimal separator.

https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/number#Examples

I would gadly send a patch including deprecation warnings if you're interested :)

@fauno
Copy link
Author

fauno commented Oct 23, 2020

A friend made me notice I was sending HTTP params instead of JSON data so now I can send numbers instead of strings, but the offer to change input to numbers stands :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants