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

Commit 079d956

Browse files
committed
chore: 🚧 Add Customer Group Endpoints
1 parent 56eb803 commit 079d956

File tree

2 files changed

+201
-0
lines changed

2 files changed

+201
-0
lines changed

src/Api/CustomerGroups.php

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
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+
* The list of 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+
/**
92+
* Check if customer group can be deleted.
93+
*
94+
* @param int $id
95+
* @return array|bool
96+
*/
97+
public function permissions($id)
98+
{
99+
return $this->get('/customerGroups/' . $id . '/permissions');
100+
}
101+
}

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)