Skip to content

Commit

Permalink
Merge pull request #178 from aligent/release/1.10.0
Browse files Browse the repository at this point in the history
Release/1.10.0
  • Loading branch information
jswift authored Feb 23, 2023
2 parents 1ba118e + 9a18c34 commit ff13855
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 27 deletions.
13 changes: 8 additions & 5 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
### Fixes

- CartsApi Missing Optional Include Parameter #145 (Thanks @jracek-chl)
- ProductModifierValues was missing value data #150. This is a small breaking change
to the [ProductModifierValue](./blob/main/src/BigCommerce/ResourceModels/Catalog/Product/ProductModifierValue.php)
constructor.
- Fix incorrect endpoint and method for Create Redirect Urls (thanks @Mosnar)
- Updated storeinformation controller to match others (thanks @joelreeds)
- Fixed incorrect endpoint on OrdersApi (thanks @simpleapps-io)
- Handle the case of no orders returned in the V2 api causing error. (Issue #161)
- Fix `preorder_release_date` property type (Issue #162)
- Add `page_title` to Brand (Issue #171)


### New Features

- Implement [Site Routes API](https://developer.bigcommerce.com/api-reference/264af6ae04399-get-a-site-s-routes) #144
- Allow overriding of most Guzzle Client defaults, and also set a timeout
4 changes: 2 additions & 2 deletions src/BigCommerce/Api/Carts/CartRedirectUrlsApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@
*/
class CartRedirectUrlsApi extends UuidResourceWithUuidParentApi
{
private const REDIRECT_URL = 'carts/%d/redirect_urls';
private const REDIRECT_URL = 'carts/%s/redirect_urls';

public function create(): CartRedirectUrlsResponse
{
$response = $this->getClient()->getRestClient()->put(
$response = $this->getClient()->getRestClient()->post(
sprintf(self::REDIRECT_URL, $this->getParentUuid())
);

Expand Down
35 changes: 22 additions & 13 deletions src/BigCommerce/BaseApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ abstract class BaseApiClient
public const DEFAULT_HANDLER = 'handler';
public const DEFAULT_BASE_URI = 'base_uri';
public const DEFAULT_HEADERS = 'headers';
public const DEFAULT_TIMEOUT = 'timeout';

private const HEADERS__AUTH_CLIENT = 'X-Auth-Client';
private const HEADERS__AUTH_TOKEN = 'X-Auth-Token';
Expand All @@ -29,36 +30,44 @@ abstract class BaseApiClient

private array $debugContainer = [];

private array $defaultClientOptions = [
self::DEFAULT_TIMEOUT => 45,
self::DEFAULT_HEADERS => [
self::HEADERS__CONTENT_TYPE => self::APPLICATION_JSON,
self::HEADERS__ACCEPT => self::APPLICATION_JSON,
]
];

public function __construct(
string $storeHash,
string $clientId,
string $accessToken,
?\GuzzleHttp\Client $client = null
?\GuzzleHttp\Client $client = null,
?array $clientOptions = []
) {
$this->storeHash = $storeHash;
$this->clientId = $clientId;
$this->accessToken = $accessToken;
$this->setBaseUri(sprintf($this->defaultBaseUrl(), $this->storeHash));

$this->client = $client ?? $this->buildDefaultHttpClient();
$this->client = $client ?? $this->buildDefaultHttpClient($clientOptions);
}

private function buildDefaultHttpClient(): \GuzzleHttp\Client
private function buildDefaultHttpClient(array $clientOptions): \GuzzleHttp\Client
{
$history = Middleware::history($this->debugContainer);
$stack = HandlerStack::create();
$stack->push($history);

return new \GuzzleHttp\Client([
self::DEFAULT_HANDLER => $stack,
self::DEFAULT_BASE_URI => $this->getBaseUri(),
self::DEFAULT_HEADERS => [
self::HEADERS__AUTH_CLIENT => $this->clientId,
self::HEADERS__AUTH_TOKEN => $this->accessToken,
self::HEADERS__CONTENT_TYPE => self::APPLICATION_JSON,
self::HEADERS__ACCEPT => self::APPLICATION_JSON,
],
]);
$options = array_merge($this->defaultClientOptions, $clientOptions);
$options[self::DEFAULT_HANDLER] = $stack;
$options[self::DEFAULT_BASE_URI] = $this->getBaseUri();
$options[self::DEFAULT_HEADERS] = array_merge([
self::HEADERS__AUTH_CLIENT => $this->clientId,
self::HEADERS__AUTH_TOKEN => $this->accessToken,
], $options[self::DEFAULT_HEADERS]);

return new \GuzzleHttp\Client($options);
}

public function getBaseUri(): string
Expand Down
1 change: 1 addition & 0 deletions src/BigCommerce/ResourceModels/Catalog/Brand/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class Brand extends ResourceModel
public ?string $meta_description;
public string $image_url;
public string $search_keywords;
public string $page_title;

public function __construct(?stdClass $optionObject = null)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BigCommerce/ResourceModels/Catalog/Product/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Product extends ResourceModel
public string $date_created;
public string $date_modified;
public int $view_count;
public ?object $preorder_release_date;
public ?string $preorder_release_date;
public string $preorder_message;
public bool $is_preorder_only;
public bool $is_price_hidden;
Expand Down
6 changes: 5 additions & 1 deletion src/BigCommerceLegacyApi/Api/Orders/OrdersApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class OrdersApi extends V2ApiBase

private const ORDERS_ENDPOINT = 'orders';
private const ORDER_ENDPOINT = 'orders/%d';
private const ORDER_COUNT_ENDPOINT = '/orders/count';
private const ORDER_COUNT_ENDPOINT = 'orders/count';

public function singleResourceUrl(): string
{
Expand Down Expand Up @@ -86,6 +86,10 @@ public function getAll(array $filters = [], int $page = 1, int $limit = 250): ar
{
$response = $this->getAllResources($filters, $page, $limit);

if ($response->getStatusCode() === 204) {
return [];
}

return array_map(fn($r) => new OrderResponse($r), json_decode($response->getBody()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,20 @@ class StoreInformationApi extends V2ApiBase
*
* @return StoreInformation
* @throws \GuzzleHttp\Exception\GuzzleException
* @deprecated Replaced by `get()` function.
*/
public function storeInformation(): StoreInformation
{
return $this->get();
}

/**
* Returns metadata about a store.
*
* @return StoreInformation
* @throws \GuzzleHttp\Exception\GuzzleException
*/
public function get(): StoreInformation
{
$response = $this->getClient()->getRestClient()->get(
self::STORE_INFORMATION_ENDPOINT
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
"date_created": "2018-08-15T14:48:46+00:00",
"date_modified": "2018-09-05T20:42:07+00:00",
"view_count": 10,
"preorder_release_date": {},
"preorder_release_date": "",
"preorder_message": "",
"is_preorder_only": false,
"is_price_hidden": false,
Expand Down
4 changes: 2 additions & 2 deletions tests/BigCommerce/responses/catalog__products__get_all.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"date_created": "2018-08-15T14:48:46+00:00",
"date_modified": "2018-09-05T20:42:07+00:00",
"view_count": 10,
"preorder_release_date": {},
"preorder_release_date": null,
"preorder_message": "",
"is_preorder_only": false,
"is_price_hidden": false,
Expand Down Expand Up @@ -168,7 +168,7 @@
"date_created": "2018-08-15T14:48:36+00:00",
"date_modified": "2018-08-20T15:11:17+00:00",
"view_count": 21,
"preorder_release_date": {},
"preorder_release_date": "",
"preorder_message": "",
"is_preorder_only": false,
"is_price_hidden": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function testCanGetStoreInformation(): void
{
$this->setReturnData('storeinformation_store.json');

$information = $this->getApi()->storeInformation()->storeInformation();
$information = $this->getApi()->storeInformation()->get();

$this->assertEquals('BigCommerce', $information->name);
$this->assertEquals('my-awesome.store', $information->domain);
Expand All @@ -33,7 +33,7 @@ public function testCanGetStoreInformationForStoreWithNoLogo()
//Weird API design means the logo is set to empty array if no logo present
$this->setReturnData('storeinformation_store__no-logo.json');

$information = $this->getApi()->storeInformation()->storeInformation();
$information = $this->getApi()->storeInformation()->get();

$this->assertEquals('MLITest', $information->name);
$this->assertNull($information->logo);
Expand Down

0 comments on commit ff13855

Please sign in to comment.