Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 4c629ce

Browse files
authored
Merge pull request #42 from grayloon/add-orders-endpoint
Add Orders Endpoint
2 parents 4b91618 + eba404a commit 4c629ce

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/Api/Orders.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Api;
4+
5+
class Orders extends AbstractApi
6+
{
7+
/**
8+
* Lists orders that match specified search criteria.
9+
*
10+
* @param int $pageSize
11+
* @param int $currentPage
12+
* @param array $filters
13+
*
14+
* @return array
15+
*/
16+
public function all($pageSize = 50, $currentPage = 1, $filters = [])
17+
{
18+
return $this->get('/orders', array_merge($filters, [
19+
'searchCriteria[pageSize]' => $pageSize,
20+
'searchCriteria[currentPage]' => $currentPage,
21+
]));
22+
}
23+
}

tests/Api/OrdersTest.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Tests;
4+
5+
use Grayloon\Magento\Api\Orders;
6+
use Grayloon\Magento\MagentoFacade;
7+
use Illuminate\Support\Facades\Http;
8+
9+
class OrdersTest extends TestCase
10+
{
11+
public function test_can_call_magento_api_orders()
12+
{
13+
$this->assertInstanceOf(Orders::class, MagentoFacade::api('orders'));
14+
}
15+
16+
public function test_can_call_magento_api_orders_all()
17+
{
18+
Http::fake([
19+
'*rest/all/V1/orders*' => Http::response([], 200),
20+
]);
21+
22+
$api = MagentoFacade::api('orders')->all();
23+
24+
$this->assertTrue($api->ok());
25+
}
26+
27+
public function test_can_call_magento_api_orders_all_with_filter()
28+
{
29+
Http::fake([
30+
'*rest/all/V1/orders*' => Http::response([], 200),
31+
]);
32+
33+
$api = MagentoFacade::api('orders')->all(1, 1, [
34+
'searchCriteria[filterGroups][0][filters][0][field]' => 'customer_email',
35+
'searchCriteria[filterGroups][0][filters][0][value]' => '[email protected]',
36+
]);
37+
38+
$this->assertTrue($api->ok());
39+
}
40+
}

0 commit comments

Comments
 (0)