Replies: 2 comments
-
I think a decimal would be most appropriate, as JS can format this much easier, for example with the Intl.NumberFormat() constructor. So my suggestion would be: Either way, as long as the prices are consistently formatted, it should be easy to convert it in any framework, as JS has built in number formatters. |
Beta Was this translation helpful? Give feedback.
-
So after some thinking and research into WooCommerce product extensions are doing. It is better if the item price is also consistant with everything else but leave the item totals unchanged. This allows developers to use the original value like they do on the frontend with the cart. I have also added additional filters for developers for more control. These filters are best to be used with a priority of at least Introduced filter Should those not want the decimals used for the monetary values they can disable them with this filter If set to true the monetary value will change from I will provide snippets on the developers hub site that will allow you to have the price formatted the way you want should you not format the monetary values within your framework. |
Beta Was this translation helpful? Give feedback.
-
Over the two API versions there has been a constant battle as to how the formatting of the cost of all things should return.
You can use a filter to alter the format to your preferred method but I think we can do better out of the box if possible.
Most values are consistent that have no currency symbol or decimal separator. Just the value with set decimals. e.g. $42,99 would return 4299.
This format was choosen to allow for developers to calculate totals after they have gathered the information. I think now CoCart is much more stable and able to calculate all totals before the cart response returns this is no longer necessary, but I could be wrong.
WooCommerce does the same thing for their Cart and Checkout Blocks for Gutenberg so I'm not sure what is better as CoCart is designed for many frameworks in mind and I don't know if any of them have limitations when it comes to formatting monterized values. I don't think there is but this is what this discussion is for. For me to find out from you.
I could be wrong but I think all of these return the same as of v3.1
The only thing not matching is the item price and item subtotal of each item in the cart. So consistenacy is what I am looking.
What I would like from you is to decide the default format you wish to have and a reason for why you choose it.
If I'm missing a format please let me know.
Beta Was this translation helpful? Give feedback.
All reactions