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

MCCY: Round to lowest denomination before applying price rounding from MCCY settings #9932

Conversation

reykjalin
Copy link
Contributor

@reykjalin reykjalin commented Dec 12, 2024

Fixes #10009

Changes proposed in this Pull Request

This is consistent with the results of the discussions in paJDYF-g0K-p2.

Previous behavior as of #9876 is to ceil the price before applying any rounding options from the settings, but based on the P2 discussions we identified that using round instead of ceil is the better approach.

Testing instructions

  1. Make sure unit tests pass.

Then;

Note

You must have the WooCommerce Deposits plugin active and enabled.

  1. Go to WooCommerce → Settings → Multi-Currency and pick a currency that is not the store currency.
  2. Open the settings for that currency and set the manual rate for the currency to 3.783325.
  3. Set "charm pricing" to none and "price rounding" to 0.00.
  4. Make sure to enable "Add a currency switcher to the Storefront theme on breadcrumb section."
  5. Create a deposits product:
    • Create a simple product. Set the price to $25
    • Go to the "Deposits" tab on the admin product page.
    • Enable deposits with "Yes - deposits are optional"
    • Set Deposit Type to "Inherit storewide settings (percent)"
    • Deposit Amount: 50
    • Save
  6. Go to the page of the product you just created.
  7. Make sure the selected currency is the one you set the manual rate for in step (2).
  8. Make sure the product price is 94.58
  9. Verify "Pay Deposit" is selected.
  10. Increase the number to "2" in the quantity input.
  11. Click "Add to cart"
  12. Make sure the subtotal in the cart is 94.58.
    • You did not read the price wrong; we're paying 50% deposit on 2 products so we expect this to be the same amount as the single product price :)

Finally;

  • Exploratory testing:
    • Play around with a couple different product types, taxes, and shipping costs.
    • Make sure amounts are consistent across product pages, mini-cart, and shortcode/blocks cart and checkout pages.
    • Try at least 2 different non-store currencies, 1 that has 2 decimals, and another that has 0 decimals, e.g. EUR and JPY, and make sure rounding is consistently applied.
    • Try some combinations of charm pricing and rounding in the currency settings, including with one or both disabled, and make sure prices are rounded correctly.

  • Run npm run changelog to add a changelog file, choose patch to leave it empty if the change is not significant. You can add multiple changelog files in one PR by running this command a few times.
  • Covered with tests (or have a good reason not to test in description ☝️)

Post merge

@botwoo
Copy link
Collaborator

botwoo commented Dec 12, 2024

Test the build

Option 1. Jetpack Beta

  • Install and activate Jetpack Beta.
  • Use this build by searching for PR number 9932 or branch name add/round-to-nearest-lowest-denomination-before-applying-rounding-from-settings in your-test.site/wp-admin/admin.php?page=jetpack-beta&plugin=woocommerce-payments

Option 2. Jurassic Ninja - available for logged-in A12s

🚀 Launch a JN site with this branch 🚀

ℹ️ Install this Tampermonkey script to get more options.


Build info:

  • Latest commit: 2dcf53b
  • Build time: 2025-01-07 02:08:22 UTC

Note: the build is updated when a new commit is pushed to this PR.

Copy link
Contributor

github-actions bot commented Dec 12, 2024

Size Change: 0 B

Total Size: 1.34 MB

