From a1aa7da86d805165e0ae289b5c12d75f74c407d6 Mon Sep 17 00:00:00 2001 From: Ilyas Salikhov Date: Thu, 6 Nov 2014 03:50:15 +0300 Subject: [PATCH] Add ordersList method --- lib/RetailCrm/ApiClient.php | 25 +++++++++++++++++++++++++ tests/RetailCrm/Tests/ApiClientTest.php | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/lib/RetailCrm/ApiClient.php b/lib/RetailCrm/ApiClient.php index a787f1f..beab987 100644 --- a/lib/RetailCrm/ApiClient.php +++ b/lib/RetailCrm/ApiClient.php @@ -108,6 +108,31 @@ class ApiClient return $this->client->makeRequest('/orders/history', Client::METHOD_GET, $parameters); } + /** + * Returns filtered orders list + * + * @param array $filter (default: array()) + * @param int $page (default: null) + * @param int $limit (default: null) + * @return void + */ + public function ordersList(array $filter = array(), $page = null, $limit = null) + { + $parameters = array(); + + if (sizeof($filter)) { + $parameters['filter'] = $filter; + } + if (null !== $page) { + $parameters['page'] = (int) $page; + } + if (null !== $limit) { + $parameters['limit'] = (int) $limit; + } + + return $this->client->makeRequest('/orders', Client::METHOD_GET, $parameters); + } + /** * Check ID parameter * diff --git a/tests/RetailCrm/Tests/ApiClientTest.php b/tests/RetailCrm/Tests/ApiClientTest.php index d4b80a5..cf5bc03 100644 --- a/tests/RetailCrm/Tests/ApiClientTest.php +++ b/tests/RetailCrm/Tests/ApiClientTest.php @@ -137,4 +137,25 @@ class ApiClientTest extends TestCase $this->assertTrue($response->success); $this->assertTrue(isset($response['orders'])); } + + /** + * @group integration + */ + public function testOrdersList() + { + $client = static::getApiClient(); + + $response = $client->ordersList(); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + $this->assertTrue(isset($response['orders'])); + + $response = $client->ordersList(array(), 1, 300); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertFalse($response->isSuccessful()); + + $response = $client->ordersList(array('paymentStatus' => 'paid'), 1); + $this->assertInstanceOf('RetailCrm\Response\ApiResponse', $response); + $this->assertTrue($response->isSuccessful()); + } }