-
Notifications
You must be signed in to change notification settings - Fork 10.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a filter to OrdersTableQuery to allow overriding of HPOS queries #39945
Conversation
Test Results SummaryCommit SHA: d8abb70
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hi @vedanshujain, Apart from reviewing the code changes, please make sure to review the testing instructions as well. You can follow this guide to find out what good testing instructions should look like: |
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.
@lsinger Nice work. I noted a few things and will leave the approval for @vedanshujain .
plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
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.
Looks good, added few more comments along with what Ron suggested.
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/tests/php/src/Internal/DataStores/Orders/OrdersTableQueryTests.php
Outdated
Show resolved
Hide resolved
5e8ff44
to
6b92530
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.
Left a couple of (very) minor notes about the filter docblock. Beyond that, I'm curious if we should provide a mechanism for query overrides to share the SQL they use? To illustrate:
use Automattic\WooCommerce\Internal\DataStores\Orders\OrdersTableQuery;
add_filter( 'woocommerce_hpos_pre_query', function ( $override ) {
// Assume I do some custom SQL here, before returning an alternative data-set.
return [
'orders' => [ /* some orders */ ],
];
} );
$query = new OrdersTableQuery;
// I get back the default SQL, not the SQL used by the callback.
echo $query->request;
This probably isn't essential (there is no @property-read
declaration for request
), but I thought I'd ask the question.
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
@barryhughes we could add that as an optional field in the $order_data array. Did you have a specific use case in mind? I'd like to make sure we understand what kind of usage we want to support before adding this. Since it would be an additional optional return value, I also wonder whether this should we a separate discussion and PR? |
No, not really—I just noticed that we can retrieve the query SQL (ie, via On taking a second look, I don't think we use the magic |
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.
Looks good to me, not sure if we want final sign-off by one of the other reviewers. Otherwise, may be a good candidate for needs: analysis
.
I re-requested another review from @vedanshujain as the HPOS DRI just for an extra level of thoroughness. |
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.
LGTM, added couple of super minor comments. Another note is, we require more detailed testing instructions than provided in the PR, can you please update them with an example of the filter than can be added to snippets? I think a nice testing instruction set could go like:
- Create couple of orders, note their ID.
- Add a filter snippet so that order query only return those IDs.
- Go to order list screen, and verify that only those orders are displayed.
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
plugins/woocommerce/src/Internal/DataStores/Orders/OrdersTableQuery.php
Outdated
Show resolved
Hide resolved
Co-authored-by: Vedanshu Jain <vedanshu.jain.2012@gmail.com>
Submission Review Guidelines:
Changes proposed in this Pull Request:
This PR adds a filter to the
OrdersTableQuery
class to allow for the overriding of HPOS queries.How to test the changes in this Pull Request:
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
woocommerce.php
, so that an HPOS-based order query will only return those IDs. Example: