-
Notifications
You must be signed in to change notification settings - Fork 219
Fix: Product Query editor preview with Stock Status setting #7682
Conversation
…tor preview can show the correct products corresponding to the enabled stock status
The release ZIP for this PR is accessible via:
|
TypeScript Errors ReportFiles with errors: 431 🎉 🎉 This PR does not introduce new TS errors. |
Size Change: 0 B Total Size: 972 kB ℹ️ 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.
I left a comment that's more about the future of this class than the code itself as it is. The code is fine and it works great. Thanks for fixing that.
src/BlockTypes/ProductQuery.php
Outdated
return $this->merge_queries( | ||
array_merge( $args, $on_sale_query ), | ||
$stock_query | ||
); |
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.
What is the advantage of this over array_merge( $args, $on_sale_query, $stock_query )
? We need to consider that we'll add more and more queries, already in #7687 I add another one which will conflict here, how should we do this in the future?
E.g.
return $this->merge_queries(
array_merge( $args, $on_sale_query, $best_selling_query ),
$stock_query
);
How do we decide what's $b
in the merge_queries
call?
My suggestion here is to actually refactor the merge_queries
call to accept multiple arguments, like most PHP array functions do. So the signature would be merge_queries(array ...$queries)
. I had suggested it here when this function was implemented, but we didn't go ahead with it because the advantages were not clear.
Now that we meet this problem, I think the advantages of having that is clearer, because we'll keep adding queries and we should just be able to do:
return $this->merge_queries(
$args, $on_sale_query, $best_selling_query, $stock_query
);
and don't worry about the internal implementation of that. 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.
What is the advantage of this over
array_merge( $args, $on_sale_query, $stock_query )
?
@sunyatasattva With the current implementation of the class and structure of WP_Query, we have to use merge_queries
for tax and meta query as tax_query
and meta_query
are arrays containing arrays.
How do we decide what's
$b
in themerge_queries
call?
As I mentioned above, queries containing tax_query
and/or meta_query
are $b
.
What do you think?
I strongly agree. merge_queries
should be the source of trust in merging queries. I can refactor it either in this PR or a follow-up PR. Tagging @gigitux here for more perspectives :)
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 created #7697, so we have more things on the table to discuss.
This PR has been marked as If deemed still relevant, the pr can be kept active by ensuring it's up to date with the main branch and removing the stale label. |
Script Dependencies ReportThe
This comment was automatically generated by the |
@sunyatasattva I updated this PR to use the latest |
@sunyatasattva I updated this PR base on our discussion in #7743. |
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.
Pre-approving this. We just need to decide on a consistent approach as I mention in my comment. Whichever one is fine by me :)
src/BlockTypes/ProductQuery.php
Outdated
if ( empty( $stock_statii ) ) { | ||
return array(); | ||
} |
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.
Alright, I see what you mean. We need to decide what is the approach we take at least within this class. I don't have a super strong opinion. Given the conversation in #7796, what do you think of the middle-ground I proposed there?
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.
Just commented there, I will update this PR following what we do with yours.
This PR updates the REST query to include the stock status meta query, so the editor preview can show the correct products corresponding to the enabled stock status.
This PR also update the
merge_queires
method to ensure properties are arrays before merging.Follow up #7397
Screenshots
Screen.Recording.2022-11-15.at.11.02.24.mov
Testing
Automated Tests
User Facing Testing
WooCommerce Visibility
Performance Impact
Changelog