-
Notifications
You must be signed in to change notification settings - Fork 219
Product Price block: add support to the Single Product Template #8609
Product Price block: add support to the Single Product Template #8609
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThe
This comment was automatically generated by the TypeScript Errors Report
assets/js/atomic/blocks/product-elements/price/edit.tsx
assets/js/atomic/blocks/product-elements/price/index.tsx assets/js/atomic/blocks/product-elements/shared/product-selector.tsx |
dc25b45
to
3d8a090
Compare
Size Change: +392 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
3d8a090
to
5205f52
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.
regularPrice={ | ||
isDescendentOfSingleProductTemplate | ||
? pricePreview | ||
: prices.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.
I'm wondering if since the lines 94-96 are using the same logic as these lines, if it would be better to store the logic in a variable/function. Just a precaution to prevent from someone from changing only one of them and forgot to change the other piece of the code in the future. Maybe something like this would work:
const price = isDescendentOfSingleProductTemplate
? pricePreview
: prices.price
...
return (
<ProductPrice
...
price={price}
...
regularPrice={price}
/>
)
What do you think?
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 point, but for the regular price props, it is necessary to use .regular_price
. I updated the code!
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.
Hi @gigitux, Well done! Except for minor things, everything else looks great to me 🙌🏻
I have left some minor suggestions but I don't have strong opinion about all of those 🙂
…ocks into 8479-product-price-block-add-support-to-the-single-product-template
Thanks folks, for your great comments! @imanish003 I addressed all your feedback! 💪
Yep, the goal is to use the Global Styles to change the dimension of the text. By default, we will set Global Styles in the default HTML template. So, it will be necessary to update #8515 |
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! Thank you for addressing all the raised points! LGTM! 🚀
Yep, the goal is to use the Global Styles to change the dimension of the text. By default, we will set Global Styles in the default HTML template. So, it will be necessary to update #8515
Cool, so after we merge this one I'll add it to the Default HTML Template
…-single-product-template
…-single-product-template
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.
Thank you for making the changes according to my suggestions. The updated code looks good to me. However, I have a minor question that I'd like to clarify, but it isn't a blocker for merging this pull request. So, I'm pre-approving the PR now. 🚀🙌🏻
onClick={ () => setIsEditing( true ) } | ||
> | ||
{ __( | ||
'Switch 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.
May I know if there is any reason behind adding ...
for Switch product…'
text?
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 don't know. It is the same string that there is in WithProductSelector
HOC https://github.com/woocommerce/woocommerce-blocks/blob/e4325c12dd3bca8bb236454e9af90ce6416f6940/assets/js/atomic/blocks/product-elements/shared/with-product-selector.js/#L79-L80
…-single-product-template
This PR added support to the Product Price block to Single Product Template.
Fixes #8479
On the implementation level, the main issue is that the atomic blocks support several contexts:
All Products Block
->withProductDataContext
HOCProducts Block
-> Gutenberg ContextSingle Product Template
-> Gutenberg ContextWithSelector
andwithProductDataContext
HOCswithProductDataContext
The HOC withProductDataContext servers pass the select product object to the block.
With Selector
The HOC withSelector, when the
ProductDataContext
isn't defined, renders a modal for selecting the product and setting the product id in the context. In this way, the block can fetch the right data.We added the support to different contexts at different times, so the code isn't in the best shape, which influenced the work for this PR.
It was necessary to create a component identical to the ´WithSelector` HOC. There is no need to show the selector product modal when the block is inside the Single Product template. Using a component, we can easily distinguish the two cases.
In any case, we should refactor all the atomic blocks and create a common logic easily to check and with great type safety: should we put it as a cooldown task?
Testing
User Facing Testing
WooCommerce Visibility
Changelog