-
Notifications
You must be signed in to change notification settings - Fork 219
Fix: incorrect default number of products in editor when inheriting query #10303
Conversation
The release ZIP for this PR is accessible via:
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the TypeScript Errors Report
🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +147 B (0%) Total Size: 1.34 MB
ℹ️ View Unchanged
|
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 @dinhtungdu,
Thanks for working on this. I was verifying the number of products as mentioned in the following table:
However, for the Product (Beta) block, the number of products is not correct in the Editor. It's showing 9 products instead of 12 in the editor. But, it displays the correct number of products on the frontend. I'm not sure if this is happening only for me. 🤷🏻♂️
@@ -139,6 +139,7 @@ export const WooInheritToggleControl = ( | |||
setQueryAttribute( props, { | |||
...props.defaultWooQueryParams, | |||
inherit, | |||
__woocommerceInherit: inherit, |
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.
AFAIK, we should use inherit
instead of __woocommerceInherit
. The __woocommerceInherit
is added only when isCustomInheritGlobalQueryImplementationEnabled
is true, but we've decided not to implement the custom inherit query from template. Therefore, this flag will always be false, as seen here. You can also find related discussion on Slack here: p1681812585287949-slack-C02UBB1EPEF.
In short, we shouldn’t use __woocommerceInherit
. Additionally, I believe we can remove the isCustomInheritGlobalQueryImplementationEnabled
flag and related code since we decided not to implement the "custom inherit query from template." I understand it might be confusing because there is still a partial implementation for the "custom inherit query from template," which is disabled by using the isCustomInheritGlobalQueryImplementationEnabled
flag.
Does that make sense?
CC: @gigitux
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.
In short, we shouldn’t use __woocommerceInherit. Additionally, I believe we can remove the isCustomInheritGlobalQueryImplementationEnabled flag and related code since we decided not to implement the "custom inherit query from template." I understand it might be confusing because there is still a partial implementation for the "custom inherit query from template," which is disabled by using the isCustomInheritGlobalQueryImplementationEnabled flag.
Since the logic is added on the Products block (that will be deprecated) I agree with you, we can remove that logic!
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 @imanish003 for the review, I agree this is a bit confusing, so let's discuss more.
- In 0d8fc18, I fixed the issue you mentioned in the review. I didn't handle well the case adding the block into archive template in the template editor.
- I use the
__woocommerceInherit
attribute just for detecting if the current rest query is inherited from template. I used it in therest_product_query
filter here (as a custom rest query argument). The reason for that is I can't find a better way, I'm open to any alternative that we can detect the 'inherit state' in the rest query. I admit this is a workaround than a solution, but given that theProducts (Beta)
block will be deprecated, this is acceptable IMO. - About removing
isCustomInheritGlobalQueryImplementationEnabled
, let's do it in a separated PR for better history.
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.
In 0d8fc18, I fixed the issue you mentioned in the review. I didn't handle well the case adding the block into archive template in the template editor.
Not sure why but it's still showing 9 products in Products beta block 🤔 Are you able to replicate this?
I use the __woocommerceInherit attribute just for detecting if the current rest query is inherited from template. I used it in the rest_product_query filter here (as a custom rest query argument). The reason for that is I can't find a better way, I'm open to any alternative that we can detect the 'inherit state' in the rest query. I admit this is a workaround than a solution, but given that the Products (Beta) block will be deprecated, this is acceptable IMO.
Got it. In that case, maybe we should consider naming this something other than __woocommerceInherit because its original intention was for use in the "custom inherit from query" implementation. Since this fix is not directly related to "custom inherit from query," using __woocommerceInherit for this fix might cause confusion. What do you think?
About removing isCustomInheritGlobalQueryImplementationEnabled, let's do it in a separated PR for better history.
Definitely, Also this doesn't fall into scope of this PR.
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.
Since this fix is not directly related to "custom inherit from query," using __woocommerceInherit for this fix might cause confusion. What do you think?
@imanish003 Because we're removing that "custom inherit feature", and the Products (Beta) block will be deprecated eventually, I don't think that's a big issue. But by the way, any name will work, I will try to find another one to clear any potential confusion.
Not sure why but it's still showing 9 products in Products beta block 🤔 Are you able to replicate this?
Let's pair on this.
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.
But by the way, any name will work, I will try to find another one to clear any potential confusion.
Thank you so much for your understanding. Since we're unsure who will be working on removing the "custom inherit query" feature, it's better to avoid any potential confusion if we can. 🙌🏻
@imanish003 I updated my PR to fix the issue with Products Beta block, can you please take another look at this? |
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.
Awesome work! Tested and confirmed that the Products beta block in the Editor now displays 12 products. 🚀
Something to clarify:
cc @imanish003 |
Fixes #10228
In this PR, we're using two different approaches to fix the same problem:
Products (Beta)
block, as we're extending the Query Loop block, we expose the__woocommerceInherit
parameter to the REST query then modify query using therest_product_query
filter to inject the correct loop items per page value to theposts_per_page
argument.Product Collection
block, because we have total control over the codebase, we're following what Gutenberg does with the Query Loop block by setting the correct loop items per page directly in the edit component.Other Checks
Testing
Automated Tests
User Facing Testing
WooCommerce Visibility
Because this PR updates the
Products (Beta)
, I checked the box forWooCommerce Core
too.Performance Impact
N/a
Changelog