-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement @woocommerce/price-format dependency #29
base: trunk
Are you sure you want to change the base?
Implement @woocommerce/price-format dependency #29
Conversation
af79156
to
6fc3130
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm finding it hard to follow what's happening, I left some comments about (what I believe to be) redundant code and eager abstraction.
To my mind, this is how it should be done:
- Convert the string provided from
"50"
to5000
. This is, to my knowledge, not something that `@woocommerce/format-price provide, but is something we're doing in Filter By Product block. - Do the math.
- Format result back.
This should all happen directly on the component, no need for extra utils that are one time use, depending on how or easy 1 is, it might get its own utility function to reduce clutter, the rest can stay.
const currentTotal = getCurrentTotal( cart ); | ||
const minorUnit = getMinorUnit( cart ); | ||
const remaining = getRemaining( freeShippingFrom, currentTotal, minorUnit ); | ||
const currency = getCurrencyFormat( cart ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like an early abstraction that shouldn't happen yet until you actually need it, further more, some of functions are useless if you check for cart here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean with the early abstraction. Could you elaborate on that? And could you tell me which functions you think are useless here? I created them to extract the cart total, the minor units and the currency format from the cart object, if a cart object is available.
src/util.js
Outdated
* @param {Object} cart The cart object. | ||
* @returns {Object} The currency format object. | ||
*/ | ||
export function getCurrencyFormat( cart ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There seems to be a lot of redundant logic here, you can get currency by using getCurrencyFromPriceResponse( cart.cartTotals )
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I removed my function getCurrencyFormat()
and I'm using getCurrencyFromPriceResponse()
instead.
That's pretty much what I'm doing here. As for converting
I moved the helper functions into As I'm using I'm looking forward to hearing your thoughts on my feedback regarding your review and the additional notes I added before. |
Update dependency @wordpress/components to v19.1.5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changes look good, and Nadirs feedback was resolved. I made some small suggestions but nothing blocking. Test coverage also good.
Update wordpress monorepo
Remove obsolete icon
…of github.com:woocommerce/woocommerce-free-shipping-progress-bar-block into add/28-implement-@woocommerce-price-format-dependency # Conflicts: # src/components/progress-bar/index.js # src/components/progress-label/index.js
I applied all changes and fixed the integration tests, which broke due to adding |
Fixes #28
Note
The remaining price should be formatted using the @woocommerce/price-format dependency, which is included in the WooCommerce Blocks plugin.
Testing instructions
Before all test cases
Test 0 decimals currency
WP Admin » WooCommerce » Settings » Currency options
and use the following settings:Indonesian rupiah (Rp)
Left
.
,
0
Test 2 decimals currency
WP Admin » WooCommerce » Settings » Currency options
and use the following settings:USD $
Left + space
,
.
2
Test 3 decimals currency
WP Admin » WooCommerce » Settings » Currency options
and use the following settings:Libyan Dinar
Right + space
.
,
3