ℹ️ View Unchanged
Filename Size
release/woocommerce-payments/assets/css/admin.css 1.37 kB
release/woocommerce-payments/assets/css/admin.rtl.css 1.37 kB
release/woocommerce-payments/assets/css/success.css 182 B
release/woocommerce-payments/assets/css/success.rtl.css 184 B
release/woocommerce-payments/dist/blocks-checkout-rtl.css 2.63 kB
release/woocommerce-payments/dist/blocks-checkout.css 2.63 kB
release/woocommerce-payments/dist/blocks-checkout.js 53.9 kB
release/woocommerce-payments/dist/cart-block.js 16.8 kB
release/woocommerce-payments/dist/cart.js 5.73 kB
release/woocommerce-payments/dist/checkout-rtl.css 932 B
release/woocommerce-payments/dist/checkout.css 931 B
release/woocommerce-payments/dist/checkout.js 33.1 kB
release/woocommerce-payments/dist/frontend-tracks.js 854 B
release/woocommerce-payments/dist/index-rtl.css 39.5 kB
release/woocommerce-payments/dist/index.css 39.4 kB
release/woocommerce-payments/dist/index.js 303 kB
release/woocommerce-payments/dist/multi-currency-analytics.js 1.08 kB
release/woocommerce-payments/dist/multi-currency-rtl.css 4.47 kB
release/woocommerce-payments/dist/multi-currency-switcher-block.js 60.9 kB
release/woocommerce-payments/dist/multi-currency.css 4.47 kB
release/woocommerce-payments/dist/multi-currency.js 57.6 kB
release/woocommerce-payments/dist/order-rtl.css 730 B
release/woocommerce-payments/dist/order.css 730 B
release/woocommerce-payments/dist/order.js 42.4 kB
release/woocommerce-payments/dist/payment-gateways-rtl.css 1.33 kB
release/woocommerce-payments/dist/payment-gateways.css 1.33 kB
release/woocommerce-payments/dist/payment-gateways.js 38.8 kB
release/woocommerce-payments/dist/plugins-page-rtl.css 386 B
release/woocommerce-payments/dist/plugins-page.css 386 B
release/woocommerce-payments/dist/plugins-page.js 20.1 kB
release/woocommerce-payments/dist/product-details-rtl.css 433 B
release/woocommerce-payments/dist/product-details.css 436 B
release/woocommerce-payments/dist/product-details.js 12 kB
release/woocommerce-payments/dist/settings-rtl.css 11.7 kB
release/woocommerce-payments/dist/settings.css 11.6 kB
release/woocommerce-payments/dist/settings.js 224 kB
release/woocommerce-payments/dist/subscription-edit-page.js 703 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal-rtl.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.css 524 B
release/woocommerce-payments/dist/subscription-product-onboarding-modal.js 20.2 kB
release/woocommerce-payments/dist/subscription-product-onboarding-toast.js 730 B
release/woocommerce-payments/dist/subscriptions-empty-state-rtl.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.css 120 B
release/woocommerce-payments/dist/subscriptions-empty-state.js 19.3 kB
release/woocommerce-payments/dist/tokenized-express-checkout-rtl.css 229 B
release/woocommerce-payments/dist/tokenized-express-checkout.css 229 B
release/woocommerce-payments/dist/tokenized-express-checkout.js 16.1 kB
release/woocommerce-payments/dist/tos-rtl.css 235 B
release/woocommerce-payments/dist/tos.css 235 B
release/woocommerce-payments/dist/tos.js 21.8 kB
release/woocommerce-payments/dist/woopay-direct-checkout.js 6.13 kB
release/woocommerce-payments/dist/woopay-express-button.js 24.6 kB
release/woocommerce-payments/dist/woopay-rtl.css 4.31 kB
release/woocommerce-payments/dist/woopay.css 4.28 kB
release/woocommerce-payments/dist/woopay.js 71 kB
release/woocommerce-payments/includes/subscriptions/assets/css/plugin-page.css 625 B
release/woocommerce-payments/includes/subscriptions/assets/js/plugin-page.js 814 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/i18n-loader.js 2.46 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/build/jetpack-script-data.js 772 B
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/i18n-loader.js 1.02 kB
release/woocommerce-payments/vendor/automattic/jetpack-assets/src/js/script-data.js 69 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/babel.config.js 163 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.js 14.2 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/identity-crisis.rtl.css 2.47 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.css 10 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.js 28.4 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-connection.rtl.css 10 kB
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.js 280 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-admin-create-user.rtl.css 198 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.css 625 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.js 333 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-login.rtl.css 626 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/jetpack-sso-users.js 424 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-ajax.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/dist/tracks-callables.js 585 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.css 215 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-admin-create-user.js 521 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.css 721 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-login.js 412 B
release/woocommerce-payments/vendor/automattic/jetpack-connection/src/sso/jetpack-sso-users.js 632 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/about.css 1.04 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-empty-state.css 294 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin-order-statuses.css 408 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/admin.css 3.59 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/checkout.css 301 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/modal.css 746 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/view-subscription.css 574 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/css/wcs-upgrade.css 414 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin-pointers.js 543 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/admin.js 9.4 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.js 6.78 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/jstz.min.js 3.84 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-coupon.js 545 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/meta-boxes-subscription.js 2.52 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.js 22.2 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/moment.min.js 11.7 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/payment-method-restrictions.js 1.29 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/admin/wcs-meta-boxes-order.js 507 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/payment-methods.js 358 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/single-product.js 428 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/view-subscription.js 1.38 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/frontend/wcs-cart.js 782 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/modal.js 1.09 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/assets/js/wcs-upgrade.js 1.26 kB
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.css 391 B
release/woocommerce-payments/vendor/woocommerce/subscriptions-core/build/index.js 3.04 kB

