-
Notifications
You must be signed in to change notification settings - Fork 219
Products block: tax_query should be calculated only if __woocommerceAttributes is valid #9049
Conversation
…s valid This commit refactors the update_rest_query method in the ProductQuery.php file to improve code readability. It simplifies conditional expressions by introducing variables for clarity, and uses ternary operators to streamline the logic.
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: 0 B Total Size: 1.11 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.
Code looks good and it's testing as described, so approving. 🚀 I only left one comment inline about returning early. Besides that, I see there is no changelog entry in the PR, is that intentional? I think this change might be worth mentioning in the changelog.
$tax_query = $this->merge_tax_queries( $attributes_query, $visibility_query ); | ||
public function update_rest_query( $args, $request ): array { | ||
$woo_attributes = $request->get_param( '__woocommerceAttributes' ); | ||
$is_valid_attributes = is_array( $woo_attributes ); |
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.
Could we return early at this point? Ie:
if ( ! is_array( $woo_attributes ) ) {
return $args;
}
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.
Besides that, I see there is no changelog entry in the PR, is that intentional? I think this change might be worth mentioning in the changelog.
To be honest, I wasn't completely certain if this needed a changelog entry. However, I've now added one just in case. 🙂
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.
Could we return early at this point? Ie:
I considered adding an early return, but I realized we are using three attributes:
- __woocommerceStockStatus
- __woocommerceAttributes
- __woocommerceStockStatus
What if __woocommerceAttributes is null, but the other attributes have correct values? I wanted to avoid this corner case. However, I'm not certain if this situation will ever occur. 🤷🏻♂️
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.
Oh, right, I didn't think that __woocommerceAttributes
could be undefined while the other could be defined. 😅
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.
@Aljullu In my opinion, let's maintain the current implementation for now so we can release the fix. If necessary, I can revisit and make adjustments later. Does that sounds good to you? 🙂
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.
Sure thing!
…s valid (#9049) This commit refactors the update_rest_query method in the ProductQuery.php file to improve code readability. It simplifies conditional expressions by introducing variables for clarity, and uses ternary operators to streamline the logic.
* Single Product Template - Compatibility Layer: don't skip custom HTML (#9075) * Fix: tax_query should be calculated only if __woocommerceAttributes is valid (#9049) This commit refactors the update_rest_query method in the ProductQuery.php file to improve code readability. It simplifies conditional expressions by introducing variables for clarity, and uses ternary operators to streamline the logic. * Blockfied Single Product Template: Add support for template for specific product (#9069) * Product Price Block: remove ProductSelector (#8980) * Empty commit for release pull request * Make Woo_Directive_Store PHP 7.3 compatible (#9033) * update version * add changelog * add testing instructions * update zip link file testing * Update docs/internal-developers/testing/releases/1001.md Co-authored-by: Albert Juhé Lluveras <[email protected]> --------- Co-authored-by: Luigi Teschio <[email protected]> Co-authored-by: Manish Menaria <[email protected]> Co-authored-by: github-actions <[email protected]> Co-authored-by: Viktor Szépe <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]>
I've added a check to calculate
$tax_query
only if a valid__woocommerceAttributes
attribute is present, which resolves issue #8765.Additionally, I've refactored the update_rest_query method in the ProductQuery.php file to enhance code readability. This involves simplifying conditional expressions with variables and using ternary operators to streamline logic.
Fixes #8765
Testing
20
in the code above. If you don't have any products withproduct_cat=20
, feel free to change the category ID.trunk
branch and repeat steps 4 and 5. Due to the bug, you will observe that both array items contain all products, meaning thatproduct_cat=20
won't work for the second query path ("/wp/v2/product?per_page=100&product_cat=20").WooCommerce Visibility
Changelog