2

I want to list the orders with datePaid is within last 14 days. But I cannot workout the correct criteria, and I don't know if isPaid works correctly as well:

'criteria' => [
    'dateUpdated' => '>=' . date('Y-m-d'.' 00:00:00', strtotime("-14 days")),
    'isPaid' => '1',
],
| improve this question | | | | |
  • You said you're looking for datePaid, but your code example is using dateUpdated. Not sure if it's affecting your results, but ` 00:00:00` is probably unnecessary. isPaid should probably be a boolean. i.e. 'isPaid' => true. – Brad Bell Apr 18 '17 at 3:47
  • If none of that helps, try posting the rest of your element API config... could be something else in there. – Brad Bell Apr 18 '17 at 3:47
  • don't know why i type dateUpdated when i was thinking datePaid. Thanks, and now things fixed! – idolab Apr 18 '17 at 7:09
4

Here's an example elementapi.php that should get you going...this is returning shipping details but you can modify the transformer for whatever data you need of course...

return [
'endpoints' => [
    'api/json/orders/whatever.json' =>  [
        'paginate' => false,
        'elementType' => 'Commerce_Order',
        'criteria' =>   ['dateOrdered' => '>'. date('Y-m-d', strtotime("-2 weeks")),
                         'isPaid' => true,
                        ],

        'transformer' => function(Commerce_OrderModel $order) {
            return [
            "id" => $order->ISOrderNumber,   
            "fullname" => $order->shippingAddress->firstName ?? '' . " " . $order->shippingAddress->lastName ?? '',
            "firstname" => $order->shippingAddress->firstName ?? '',
            "lastname" => $order->shippingAddress->lastName ?? '',    
            "company" => $order->shippingAddress->businessName ?? '',
            "street1" => $order->shippingAddress->address1 ?? '',
            "street2" => $order->shippingAddress->address2 ?? '',
            "suburb" => $order->shippingAddress->city ?? '',
            "state" => $order->shippingAddress->stateName ?? '',
            "postcode" => $order->shippingAddress->zipCode ?? '',
            "phone" => $order->shippingAddress->phone ?? '',
            "mobile" => $order->shippingAddress->phone ?? '',
            "email" => $order->email ?? '', 
            ];
        },
    ], 

    // Next api thing to go here...

],

];

| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.