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

Commit

Permalink
Merge pull request #66 from grayloon/customer-groups
Browse files Browse the repository at this point in the history
Customer Group Endpoints
  • Loading branch information
ahinkle authored May 20, 2021
2 parents 56eb803 + b475a8a commit 234c539
Show file tree
Hide file tree
Showing 3 changed files with 262 additions and 0 deletions.
62 changes: 62 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ A Magento 2 API Object Oriented wrapper for a Laravel application.
- [Categories](#categories)
- [Customer Token](#customer-token)
- [Customers](#customers)
- [Customer Groups](#customer-groups)
- [Guest Cart](#guest-cart)
- [Orders](#orders)
- [Product Attributes](#product-attributes)
Expand Down Expand Up @@ -212,6 +213,67 @@ Reset customer password.
Magento::api('customers')->resetPassword($email, $resetToken, $newPassword);
```

<a id="customer-groups"></a>

### Customer Groups

GET `/V1/customerGroups/{id}`

Show the customer group by the provided ID.
```php
Magento::api('customerGroups')->show($id);
```

PUT `/V1/customerGroups/{id}`

Save the customer group by the provided ID.
```php
Magento::api('customerGroups')->saveGroup($id, $customerGroupRepositoryV1SavePutBody = []);
```

DELETE `/V1/customerGroups/{id}`

Delete customer group by the provided ID.
```php
Magento::api('customerGroups')->deleteGroup($id);
```

POST `/V1/customerGroups`

Save/Create Customer Group.
```php
Magento::api('customerGroups')->createGroup($customerGroupRepositoryV1SavePostBody = []);
```

GET `/V1/customerGroups/search`

Search the Customer Groups.
```php
Magento::api('customerGroups')->search($pageSize = 50, $currentPage = 1, $filters = []);
```

GET `/V1/customerGroups/default`

Get the default customer group.
```php
Magento::api('customerGroups')->default();
```

PUT `/V1/customerGroups/default/{id}`

Set the default customer group.
```php
Magento::api('customerGroups')->setDefault($id);
```

GET `/V1/customerGroups/{id}/permissions`

Determine if customer group can be deleted.
```php
Magento::api('customerGroups')->permissions($id);
```


<a id="guest-cart"></a>
### Guest Cart (various)

Expand Down
100 changes: 100 additions & 0 deletions src/Api/CustomerGroups.php
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');
}
}
100 changes: 100 additions & 0 deletions tests/Api/CustomerGroupsTest.php
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());
}
}

0 comments on commit 234c539

Please sign in to comment.