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

fix(commerce): return fractional prices #2458

Merged
merged 28 commits into from
Mar 1, 2024
Merged

Conversation

import-brain
Copy link
Member

closes #350

@import-brain import-brain added c: bug Something isn't working p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug m: commerce Something is referring to the commerce module labels Oct 9, 2023
@import-brain import-brain added this to the vAnytime milestone Oct 9, 2023
@import-brain import-brain requested a review from a team October 9, 2023 22:47
@import-brain import-brain self-assigned this Oct 9, 2023
@import-brain import-brain requested a review from a team as a code owner October 9, 2023 22:47
@codecov
Copy link

codecov bot commented Oct 9, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.56%. Comparing base (8e880c1) to head (ae6343d).

Additional details and impacted files
@@           Coverage Diff           @@
##             next    #2458   +/-   ##
=======================================
  Coverage   99.56%   99.56%           
=======================================
  Files        2846     2846           
  Lines      248656   248715   +59     
  Branches      642      654   +12     
=======================================
+ Hits       247581   247643   +62     
+ Misses       1075     1072    -3     
Files Coverage Δ
src/modules/commerce/index.ts 98.98% <100.00%> (+0.13%) ⬆️

... and 2 files with indirect coverage changes

ST-DDT
ST-DDT previously approved these changes Oct 9, 2023
@ST-DDT ST-DDT requested a review from a team October 9, 2023 23:16
Copy link
Contributor

@matthewmayer matthewmayer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem very realistic, e-commerce sites don't typically have random numbers of cents on a price for items above $100. It's more common to round to a nice number like .00 or .95 or .99

image

@ST-DDT
Copy link
Member

ST-DDT commented Oct 10, 2023

There are some prices that are like 1.20€ like a serving of ice.

@ST-DDT
Copy link
Member

ST-DDT commented Oct 10, 2023

Amazon Prime Video today:
grafik

But I must admit a price like 10.09€ is rare.

@matthewmayer
Copy link
Contributor

I think a more realistic algorithm for prices might be:

  • Generate the raw price
  • Round to 2 or 3 significant digits (e.g. 1.23 or 12.30 or 123.00 or 1230.00)
  • Optionally deduct 0.01 or 0.05

@import-brain
Copy link
Member Author

import-brain commented Oct 11, 2023

There are some prices that are like 1.20€ like a serving of ice.

Also, when you convert a price from one currency to another, you often get something like "$120.14".

@ST-DDT
Copy link
Member

ST-DDT commented Oct 17, 2023

Team Decision

We will alter the distribution to favor the special numbers by using faker.helpers.weightedArrayElement for the last decimal digit.

  • 9: weight: 5
  • 5: weight: 3
  • 0: weight: 1
  • random(0-9): weight: 1

If the dec is zero we will skip this behavior.

@import-brain
Copy link
Member Author

@import-brain Could you please update this PR or should we take it over?

@ST-DDT Could you please take this over?

@ST-DDT
Copy link
Member

ST-DDT commented Feb 11, 2024

Sure no problem. This might take a bit though.

@ST-DDT
Copy link
Member

ST-DDT commented Feb 29, 2024

Here a few prices that are returned by the price method:

Summary
Last Digit Occurrences
0 13
1 0
2 1
3 1
4 2
5 30
6 1
7 1
8 2
9 49
Values
Price Last Digit
278.39 9
224.59 9
171.99 9
968.26 6
832.10 0
911.79 9
345.35 5
842.69 9
636.79 9
325.29 9
666.80 0
891.55 5
897.49 9
377.09 9
731.65 5
821.55 5
650.40 0
595.09 9
268.18 8
461.00 0
188.25 5
915.30 0
483.49 9
1.19 9
203.95 5
611.29 9
546.49 9
297.95 5
759.49 9
344.69 9
388.89 9
898.15 5
319.95 5
99.25 5
399.69 9
269.45 5
562.29 9
336.45 5
628.39 9
24.99 9
89.65 5
380.05 5
183.99 9
647.03 3
896.95 5
37.45 5
581.39 9
70.79 9
281.10 0
878.29 9
838.05 5
940.95 5
692.09 9
938.20 0
936.89 9
339.45 5
663.55 5
664.19 9
663.59 9
234.55 5
609.69 9
817.09 9
448.55 5
755.69 9
514.15 5
406.72 2
368.75 5
375.50 0
377.60 0
633.69 9
813.09 9
281.39 9
834.69 9
639.95 5
729.39 9
91.50 0
497.29 9
281.49 9
771.09 9
803.69 9
159.85 5
386.79 9
738.77 7
442.85 5
210.74 4
569.78 8
171.84 4
206.19 9
732.79 9
305.89 9
181.55 5
311.39 9
694.30 0
413.45 5
317.80 0
483.20 0
599.19 9
765.69 9
34.89 9
507.65 5

@ST-DDT
Copy link
Member

ST-DDT commented Feb 29, 2024

Ready for review

ST-DDT
ST-DDT previously approved these changes Feb 29, 2024
ST-DDT
ST-DDT previously approved these changes Feb 29, 2024
@ST-DDT ST-DDT requested a review from a team February 29, 2024 11:18
@matthewmayer
Copy link
Contributor

matthewmayer commented Feb 29, 2024

While it's not strictly a breaking change I think it's worth a mention in the migration guide given that it changes the behavior of the method.

@ST-DDT ST-DDT requested a review from a team February 29, 2024 18:24
@ST-DDT
Copy link
Member

ST-DDT commented Feb 29, 2024

While it's not strictly a breaking change I think it's worth a mention in the migration guide given that it changes the behavior of the method.

Added

@ST-DDT ST-DDT self-assigned this Mar 1, 2024
@ST-DDT ST-DDT changed the title fix: return fractional prices from commerce.price() fix(commerce): return fractional prices Mar 1, 2024
@ST-DDT ST-DDT merged commit 9348138 into next Mar 1, 2024
18 checks passed
@ST-DDT ST-DDT deleted the fix/fract_currency_prices branch March 1, 2024 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: bug Something isn't working m: commerce Something is referring to the commerce module p: 1-normal Nothing urgent s: accepted Accepted feature / Confirmed bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Commerce price does not return fractional currency prices
5 participants