Skip to content

Commit

Permalink
Implement the get all and get all for channel currency assignments en…
Browse files Browse the repository at this point in the history
…dpoints #53
  • Loading branch information
jswift committed Apr 13, 2021
1 parent 622920b commit 32a2852
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 21 deletions.
54 changes: 36 additions & 18 deletions src/BigCommerce/Api/Channels/ChannelCurrencyAssignmentsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

namespace BigCommerce\ApiV3\Api\Channels;

use BigCommerce\ApiV3\Api\Generic\ResourceWithBatchUpdateApi;
use BigCommerce\ApiV3\Api\Generic\BatchUpdateResource;
use BigCommerce\ApiV3\Api\Generic\CreateResource;
use BigCommerce\ApiV3\Api\Generic\DeleteResource;
use BigCommerce\ApiV3\Api\Generic\GetAllResources;
use BigCommerce\ApiV3\Api\Generic\UpdateResource;
use BigCommerce\ApiV3\Api\Generic\V3ApiBase;
use BigCommerce\ApiV3\ResponseModels\Channel\ChannelCurrencyAssignmentsResponse;
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse;
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;

Expand All @@ -11,44 +17,56 @@
*
*
*/
class ChannelCurrencyAssignmentsApi extends ResourceWithBatchUpdateApi
class ChannelCurrencyAssignmentsApi extends V3ApiBase
{
use GetAllResources;
use DeleteResource;
use UpdateResource;
use CreateResource;
use BatchUpdateResource;

public function batchUpdate(array $resources): PaginatedResponse
{
// TODO: Implement batchUpdate() method.
}
// batchcreate?
protected function multipleResourcesEndpoint(): string
private const CURRENCY_ASSIGNMENTS_ENDPOINT = 'channels/currency-assignments';
private const CURRENCY_ASSIGNMENT_ENDPOINT = 'channels/%d/currency-assignments';


public function create(): ChannelCurrencyAssignmentsResponse
{
// TODO: Implement multipleResourcesEndpoint() method.
}

protected function singleResourceEndpoint(): string
public function update(): ChannelCurrencyAssignmentsResponse
{
// TODO: Implement singleResourceEndpoint() method.
}

protected function resourceName(): string
public function batchUpdate(array $resources): ChannelCurrencyAssignmentsResponse
{
// TODO: Implement resourceName() method.
// TODO: Implement batchUpdate() method.
}

public function get(): SingleResourceResponse
public function getAll(array $filters = [], int $page = 1, int $limit = 250): ChannelCurrencyAssignmentsResponse
{
// TODO: Implement get() method.
return new ChannelCurrencyAssignmentsResponse($this->getAllResources($filters, $page, $limit));
}

public function getAll(array $filters = [], int $page = 1, int $limit = 250): PaginatedResponse
protected function multipleResourcesEndpoint(): string
{
// TODO: Implement getAll() method.
return self::CURRENCY_ASSIGNMENTS_ENDPOINT;
}

public function create(): SingleResourceResponse
/**
* Currency Assignment endpoints are different, they are all multiple resource endpoints, that may or may not
* be filtered by channel id.
*
* @return string
*/
public function multipleResourceUrl(): string
{
return $this->getParentResourceId() ? $this->singleResourceUrl() : $this->multipleResourcesEndpoint();
}

public function update(): SingleResourceResponse
public function singleResourceUrl(): string
{
return sprintf(self::CURRENCY_ASSIGNMENT_ENDPOINT, $this->getParentResourceId());
}
}
5 changes: 5 additions & 0 deletions src/BigCommerce/Api/Channels/ChannelsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,9 @@ public function site(): ChannelSitesApi
{
return new ChannelSitesApi($this->getClient(), null, $this->getResourceId());
}

public function currencyAssignments(): ChannelCurrencyAssignmentsApi
{
return new ChannelCurrencyAssignmentsApi($this->getClient(), null, $this->getResourceId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse;
use stdClass;

/**
* Note this doesn't seem to be used by the API currently, it returns an array of assignments always. This class
* is included for completeness
*/
class ChannelCurrencyAssignmentResponse extends SingleResourceResponse
{
private ChannelCurrencyAssignment $currencyAssignment;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,20 @@ class ChannelCurrencyAssignmentsApiTest extends BigCommerceApiTest
{
public function testCanGetCurrencyAssignment()
{
$this->markTestIncomplete();
$this->setReturnData('channel_currency_assignments.json');
$channelId = 1;

$currencyAssignments = $this->getApi()
->channel($channelId)->currencyAssignments()->getAll()->getCurrencyAssignments();
$this->assertEquals("channels/$channelId/currency-assignments", $this->getLastRequestPath());
$this->assertEquals('AUD', $currencyAssignments[0]->default_currency);
}

public function testCanGetAllCurrencyAssignments()
public function testCanGetAllChannelsCurrencyAssignments()
{
$this->markTestIncomplete();
$this->setReturnData('channel_currency_assignments.json');
$currencyAssignments = $this->getApi()->channels()->currencyAssignments()->getAll()->getCurrencyAssignments();
$this->assertEquals('channels/currency-assignments', $this->getLastRequestPath());
$this->assertEquals('AUD', $currencyAssignments[0]->default_currency);
}
}
12 changes: 12 additions & 0 deletions tests/BigCommerce/responses/channel_currency_assignments.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"data": [
{
"channel_id": 1,
"enabled_currencies": [
"AUD"
],
"default_currency": "AUD"
}
],
"meta": {}
}

0 comments on commit 32a2852

Please sign in to comment.