Jump to content

[API WebService] get orders sorted by date


Recommended Posts

Hello, I am developing a website to receive orders from several prestashop.
I bring the orders from php with;

$ opt = [
                     'resource' => 'orders',
                     'display' => '[id, reference, total_paid, id_customer, id_cart, id_address_delivery, current_state, payment, date_add]',
                     'sort' => '[id_DESC]',
                     'limit' => '10'
                     ];
             $ xml = $ webService-> get ($ opt);
             $ resources = $ xml-> orders-> children (); 

I have tried to change the sort to "date_add_DESC" but it does not return anything.
I have thought about ordering the array when I have filled it with php's usort () function,

            usort($ArrayPedidos, function ($a, $b) {
                return strcmp($a["fecha"], $b["fecha"]);
            });

but I can't, any help would be good for me. thanks.

array.png

Edited by anderrios (see edit history)
Link to comment
Share on other sites

  • 2 years later...

Hello, how are you? You're using a string comparison, not a date comparison. STRCMP() is a string function, so it converts idate to a string in 'YYYY-MM-DD' format and performs a string comparison. It does not convert '20030505' to the date '2003-05-05' and perform a date comparison. I hope this helps you. Best regards, and have a great day!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...