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()); + } }