compressed-size-action

…ings

This is consistent with the results of the discussions in paJDYF-g0K-p2.

Previous behavior as of #9876 is to ceil the price before applying any
rounding options from the settings, but based on the P2 discussions we
identified that using `round` instead of `ceil` is the better approach.
@reykjalin reykjalin force-pushed the add/round-to-nearest-lowest-denomination-before-applying-rounding-from-settings branch from d971558 to ff38f59 Compare December 20, 2024 05:50
@reykjalin reykjalin marked this pull request as ready for review December 20, 2024 06:41
@reykjalin reykjalin requested review from a team and bborman22 and removed request for a team December 20, 2024 06:41
Copy link
Contributor

@bborman22 bborman22 left a comment

Choose a reason for hiding this comment

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

This tested very well and matched all the expectations. I included a table of the scenarios I tested below to cover product types, quantities, price rounding, and price charming settings. The only note I had was that with JPY, since the price rounding options only goes to 1 (not 0) it essentially always uses a ceiling. I believe this is the desired behavior given the zero decimal aspect, but wanted to confirm that with you.

EUR using a conversion rate of 3.783325

Product Type Price Single Item Conversion Quantity Quantity Conversion Using Round Rounding 0.5, Charm None Rounding None, Charm -0.01 Rounding 1.0, Charm -0.01
Deposit 25 94.583125 1 94.583125 94.58 95 94.57 94.99
Subscription 10 37.83325 1 37.83325 37.83 38 37.82 37.99
Subscription Sign Up Fee 2 7.56665 1 7.56665 7.57 8 7.56 7.99
Simple Product 18.5 69.9915125 1 69.9915125 69.99 70 69.98 69.99
Simple Product 18.3 69.2348475 1 69.2348475 69.23 69.5 69.22 69.99
Deposit 25 94.583125 20 1891.6625 1891.6 1900 1891.4 1899.8
Subscription 10 37.83325 20 756.665 756.6 760 756.4 759.8
Subscription Sign Up Fee 2 7.56665 20 151.333 151.4 160 151.2 159.8
Simple Product 18.5 69.9915125 20 1399.83025 1399.8 1400 1399.6 1399.8
Simple Product 18.3 69.2348475 20 1384.69695 1384.6 1390 1384.4 1399.8

JPY using a conversion rate of 147.37782

Product Type Price Single Item Conversion Using Ceil Rounding 50, Charm None Rounding 1, Charm -1 Rounding 100, Charm -1
Deposit 25 3684.4455 3685 3700 3684 3699
Subscription 10 1473.7782 1474 1500 1473 1499
Subscription Sign Up Fee 2 294.75564 295 300 294 299
Simple Product 18.5 2726.48967 2727 2750 2726 2799
Simple Product 18.3 2697.014106 2698 2700 2697 2699

I had one minor nit on reusing a value, but it's not a blocker in my opinion. Otherwise this all looks good to me!

includes/multi-currency/MultiCurrency.php Outdated Show resolved Hide resolved
@reykjalin reykjalin requested a review from bborman22 January 7, 2025 02:03
@reykjalin
Copy link
Contributor Author

The only note I had was that with JPY, since the price rounding options only goes to 1 (not 0) it essentially always uses a ceiling. I believe this is the desired behavior given the zero decimal aspect, but wanted to confirm that with you.

@bborman22, yes that is expected behavior if the rounding is set to 1. I'm surprised that there isn't a None or 0 option, but if 1 is the lowest available value then ceiling the amount is expected :)

Copy link
Contributor

@bborman22 bborman22 left a comment

Choose a reason for hiding this comment

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

I gave this another quick run through after that update and everything still looked good!

LGTM!

@reykjalin reykjalin added this pull request to the merge queue Jan 7, 2025
Merged via the queue into develop with commit 5098c26 Jan 7, 2025
25 checks passed
@reykjalin reykjalin deleted the add/round-to-nearest-lowest-denomination-before-applying-rounding-from-settings branch January 7, 2025 20:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants