-
Notifications
You must be signed in to change notification settings - Fork 221
Product Query: Add order by “best selling” as a preset #7687
Product Query: Add order by “best selling” as a preset #7687
Conversation
The release ZIP for this PR is accessible via:
|
TypeScript Errors ReportFiles with errors: 427 🎉 🎉 This PR does not introduce new TS errors. |
Size Change: +306 B (0%) Total Size: 971 kB
ℹ️ View Unchanged
|
Script Dependencies ReportThere is no changed script dependency between this branch and trunk. This comment was automatically generated by the |
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.
When testing this PR, I'm getting this error:
Is that something you can also reproduce, @sunyatasattva? The ProductQuery
class doesn't seem to have a extend_rest_query_allowed_params
method.
Thanks for catching that @Aljullu. Looks like something went wrong with the rebasing, perhaps? The actual method name was |
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 for updating the PR, @sunyatasattva!
I could work-around it making extend_rest_query_allowed_params
public. However, then I get a 400 error when the Product Query block tries to load products in the editor.
Can you reproduce as well?
This is odd. Here is a video of the flow working fine on my side. It's also interesting that I did not change the type of the method to EDIT: I read more about how WP Filters work, and indeed I guess it should be public. I am now very confused on how it worked in my case and didn't throw a fatal error. Any ideas? Anyways, I have updated it to be public. best-selling.movWhat's your environment? Are you able to reproduce on a fresh one? I wonder if perhaps there is a conflicting filter removing the allowed query params? Perhaps giving the filter a higher priority could solve this, if that's the case? I'm going to try and investigate a bit further to see whether I can break it. |
@Aljullu Tried changing the merging approach on the filter. Could you please also pull and test again? |
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.
It's working well on my end, now. Thanks for updating this PR, @sunyatasattva! Code changes look good as well.
It honestly was super mysterious on how things were working for me previously. I do not understand, but glad you tested. 🙏 |
This commits achieves the following: * Adds a section in the inspector control called “Popular Presets”, which contains a dropdown with popular presets. * Adds support for the first preset: “Best selling products”. By selecting this, users can sort products by total sales. * Switches the order of the custom inspector controls and the default Query Loop inspector controls: our controls will be now on top as per the latest design spec (see pdnLyh-2By-p2). * Restricts the allowed Query parameters to the sort orders we want to allow according to the latest design spec (disabling title and date). * Removes the core “Order By” dropdown. * Refactor `setCustomQueryAttribute` to `setQueryAttribute` because since a few iterations, our custom query attributes are not deeply nested anymore, and this function can be used for the normal query too.
…y block This commit does the following: * Adds the `popularity` value as an allowed value for `orderby` on `product` REST API calls. * Handles the query differently if the `orderby` value is one among the custom ones.
7cda22f
to
13a0331
Compare
Filters` to match with the updates from #7687
…ced Filters` (#7726) * E2E: Change label of product filters from `Product filters` to `Advanced Filters` to match with the updates from #7687 * rename test file and test title to advanced filters * E2E: Fix flaky test related to `waitForAllProductsBlockLoaded` (#7727) * explain the reason for try/catch
* Add support for “Popular Presets” for PQ block This commits achieves the following: * Adds a section in the inspector control called “Popular Presets”, which contains a dropdown with popular presets. * Adds support for the first preset: “Best selling products”. By selecting this, users can sort products by total sales. * Switches the order of the custom inspector controls and the default Query Loop inspector controls: our controls will be now on top as per the latest design spec (see pdnLyh-2By-p2). * Restricts the allowed Query parameters to the sort orders we want to allow according to the latest design spec (disabling title and date). * Removes the core “Order By” dropdown. * Refactor `setCustomQueryAttribute` to `setQueryAttribute` because since a few iterations, our custom query attributes are not deeply nested anymore, and this function can be used for the normal query too. * Add back-end support for sorting by Best Selling via the Product Query block * Adds the `popularity` value as an allowed value for `orderby` on `product` REST API calls. * Handles the query differently if the `orderby` value is one among the custom ones.
…ced Filters` (#7726) * E2E: Change label of product filters from `Product filters` to `Advanced Filters` to match with the updates from #7687 * rename test file and test title to advanced filters * E2E: Fix flaky test related to `waitForAllProductsBlockLoaded` (#7727) * explain the reason for try/catch
This PR achieves the following:
setCustomQueryAttribute
tosetQueryAttribute
because since a few iterations, our custom query attributes are not deeply nested anymore, and this function can be used for the normal query too.In order to achieve back-end compatibility, since the Product Query block uses the WordPress API as opposed to the Store API, we needed to add compatibility for the custom
popularity
meta value as a valid value of theorderby
parameter through a REST API filter. This shouldn't cause any side-effects, but it is important to know that we are meddling once more with the REST API itself (the other is to add compatibility for editor preview).Fixes #7324
References #7621
Accessibility
Other Checks
Screenshots
Testing
User Facing Testing
WooCommerce Visibility
Changelog