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 · 40 comments

Comments

@claudiosanches
Copy link
Member

@claudiosanches claudiosanches commented Oct 17, 2017

Ref woocommerce/woocommerce#17262

@robmonk

This comment has been minimized.

Copy link

@robmonk 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

This comment has been minimized.

Copy link

@lester-fh 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

This comment has been minimized.

Copy link

@franzferdinand franzferdinand commented Jan 25, 2018

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

This comment has been minimized.

Copy link

@rcojoe 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 was marked as spam.

Copy link

@jahglow jahglow commented May 8, 2018

Please add it, it's very embarassing that it's still not there!

@KristapsBerzins

This comment was marked as spam.

Copy link

@KristapsBerzins KristapsBerzins commented May 11, 2018

It's quite frustrating not having this feature yet. Quite mandatory in my opinion in e-commerce.

@franzferdinand

This comment has been minimized.

Copy link

@franzferdinand franzferdinand commented May 11, 2018

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

@aleksi-kallio

This comment has been minimized.

Copy link

@aleksi-kallio aleksi-kallio 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 was marked as spam.

Copy link

@fbnz156 fbnz156 commented Jul 12, 2018

How is this still not a thing? This is absolutely essential in absence of an IPN (ION? Instant Order Notification?) system to handle external invoicing, order tracking, etc.

@sparkweb

This comment has been minimized.

Copy link

@sparkweb 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

This comment has been minimized.

Copy link

@gregrobson gregrobson commented Sep 5, 2018

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 was marked as spam.

Copy link

@LucaQapla LucaQapla commented Sep 13, 2018

Hello,
I really need to have the ability to get orders "modified after a date". Any news?

@LucaQapla

This comment was marked as spam.

Copy link

@LucaQapla LucaQapla commented Sep 18, 2018

:'(

@LucaQapla

This comment was marked as off-topic.

Copy link

@LucaQapla LucaQapla commented Sep 23, 2018

no news?
@claudiosanches ?

@claudiosanches

This comment has been minimized.

Copy link
Member Author

@claudiosanches claudiosanches commented Sep 24, 2018

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

@MioPedersen

This comment has been minimized.

Copy link

@MioPedersen MioPedersen commented Oct 29, 2018

@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

This comment has been minimized.

Copy link

@florianbepunkt florianbepunkt commented Nov 5, 2018

also interested… could not find this in the docs

@daomeideshu

This comment has been minimized.

Copy link

@daomeideshu daomeideshu commented Dec 18, 2018

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

@LucaQapla

This comment was marked as spam.

Copy link

@LucaQapla LucaQapla commented Dec 24, 2018

Merry Christmas

@andycheng123

This comment has been minimized.

Copy link

@andycheng123 andycheng123 commented Jan 15, 2019

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

@koenhoeijmakers

This comment has been minimized.

Copy link

@koenhoeijmakers koenhoeijmakers commented Jan 15, 2019

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

@florianbepunkt

This comment has been minimized.

Copy link

@florianbepunkt florianbepunkt commented Jan 15, 2019

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

This comment has been minimized.

Copy link

@andycheng123 andycheng123 commented Jan 15, 2019

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 was marked as outdated.

Copy link
Member Author

@claudiosanches claudiosanches commented Jan 16, 2019

This will comes with WooCommerce 3.6.

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

This comment has been minimized.

Copy link
Member

@mikejolley mikejolley commented Apr 17, 2019

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

@johan855

This comment has been minimized.

Copy link

@johan855 johan855 commented Apr 17, 2019

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?

@madmath03

This comment has been minimized.

Copy link

@madmath03 madmath03 commented Apr 17, 2019

Since @mikejolley mentioned contributing for this, I guess it’s not available in 3.6 either.

@andycheng123

This comment has been minimized.

Copy link

@andycheng123 andycheng123 commented Apr 19, 2019

@timjen3

This comment has been minimized.

Copy link

@timjen3 timjen3 commented Apr 23, 2019

Until this enhancement gets implemented for the WP API, I'm still using the V3 WooCommerce API where you are able to pass these url params:
filter[updated_at_min]
filter[updated_at_max]

The parameters accept a date-time of format "%Y-%m-%dT%H:%M:%SZ". It seems to work fine, aside from the worry of using deprecated code.

@sharkguto

This comment has been minimized.

Copy link

@sharkguto sharkguto commented Apr 30, 2019

🤖
Any updates? I am able to orderby correct by last modified date on user interface (wp-admin), however by API not.

image

image

[f'{jj["date_paid_gmt"]} {jj["date_modified_gmt"]} - {jj["id"]}' for jj in wcapi.get("orders", params=dict(per_page=per_page, page=page, status="completed", order="asc", orderby="date")).json()[:8]]

my workaround is getting all records , parse de datetime and sort by it, using python... but this is very painfull for my system, and it would not be possible to scale in the future

Orderby "modified date", in orders api v3, makes totally sense to have in woocommerce api. Hope it will be implemented soon.

@spoyntersmith

This comment has been minimized.

Copy link

@spoyntersmith spoyntersmith commented May 2, 2019

I'd like to know whether this is possible on the customer endpoint.
like:
/wp-json/wc/v3/customers?filter[updated_at_min]=2020-01-01

@timjen3

This comment has been minimized.

Copy link

@timjen3 timjen3 commented Jun 12, 2019

@spoyntersmith You can't use that with the wp-json only with wc-api. As I recall, it should work for all the endpoints. You can also pass a parameter to limit how many items come back:
?filter[limit]=100

@Braintelligence

This comment has been minimized.

Copy link

@Braintelligence Braintelligence commented Aug 6, 2019

@timjen3 Can you please shed some light on how to use the wc-api instead of wp-json? I enabled legacy API in the settings but I just can't get a meaningful curl to work with wc-api.

EDIT: Nevermind, it was an issue with the maintenance mode.

@invertedfjord

This comment has been minimized.

Copy link

@invertedfjord invertedfjord commented Oct 4, 2019

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 am debating creating an extension custom endpoint that returns the orders by an updated at param.

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

This comment has been minimized.

Copy link

@issue-label-bot issue-label-bot bot commented Oct 4, 2019

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

This comment has been minimized.

Copy link
Member Author

@claudiosanches claudiosanches commented Oct 4, 2019

Thank you for reporting this issue!

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

@timjen3

This comment has been minimized.

Copy link

@timjen3 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

This comment has been minimized.

Copy link

@anthonyabc anthonyabc commented Oct 17, 2019

@claudiosanches #30 Does NOT address this issue.

@stayhero

This comment has been minimized.

Copy link

@stayhero 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

This comment has been minimized.

Copy link

@kdekok 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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
You can’t perform that action at this time.