Skip to content

Conversation

@mattsherman
Copy link
Contributor

@mattsherman mattsherman commented Sep 2, 2022

All Submissions:

Changes proposed in this Pull Request:

This PR addresses a few code issues in the products pricing section:

  • Removes a bit of unused code
  • Switches from Currency().formatCurrency, which is deprecated, to Currency().formatAmount
  • Renames priceValidation to sanitizeAndSetPrice, which is more accurate (it was not validating the price, but rather sanitizing it and then setting it) and swaps the order of the name and value, which is more natural (name, value vs value, name)

This is a follow up to #34382

How to test the changes in this Pull Request:

  1. Go to Products> Add New (MVP and create a product.
  2. Verify that settings the regular and sale price works properly still, including sanitizing of any input value (no regression; functionality should be identical).

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 Sep 2, 2022

Test Results Summary

Commit SHA: 51f7542

Test 🧪Passed ✅Failed 🚨Broken 🚧Skipped ⏭️Unknown ❔Total 📊Duration ⏱️
API Tests11800201200m 42s
E2E Tests186001018716m 23s
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.

louwie17
louwie17 previously approved these changes Sep 2, 2022
Copy link
Contributor

@louwie17 louwie17 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀 nice work @mattsherman, thanks for keeping it small and not including it as part of other work ( I have something to learn from you :) )
Also appreciate not seeing the giant deprecated warning in the console anymore 👍 👍

Comment on lines 66 to 70
const taxSettingsText =
'Per your {{link}}store settings{{/link}}, tax is {{strong}}%sincluded{{/strong}} in the price.';
const addNot = pricesIncludeTax ? '' : 'not ';
taxSettingsText.replace( taxSettingsText, addNot );

Copy link
Contributor

@octaedro octaedro Sep 2, 2022

Choose a reason for hiding this comment

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

We will need the addNot to add it when the tax is not included in the price (37-gh-woocommerce/mothra-private).
The code should look like this:

	const addNot = pricesIncludeTax ? '' : 'not ';
	const taxSettingsElement = interpolateComponents( {
		mixedString: sprintf(
			__(
				'Per your {{link}}store settings{{/link}}, tax is {{strong}}%sincluded{{/strong}} in the price.',
				'woocommerce'
			),
			addNot
		),
		components: {
			link: (
				<Link
					href={ `${ ADMIN_URL }admin.php?page=wc-settings&tab=tax` }
					target="_blank"
					type="external"
					onClick={ () => {
						recordEvent( 'product_pricing_list_price_help' );
					} }
				>
					<></>
				</Link>
			),
			strong: <strong />,
		},
	} );

I missed that in my original PR.

Copy link
Contributor

@octaedro octaedro left a comment

Choose a reason for hiding this comment

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

Good job @mattsherman! The code looks good and other than the comment I left this is testing well on my end.

@mattsherman mattsherman force-pushed the update/products-pricing-section-cleanup branch from fcddacb to 51f7542 Compare September 2, 2022 20:09
Copy link
Contributor

@louwie17 louwie17 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 reverting the one change that @octaedro mentioned, this still tests well.
🚢

@mattsherman mattsherman merged commit c87d3c6 into trunk Sep 6, 2022
@mattsherman mattsherman deleted the update/products-pricing-section-cleanup branch September 6, 2022 14:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants