Skip to content

Conversation

@octaedro
Copy link
Contributor

@octaedro octaedro commented Aug 18, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR aims to add a Pricing section and the fields List price and Sale price.

In a follow-up PR, we should replace the component ProductSectionLayout with FormSection.

screenshot-clean local-2022 08 23-10_58_00

Closes # 37-gh-woocommerce/mothra-private 44-gh-woocommerce/mothra-private .

How to test the changes in this Pull Request:

  1. Go to Products > Add New (MVP) and create a product.
  2. Verify that it's possible to add a List price, and that the price list is correctly formatted after the input loses focus.
  3. Add multiple decimal points and verify that the data is being saved in the DB correctly and that the amount is being shown as it should after leaving the input.
  4. The amount should stay the same after refreshing the page.
  5. Verify that it's possible to add negative numbers.
  6. Go to 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.
  7. Taxes
  • If tax is included in the price, the helper text reads: Per your store settings, tax is included in the price.
  • If tax is excluded from the price, the helper text reads: Per your store settings, tax is not included in the price.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully run tests with your changes locally?
  • Have you created a changelog file for each project being changed, ie pnpm changelog add --filter=<project>?

FOR PR REVIEWER ONLY:

  • I have reviewed that everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities. I made sure Linting is not ignored or disabled.

@github-actions
Copy link
Contributor

github-actions bot commented Aug 18, 2022

Test Results Summary

Commit SHA: 77341e2

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests000000NaNm NaNs
E2E Tests186001018713m 54s
To view the full API test report, click here.
To view the full E2E test report, click here.
To view all test reports, visit the WooCommerce Test Reports Dashboard.

@octaedro octaedro changed the title Add/30 list price field Add Pricing section Aug 19, 2022
# 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
@octaedro octaedro force-pushed the add/30_list_price_field branch from 6a624ee to 83a46a7 Compare August 23, 2022 17:53
@octaedro octaedro marked this pull request as ready for review August 23, 2022 17:58
@octaedro octaedro requested a review from a team August 23, 2022 18:32
Copy link
Contributor

@joshuatf joshuatf left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.',
Copy link
Contributor

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.

Suggested change
'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.

Copy link
Contributor Author

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.',
Copy link
Contributor

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 }`, {
Copy link
Contributor

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?

Copy link
Contributor Author

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 > = {
Copy link
Contributor

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 > = {
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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&nbsp;
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor Author

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&nbsp;
Copy link
Contributor

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.

@github-actions github-actions bot added the package: @woocommerce/components issues related to @woocommerce/components label Aug 25, 2022
@octaedro
Copy link
Contributor Author

Thank you @joshuatf for your review.
I addressed the changes you suggested.
Could you take another look at this PR?

@octaedro octaedro requested a review from joshuatf August 25, 2022 18:33
Copy link
Contributor

@joshuatf joshuatf left a 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' ) }
Copy link
Contributor

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" />,
Copy link
Contributor

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.

Suggested change
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 ) => {
Copy link
Contributor

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 );

@octaedro
Copy link
Contributor Author

Thank you @joshuatf for your review.
I'm going to go ahead and merge this PR and handle the suggestions in a follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: @woocommerce/components issues related to @woocommerce/components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants