Skip to content
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

Sort and filter orders and other resource types by date modified #37

Closed
claudiosanches opened this issue Oct 17, 2017 · 58 comments
Closed
Assignees
Labels
has pull request Issue that has pull request.

Comments

@claudiosanches
Copy link
Contributor

Ref woocommerce/woocommerce#17262

@robmonk
Copy link

robmonk commented Dec 7, 2017

Is there any plan to address filtering by date modified anytime soon?

This is a really important enhancement for us that will allow us to EFFICIENTLY identify orders that have been recently modified such that they are now eligible for import into our application. Our application looks for new and modified orders every hour for all WooCommerce stores across our customer base -- looking back many hours to many days on every hourly query for all WooCommerce stores across our customer base to catch updated orders that are now in an eligible state for import into our app is incredibly inefficient - the lack of this functionality negatively impacts our application performance and our customers who have WooCommerce stores.

@lester-fh
Copy link

lester-fh commented Jan 5, 2018

Filtering or Sorting on Modified Date is essential to this api functioning efficiently. I can't see any other way to detect modified orders, other than rescanning an entire range of old orders. This is fine for smaller projects, but we have hundreds of thousands of orders to scan if we want to be determinant.

@franzferdinand
Copy link

Same here: Our software processes orders for numerous WooCommerce merchants in order to automatically create invoices for them. This enhancement would be a great relief for us and our customers.

@rcojoe
Copy link

rcojoe commented Feb 7, 2018

@lester-fh ,
I have been looking everywhere for this and can't find an answer, so I dug into it and found this article that gave me the starting point to work towards my solution.
https://francescocarlucci.com/woocommerce-api-add-custom-data-default-endpoints/

Sometimes I just need some helper code to get me started. This here will return a list of products that were modified since the passed parameter "last_modified".
Here is my php api call.
print_r($woocommerce->get('products',array( "last_modified" => "2018-01-23T00:00:00Z")));

It will return the entire array of all products with an array key [0,1,2,3....] assigned to each (default api behavior). What this modification does, is it doesn't populate the data in the filtered records, so if you check that an entry has a particular key set, like "ID", then your program will process it. Otherwise, go to the next entry. Essentially, the products will be "filtered" so only valid entries are the ones with a last_modified date greater than 2018-01-23.

To use this with orders, find and replace "product" to "order" i.e. change "woocommerce_rest_prepare_product_object" to "woocommerce_rest_prepare_order_object"

This is in my functions.php file:

add_filter( 'woocommerce_rest_prepare_product_object', 'last_modified_update', 10, 3 ); 
function last_modified( $response, $object, $request ) { 
	if (!isset($request->get_params()['last_modified'])) return $response;
	if (strtotime($response->data['date_modified']) > strtotime($request->get_params()['last_modified'])){
	return $response;
	}
    //return $response;
    }

@mikejolley mikejolley changed the title Sort Orders by date modified Sort and filter orders and other resource types by date modified Apr 17, 2018
@jahglow

This comment has been minimized.

@KristapsBerzins

This comment has been minimized.

@franzferdinand
Copy link

We would be very grateful for this feature and appreciate your effort!

@ghost
Copy link

ghost commented Jun 5, 2018

This is absolutely essential to us and prevents us from migrating from legacy APIs to the later versions. I hope that newer WC versions won't remove the legacy v3 API before this is done.

@fbnz156

This comment has been minimized.

@sparkweb
Copy link

sparkweb commented Aug 9, 2018

I've been working on upgrading our Legacy V3 support and just ran into this. This is an absolute blocker to moving to the new wc-json endpoints.

@gregrobson
Copy link

This is really annoying. We have a case where occasionally webhooks don't fire so I need to check periodically. I'd rather not paginate all the order records as that will only get worse over time.

The only I can see is to register a custom API endpoint so you have /wp-json/acme/v1/orders?modified_after=<date1>&modified_before=<date2> that can return the post IDs of updated orders.

That does mean another round trip to the API using the list records and include parameter to grab bunches of post IDs for orders. http://woocommerce.github.io/woocommerce-rest-api-docs/#list-all-orders

Docs for adding custom endpoints for anyone going down this particular rabbit hole of "fun" 😉
https://developer.wordpress.org/rest-api/extending-the-rest-api/adding-custom-endpoints/
WP Query reference...
https://codex.wordpress.org/Class_Reference/WP_Query

@claudiosanches claudiosanches self-assigned this Sep 12, 2018
@LucaQapla

This comment has been minimized.

@LucaQapla

This comment has been minimized.

@LucaQapla

This comment has been minimized.

@claudiosanches
Copy link
Contributor Author

@LucaQapla I'll post here when I have some news, if not, there is no news.

@MioPedersen
Copy link

@claudiosanches I can see that v3 of the API is out. Have this feature been implemented in this version? We've been wanting it for so long, and it doesn't make sense that our old API implementation is more feature rich than the newest.

@florianbepunkt
Copy link

also interested… could not find this in the docs

@daomeideshu
Copy link

Hello,
We also need the feature to get orders "modified after a date".
Any news?

@LucaQapla

This comment has been minimized.

@andycheng123
Copy link

This is an essential function.
Hope it will be implemented soon

@koenhoeijmakers
Copy link

It's a milestone for v4 so we'll see it when v4 is released i suppose.

@florianbepunkt
Copy link

This has been on the roadmap for quite some time and originally was supposed to land in V3: #17262

Not sure if there is a recommendation for running WooCommerce in a connected eCommerce system where WooCommerce is just one piece of a puzzle besides an erp system or some sort of automated order processing system. Our current workaround is to use a webhook and periodically query for orders where the webhook has not fired properly. But it generates overhead and I would not recommend this for a high order load.

@andycheng123
Copy link

This has been on the roadmap for quite some time and originally was supposed to land in V3: #17262

Not sure if there is a recommendation for running WooCommerce in a connected eCommerce system where WooCommerce is just one piece of a puzzle besides an erp system or some sort of automated order processing system. Our current workaround is to use a webhook and periodically query for orders where the webhook has not fired properly. But it generates overhead and I would not recommend this for a high order load.

I did pretty much similar setup for my clients. The performance is not very good though...

@claudiosanches

This comment has been minimized.

@woocommerce woocommerce locked and limited conversation to collaborators Jan 16, 2019
@woocommerce woocommerce unlocked this conversation Apr 17, 2019
@mikejolley
Copy link
Member

I've reopened comments. Please keep on topic. Contributions are also welcome.

@johan855
Copy link

Hi, I see the previous comment from Claudio was marked as outdated, I cannot find any information related to this topic in the new release, does it mean this feature is not included on the latest 3.6 version?

@claudiosanches claudiosanches transferred this issue from woocommerce/wc-api-dev Oct 4, 2019
@issue-label-bot
Copy link

Issue-Label Bot is automatically applying the label type: feature request to this issue, with a confidence of 0.82. Please mark this comment with 👍 or 👎 to give our bot feedback!

Links: app homepage, dashboard and code for this bot.

@claudiosanches
Copy link
Contributor Author

Thank you for reporting this issue!

I'm closing the issue as it already has a PR, please continue the discussion over at #30

@claudiosanches claudiosanches added the has pull request Issue that has pull request. label Oct 4, 2019
@timjen3
Copy link

timjen3 commented Oct 10, 2019

@claudiosanches It looks like the linked ticket will only add filtering for Products / Variations. A lot of people are asking for filtering of orders in this issue. Is there another PR for filtering of Orders?

@anthonyabc
Copy link

@claudiosanches #30 Does NOT address this issue.

@stayhero
Copy link

stayhero commented Nov 7, 2019

@claudiosanches Yes, that does not address this issue. We would need to be able to filter for the modified date.

@kdekok
Copy link

kdekok commented Nov 11, 2019

Other issues DO NOT ADDRESS this one.
Please re-open issue and add orderby=date_modified, how hard can that be?

@kepeder
Copy link

kepeder commented Nov 26, 2019

Added another pull-request for querying orders as well by created and modified. #66

@codermrrob
Copy link

The lack of this feature makes integration with accounting systems incredibly difficult. Yes it is possible to create some kind of extension/plugin to deal with this but the reason we are trying to use the API is because plugins seem to be somewhat unreliable

@weaselmetal
Copy link

weaselmetal commented Jan 21, 2020

@claudiosanches if you merged both PR 66 and PR 30, then orders, products and product variants would support the requested filter, correct? You mentioned in the PR that the filter needs to be supported on all objects. Which ones? All that are documented in the API docs? Why would that be the case? What speaks against adding the filter option to objects where people actively requested their addition?

@MioPedersen
Copy link

Why this has not become a feature years ago is baffling to me. Would you just communicate if this is a feature that will be implemented or not? We have a ton of users who really need this feature, and we're constantly bombarded by issues because of this.

@homes2001
Copy link

This issue should get reopened. It was closed on Oct 4, 2019 because there was an open PR, but the PR was closed by @kepeder , without anything actually getting merged. The issue described here still remains, we are still looking for a way to only list orders modified after a certain date.

@Arohonka
Copy link

Arohonka commented Feb 3, 2020

Would this help, I just found this snippet and it works in backend: https://rudrastyh.com/wordpress/date-range-filter.html

@kepeder
Copy link

kepeder commented Feb 3, 2020

I merged multiple PRs into one, so that one is still open :-)

@lcs-prbnc
Copy link

I landed here, coming from an issue posted in 2017.
Can't believe the feature is not implemented yet 👎

@lucidjay
Copy link

lucidjay commented Jun 4, 2020

Cannot believe that such a basic feature that has been continuously requested by the community over the past 3 year and it is STILL not implemented...

@claudiosanches
Copy link
Contributor Author

We are considering this feature and it will get introduced in the next version of the REST API.

@diguardia
Copy link

It would be great!

@androidcode33
Copy link

androidcode33 commented Jul 19, 2020

This worked for me. With Woo 4.0.x / API v3.

add_filter('woocommerce_rest_orders_prepare_object_query', function(array $args, \WP_REST_Request $request) {
$modified_after = $request->get_param('modified_after');
if (!$modified_after) {
    return $args;
}

$args['date_query'][0]['column'] = 'post_modified';
$args['date_query'][0]['after']  = $modified_after;

return $args;
} , 10, 2);

/wp-json/wc/v3/orders/?modified_after=2020-05-09T14:00:00

@reason8910
Copy link

@androidcode33 Would this function be able to filter products by date_modified?
What changes would have to be made. Thanks

@androidcode33
Copy link

androidcode33 commented Sep 8, 2020

@reason8910 No need to do any other changes.

Let me know if it works for you or any other inquiries.

thanks

@reason8910
Copy link

@reason8910 No need to do any other changes.

Let me know if it works for you or any other inquiries.

thanks

Wouldn't I need to change this line: woocommerce_rest_orders_prepare_object_query to woocommerce_rest_products_prepare_object_query

@androidcode33
Copy link

@reason8910 this worked for me on orders. I haven't tested it with products.

@weaselmetal
Copy link

@claudiosanches awesome news that this will be taken care of! Could you please point readers of this conversation to the issue(s) that implement the requested features? I found this #226 but it only deals with ordering, filtering resources by modified date is not part of the change afaict. Thank you!

@agastiazoro
Copy link

agastiazoro commented Nov 9, 2020

@reason8910 No need to do any other changes.
Let me know if it works for you or any other inquiries.
thanks

Wouldn't I need to change this line: woocommerce_rest_orders_prepare_object_query to woocommerce_rest_products_prepare_object_query

I've founded it, it's "woocommerce_rest_product_object_query"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has pull request Issue that has pull request.
Projects
None yet
Development

No branches or pull requests