This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from grayloon/customer-groups
Customer Group Endpoints
- Loading branch information
Showing
3 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Grayloon\Magento\Api; | ||
|
||
class CustomerGroups extends AbstractApi | ||
{ | ||
/** | ||
* Show the customer group by the provided ID. | ||
* | ||
* @param int $id | ||
* @return array | ||
*/ | ||
public function show($id) | ||
{ | ||
return $this->get('/customerGroups/'.$id); | ||
} | ||
|
||
/** | ||
* Save the customer group by the provided ID. | ||
* | ||
* @param int $id | ||
* @param array $customerGroupRepositoryV1SavePutBody | ||
* @return array | ||
*/ | ||
public function saveGroup($id, $customerGroupRepositoryV1SavePutBody = []) | ||
{ | ||
return $this->put('/customerGroups/'.$id, $customerGroupRepositoryV1SavePutBody); | ||
} | ||
|
||
/** | ||
* Delete customer group by the provided ID. | ||
* | ||
* @param int $id | ||
* @return array | ||
*/ | ||
public function deleteGroup($id) | ||
{ | ||
return $this->delete('/customerGroups/'.$id); | ||
} | ||
|
||
/** | ||
* Save/Create Customer Group. | ||
* | ||
* @param array $customerGroupRepositoryV1SavePutBody | ||
* @return array | ||
*/ | ||
public function createGroup($customerGroupRepositoryV1SavePostBody = []) | ||
{ | ||
return $this->post('/customerGroups', $customerGroupRepositoryV1SavePostBody); | ||
} | ||
|
||
/** | ||
* Search the Customer Groups. | ||
* | ||
* @param int $pageSize | ||
* @param int $currentPage | ||
* @param array $filters | ||
* | ||
* @return array | ||
*/ | ||
public function search($pageSize = 50, $currentPage = 1, $filters = []) | ||
{ | ||
return $this->get('/customerGroups/search', array_merge($filters, [ | ||
'searchCriteria[pageSize]' => $pageSize, | ||
'searchCriteria[currentPage]' => $currentPage, | ||
])); | ||
} | ||
|
||
/** | ||
* Get the default Customer Group. | ||
* | ||
* @return array | ||
*/ | ||
public function default() | ||
{ | ||
return $this->get('/customerGroups/default'); | ||
} | ||
|
||
/** | ||
* Set the system default customer group. | ||
* | ||
* @param int $id | ||
* @return array | ||
*/ | ||
public function setDefault($id) | ||
{ | ||
return $this->put('/customerGroups/default/'.$id); | ||
} | ||
|
||
/** | ||
* Check if customer group can be deleted. | ||
* | ||
* @param int $id | ||
* @return array|bool | ||
*/ | ||
public function permissions($id) | ||
{ | ||
return $this->get('/customerGroups/'.$id.'/permissions'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
namespace Grayloon\Magento\Tests; | ||
|
||
use Grayloon\Magento\Api\CustomerGroups; | ||
use Grayloon\Magento\MagentoFacade; | ||
use Illuminate\Support\Facades\Http; | ||
|
||
class CustomerGroupsTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_can_instanciate() | ||
{ | ||
$this->assertInstanceOf(CustomerGroups::class, MagentoFacade::api('customerGroups')); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_show() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/1' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->show(1); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_save_group() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/1' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->saveGroup(1, []); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_delete_group() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/1' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->deleteGroup(1); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_create_group() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->createGroup([]); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_search_groups() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/search*' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->search(); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_get_default() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/default' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->default(); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
|
||
/** @test */ | ||
public function it_can_set_default() | ||
{ | ||
Http::fake([ | ||
'*rest/all/V1/customerGroups/default/1' => Http::response([], 200), | ||
]); | ||
|
||
$api = MagentoFacade::api('customerGroups')->setDefault(1); | ||
|
||
$this->assertTrue($api->ok()); | ||
} | ||
} |