-
Notifications
You must be signed in to change notification settings - Fork 23
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 #24 from aligent/feature/order-metafields-api
Feature/order metafields api
- Loading branch information
Showing
8 changed files
with
123 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
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,39 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\Orders; | ||
|
||
use BigCommerce\ApiV3\Api\ResourceApi; | ||
use BigCommerce\ApiV3\ResponseModels\Order\OrderMetafieldResponse; | ||
use BigCommerce\ApiV3\ResponseModels\Order\OrderMetafieldsResponse; | ||
|
||
class OrderMetafieldsApi extends ResourceApi | ||
{ | ||
private const RESOURCE_NAME = 'metafields'; | ||
private const METAFIELD_ENDPOINT = 'orders/{order_id}/metafields'; | ||
private const METAFIELDS_ENDPOINT = 'orders/{order_id}/metafields/%d'; | ||
|
||
protected function singleResourceEndpoint(): string | ||
{ | ||
return self::METAFIELD_ENDPOINT; | ||
} | ||
|
||
protected function multipleResourcesEndpoint(): string | ||
{ | ||
return self::METAFIELDS_ENDPOINT; | ||
} | ||
|
||
protected function resourceName(): string | ||
{ | ||
return self::RESOURCE_NAME; | ||
} | ||
|
||
public function get(): OrderMetafieldResponse | ||
{ | ||
return new OrderMetafieldResponse($this->getResource()); | ||
} | ||
|
||
public function getAll(array $filters = [], int $page = 1, int $limit = 250): OrderMetafieldsResponse | ||
{ | ||
return new OrderMetafieldsResponse($this->getAllResources($filters, $page, $limit)); | ||
} | ||
} |
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,10 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResourceModels\Order; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Metafield; | ||
|
||
class OrderMetafield extends Metafield | ||
{ | ||
public string $resource_type = 'order'; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Order/OrderMetafieldResponse.php
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,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResponseModels\Order; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Order\OrderMetafield; | ||
use BigCommerce\ApiV3\ResponseModels\SingleResourceResponse; | ||
use stdClass; | ||
|
||
class OrderMetafieldResponse extends SingleResourceResponse | ||
{ | ||
private OrderMetafield $metafield; | ||
|
||
public function getMetafield(): OrderMetafield | ||
{ | ||
return $this->metafield; | ||
} | ||
|
||
protected function addData(stdClass $rawData): void | ||
{ | ||
$this->metafield = new OrderMetafield($rawData); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/BigCommerce/ResponseModels/Order/OrderMetafieldsResponse.php
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,22 @@ | ||
<?php | ||
|
||
namespace BigCommerce\ApiV3\ResponseModels\Order; | ||
|
||
use BigCommerce\ApiV3\ResourceModels\Order\OrderMetafield; | ||
use BigCommerce\ApiV3\ResponseModels\PaginatedResponse; | ||
|
||
class OrderMetafieldsResponse extends PaginatedResponse | ||
{ | ||
/** | ||
* @return OrderMetafield[] | ||
*/ | ||
public function getMetafields(): array | ||
{ | ||
return $this->getData(); | ||
} | ||
|
||
protected function resourceClass(): string | ||
{ | ||
return OrderMetafield::class; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
|
||
namespace BigCommerce\Tests\Orders; | ||
|
||
use BigCommerce\Tests\BigCommerceApiTest; | ||
|
||
class OrderMetafieldsApiTest extends BigCommerceApiTest | ||
{ | ||
public function testCanGetOrderMetafield(): void | ||
{ | ||
$this->markTestIncomplete(); | ||
} | ||
|
||
public function testCanGetAllOrderMetafields(): void | ||
{ | ||
$this->markTestIncomplete(); | ||
} | ||
} |