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

Commit 234c539

Browse files
authored
Merge pull request #66 from grayloon/customer-groups
Customer Group Endpoints
2 parents 56eb803 + b475a8a commit 234c539

File tree

3 files changed

+262
-0
lines changed

3 files changed

+262
-0
lines changed

README.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A Magento 2 API Object Oriented wrapper for a Laravel application.
2424
- [Categories](#categories)
2525
- [Customer Token](#customer-token)
2626
- [Customers](#customers)
27+
- [Customer Groups](#customer-groups)
2728
- [Guest Cart](#guest-cart)
2829
- [Orders](#orders)
2930
- [Product Attributes](#product-attributes)
@@ -212,6 +213,67 @@ Reset customer password.
212213
Magento::api('customers')->resetPassword($email, $resetToken, $newPassword);
213214
```
214215

216+
<a id="customer-groups"></a>
217+
218+
### Customer Groups
219+
220+
GET `/V1/customerGroups/{id}`
221+
222+
Show the customer group by the provided ID.
223+
```php
224+
Magento::api('customerGroups')->show($id);
225+
```
226+
227+
PUT `/V1/customerGroups/{id}`
228+
229+
Save the customer group by the provided ID.
230+
```php
231+
Magento::api('customerGroups')->saveGroup($id, $customerGroupRepositoryV1SavePutBody = []);
232+
```
233+
234+
DELETE `/V1/customerGroups/{id}`
235+
236+
Delete customer group by the provided ID.
237+
```php
238+
Magento::api('customerGroups')->deleteGroup($id);
239+
```
240+
241+
POST `/V1/customerGroups`
242+
243+
Save/Create Customer Group.
244+
```php
245+
Magento::api('customerGroups')->createGroup($customerGroupRepositoryV1SavePostBody = []);
246+
```
247+
248+
GET `/V1/customerGroups/search`
249+
250+
Search the Customer Groups.
251+
```php
252+
Magento::api('customerGroups')->search($pageSize = 50, $currentPage = 1, $filters = []);
253+
```
254+
255+
GET `/V1/customerGroups/default`
256+
257+
Get the default customer group.
258+
```php
259+
Magento::api('customerGroups')->default();
260+
```
261+
262+
PUT `/V1/customerGroups/default/{id}`
263+
264+
Set the default customer group.
265+
```php
266+
Magento::api('customerGroups')->setDefault($id);
267+
```
268+
269+
GET `/V1/customerGroups/{id}/permissions`
270+
271+
Determine if customer group can be deleted.
272+
```php
273+
Magento::api('customerGroups')->permissions($id);
274+
```
275+
276+
215277
<a id="guest-cart"></a>
216278
### Guest Cart (various)
217279

src/Api/CustomerGroups.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Api;
4+
5+
class CustomerGroups extends AbstractApi
6+
{
7+
/**
8+
* Show the customer group by the provided ID.
9+
*
10+
* @param int $id
11+
* @return array
12+
*/
13+
public function show($id)
14+
{
15+
return $this->get('/customerGroups/'.$id);
16+
}
17+
18+
/**
19+
* Save the customer group by the provided ID.
20+
*
21+
* @param int $id
22+
* @param array $customerGroupRepositoryV1SavePutBody
23+
* @return array
24+
*/
25+
public function saveGroup($id, $customerGroupRepositoryV1SavePutBody = [])
26+
{
27+
return $this->put('/customerGroups/'.$id, $customerGroupRepositoryV1SavePutBody);
28+
}
29+
30+
/**
31+
* Delete customer group by the provided ID.
32+
*
33+
* @param int $id
34+
* @return array
35+
*/
36+
public function deleteGroup($id)
37+
{
38+
return $this->delete('/customerGroups/'.$id);
39+
}
40+
41+
/**
42+
* Save/Create Customer Group.
43+
*
44+
* @param array $customerGroupRepositoryV1SavePutBody
45+
* @return array
46+
*/
47+
public function createGroup($customerGroupRepositoryV1SavePostBody = [])
48+
{
49+
return $this->post('/customerGroups', $customerGroupRepositoryV1SavePostBody);
50+
}
51+
52+
/**
53+
* Search the Customer Groups.
54+
*
55+
* @param int $pageSize
56+
* @param int $currentPage
57+
* @param array $filters
58+
*
59+
* @return array
60+
*/
61+
public function search($pageSize = 50, $currentPage = 1, $filters = [])
62+
{
63+
return $this->get('/customerGroups/search', array_merge($filters, [
64+
'searchCriteria[pageSize]' => $pageSize,
65+
'searchCriteria[currentPage]' => $currentPage,
66+
]));
67+
}
68+
69+
/**
70+
* Get the default Customer Group.
71+
*
72+
* @return array
73+
*/
74+
public function default()
75+
{
76+
return $this->get('/customerGroups/default');
77+
}
78+
79+
/**
80+
* Set the system default customer group.
81+
*
82+
* @param int $id
83+
* @return array
84+
*/
85+
public function setDefault($id)
86+
{
87+
return $this->put('/customerGroups/default/'.$id);
88+
}
89+
90+
/**
91+
* Check if customer group can be deleted.
92+
*
93+
* @param int $id
94+
* @return array|bool
95+
*/
96+
public function permissions($id)
97+
{
98+
return $this->get('/customerGroups/'.$id.'/permissions');
99+
}
100+
}

tests/Api/CustomerGroupsTest.php

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
3+
namespace Grayloon\Magento\Tests;
4+
5+
use Grayloon\Magento\Api\CustomerGroups;
6+
use Grayloon\Magento\MagentoFacade;
7+
use Illuminate\Support\Facades\Http;
8+
9+
class CustomerGroupsTest extends TestCase
10+
{
11+
/** @test */
12+
public function it_can_instanciate()
13+
{
14+
$this->assertInstanceOf(CustomerGroups::class, MagentoFacade::api('customerGroups'));
15+
}
16+
17+
/** @test */
18+
public function it_can_show()
19+
{
20+
Http::fake([
21+
'*rest/all/V1/customerGroups/1' => Http::response([], 200),
22+
]);
23+
24+
$api = MagentoFacade::api('customerGroups')->show(1);
25+
26+
$this->assertTrue($api->ok());
27+
}
28+
29+
/** @test */
30+
public function it_can_save_group()
31+
{
32+
Http::fake([
33+
'*rest/all/V1/customerGroups/1' => Http::response([], 200),
34+
]);
35+
36+
$api = MagentoFacade::api('customerGroups')->saveGroup(1, []);
37+
38+
$this->assertTrue($api->ok());
39+
}
40+
41+
/** @test */
42+
public function it_can_delete_group()
43+
{
44+
Http::fake([
45+
'*rest/all/V1/customerGroups/1' => Http::response([], 200),
46+
]);
47+
48+
$api = MagentoFacade::api('customerGroups')->deleteGroup(1);
49+
50+
$this->assertTrue($api->ok());
51+
}
52+
53+
/** @test */
54+
public function it_can_create_group()
55+
{
56+
Http::fake([
57+
'*rest/all/V1/customerGroups' => Http::response([], 200),
58+
]);
59+
60+
$api = MagentoFacade::api('customerGroups')->createGroup([]);
61+
62+
$this->assertTrue($api->ok());
63+
}
64+
65+
/** @test */
66+
public function it_can_search_groups()
67+
{
68+
Http::fake([
69+
'*rest/all/V1/customerGroups/search*' => Http::response([], 200),
70+
]);
71+
72+
$api = MagentoFacade::api('customerGroups')->search();
73+
74+
$this->assertTrue($api->ok());
75+
}
76+
77+
/** @test */
78+
public function it_can_get_default()
79+
{
80+
Http::fake([
81+
'*rest/all/V1/customerGroups/default' => Http::response([], 200),
82+
]);
83+
84+
$api = MagentoFacade::api('customerGroups')->default();
85+
86+
$this->assertTrue($api->ok());
87+
}
88+
89+
/** @test */
90+
public function it_can_set_default()
91+
{
92+
Http::fake([
93+
'*rest/all/V1/customerGroups/default/1' => Http::response([], 200),
94+
]);
95+
96+
$api = MagentoFacade::api('customerGroups')->setDefault(1);
97+
98+
$this->assertTrue($api->ok());
99+
}
100+
}

0 commit comments

Comments
 (0)