-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Add Pricing section #34382
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
Add Pricing section #34382
Conversation
Test Results SummaryCommit SHA: 77341e2
To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
# Conflicts: # plugins/woocommerce-admin/client/products/add-product-page.tsx # plugins/woocommerce-admin/client/products/layout/product-section-layout.scss # plugins/woocommerce-admin/client/products/sections/product-details-section.tsx
6a624ee to
83a46a7
Compare
joshuatf
left a comment
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.
Great work, Fernando! Looking really good.
Just left a few comments/questions.
| }; | ||
|
|
||
| return ( | ||
| <ProductSectionLayout |
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.
Could we use the FormSection component now that it's merged?
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 like the idea, I added it in the commit 72b843d
|
|
||
| if ( values.regular_price && ! /^[0-9.,]+$/.test( values.regular_price ) ) { | ||
| errors.regular_price = __( | ||
| 'Please enter with one monetary decimal point without thousand separators and currency symbols.', |
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 guess we're trying to keep this consistent for easier translation, right? I think adding a price may make this slightly more clear.
| 'Please enter with one monetary decimal point without thousand separators and currency symbols.', | |
| 'Please enter a price with one monetary decimal point without thousand separators and currency symbols.', |
Although, I would expect a price with thousands separator or currency to work and be sanitized.
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.
Nice catch! Yes, the price is currently sanitized. I added the validation just to be more defensive. It wouldn't hit the validation because I'm sanitizing it in the onChange method. I fixed the text in the commit dd6622e
|
|
||
| if ( values.sale_price && ! /^[0-9.,]+$/.test( values.sale_price ) ) { | ||
| errors.sale_price = __( | ||
| 'Please enter with one monetary decimal point without thousand separators and currency symbols.', |
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.
Same comment here.
| checked, | ||
| className: classnames( 'woocommerce-add-product__checkbox', className ), | ||
| onChange: ( isChecked: boolean ) => { | ||
| recordEvent( `add_product_checkbox_${ name }`, { |
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.
Does this only show on the "add prouct page" or will this also show on edit?
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 eyes! I modified this in the commit 99f7048
| name: 'My Product', | ||
| sale_price: 'text', | ||
| }; | ||
| const productSalePriceWithNotAllowedCharacters: Partial< Product > = { |
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.
Love these tests and the clear var naming ❤️
| name: 'My Product', | ||
| sale_price: 'text', | ||
| }; | ||
| const productSalePriceWithNotAllowedCharacters: Partial< Product > = { |
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.
Love these tests and the clear var naming ❤️
| recordEvent( 'add_product_pricing_help' ); | ||
| } } | ||
| > | ||
| How to price your product: expert tips |
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.
Think we'll need this localized.
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.
Fixed in the commit 1e35239
|
|
||
| <div className="woocommerce-product-form__custom-label-input"> | ||
| <label htmlFor="sale_price"> | ||
| Sale price |
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.
Will need these localized for translation as well. Probably will want to interpolate these to make translation easier.
| ONLY_ONE_DECIMAL_SEPARATOR.replaceAll( '%s', decimalSeparator ), | ||
| 'g' | ||
| ); | ||
| const cleanValue = value |
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.
If I change my decimal separator to , I'm no longer able to add numbers after the decimal. E.g., 10,59 gets updated to 10,00.
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 has been fixed in the commit 55c7c97
| /> | ||
| { ! isTaxSettingsResolving && ( | ||
| <span className="woocommerce-product-form__secondary-text"> | ||
| Per your |
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.
Same comment here around localization and interpolation.
|
Thank you @joshuatf for your review. |
joshuatf
left a comment
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.
Thanks for changes on this, @octaedro! They look good and are testing well for me.
I left a few optional comments, but one I'd really love to see either here or a follow-up is extracting the sanitizePrice logic to a utils file so we can test it more easily. But I won't block you on this PR if you want to merge and we can follow-up on this.
| <div className="woocommerce-product-form__custom-label-input"> | ||
| <InputControl | ||
| label={ __( 'List price', 'woocommerce' ) } | ||
| placeholder={ __( '10.59', 'woocommerce' ) } |
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.
We can always update this later, but I wonder if this is something that shouldn't be translated since store languages don't always match store currencies.
| 'woocommerce' | ||
| ), | ||
| components: { | ||
| span: <span className="woocommerce-product-form__optional-input" />, |
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.
Would it be worthwhile to include (optional) as its own text here so that it can be translated once? Not sure if this advantageous or not.
| span: <span className="woocommerce-product-form__optional-input" />, | |
| span: <span className="woocommerce-product-form__optional-input">{ __( '(optional)', 'woocommerce' ) }</span>, |
| const context = useContext( CurrencyContext ); | ||
| const { getCurrencyConfig } = context; | ||
| const { decimalSeparator } = getCurrencyConfig(); | ||
| const priceValidation = ( value: string, name: string ) => { |
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.
It would be awesome to extract most of this logic into a separate function so that it's easier to test and this function becomes:
const sanitizedValue = sanitizePrice( value );
setValue( name, sanitizedValue );|
Thank you @joshuatf for your review. |
All Submissions:
Changes proposed in this Pull Request:
This PR aims to add a Pricing section and the fields
List priceandSale price.In a follow-up PR, we should replace the component ProductSectionLayout with FormSection.
Closes # 37-gh-woocommerce/mothra-private 44-gh-woocommerce/mothra-private .
How to test the changes in this Pull Request:
Products>Add New (MVP)and create a product.List price, and that the price list is correctly formatted after the input loses focus.WooCommerce>Settings>General(URL: /wp-admin/admin.php?page=wc-settings) and change the currency options, verify that the currency reflects the changes that you have made.Other information:
pnpm changelog add --filter=<project>?FOR PR REVIEWER ONLY: