Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit b302b41

Browse files
committed
Merge branch 'release/v2.11.0'
2 parents c7321fb + f2f2021 commit b302b41

17 files changed

+397
-297
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# [2.11.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.10.0...v2.11.0) (2020-05-05)
2+
3+
4+
### Features
5+
6+
* **Error:** add helper methods to retrieve errors from exceptions ([fd09c89](https://github.com/commercetools/commercetools-php-sdk/commit/fd09c89ce1570913fdf2426b11b0309afbb42171))
7+
* **Error:** improve message for unknown ApiException ([24a91ad](https://github.com/commercetools/commercetools-php-sdk/commit/24a91adef569491c77ab2d76a584909963ac48ab))
8+
* **Message:** support InventoryEntryQuantitySet message ([043aebe](https://github.com/commercetools/commercetools-php-sdk/commit/043aebe7dba96b825efcd720f936e50d276a349d))
9+
* **Search:** add helper method to retrieve facets from search response ([2a24040](https://github.com/commercetools/commercetools-php-sdk/commit/2a24040b498cefd8cbc62178b68654869ffb6f5b))
10+
11+
12+
113
# [2.10.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.9.0...v2.10.0) (2020-04-02)
214

315

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commercetools-php-sdk-changelog",
3-
"version": "2.11.0",
3+
"version": "2.12.0",
44
"description": "commercetools PHP SDK changelog generator package description",
55
"homepage": "https://github.com/commercetools/commercetools-php-sdk",
66
"bugs": "https://github.com/commercetools/commercetools-php-sdk/issues",

src/Core/AbstractHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
abstract class AbstractHttpClient
1616
{
17-
const VERSION = '2.10.0';
17+
const VERSION = '2.11.0';
1818

1919
/**
2020
* @var AdapterInterface

src/Core/Error/ApiException.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<?php
2-
/**
3-
* @author @jenschude <[email protected]>
4-
*/
52

63
namespace Commercetools\Core\Error;
74

@@ -31,7 +28,7 @@ public function __construct(
3128
ResponseInterface $response = null,
3229
Exception $previous = null
3330
) {
34-
$code = $response ? $response->getStatusCode() : 0;
31+
$code = $response ? $response->getStatusCode() : ($previous ? $previous->getCode() : 0);
3532
parent::__construct($message, $code, $previous);
3633
$this->request = $request;
3734
$this->response = $response;
@@ -48,7 +45,8 @@ public static function create(
4845
Exception $previous = null
4946
) {
5047
if (is_null($response)) {
51-
return new self('Error completing request', $request, null, $previous);
48+
$message = $previous ? 'Error completing request: ' . $previous->getMessage() : "Error completing request";
49+
return new self($message, $request, null, $previous);
5250
}
5351

5452
$level = floor($response->getStatusCode() / 100);

src/Core/Error/ClientErrorException.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,10 @@
1111
*/
1212
class ClientErrorException extends ApiServiceException
1313
{
14+
public function getErrorContainer()
15+
{
16+
$errors = parent::getErrors();
17+
18+
return ErrorContainer::fromArray($errors);
19+
}
1420
}

src/Core/Error/ConcurrentModificationException.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,12 @@
1414
*/
1515
class ConcurrentModificationException extends ClientErrorException
1616
{
17+
public function getCurrentVersion()
18+
{
19+
$error = $this->getErrorContainer()->getByCode(ConcurrentModificationError::CODE);
20+
if ($error instanceof ConcurrentModificationError) {
21+
return $error->getCurrentVersion();
22+
}
23+
return null;
24+
}
1725
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
4+
namespace Commercetools\Core\Model\Message;
5+
6+
use Commercetools\Core\Model\Common\DateTimeDecorator;
7+
use DateTime;
8+
use Commercetools\Core\Model\Common\Reference;
9+
10+
/**
11+
* @package Commercetools\Core\Model\Message
12+
* @link https://docs.commercetools.com/http-api-message-types#inventoryentryquantityset-message
13+
* @method string getId()
14+
* @method InventoryEntryQuantitySetMessage setId(string $id = null)
15+
* @method int getVersion()
16+
* @method InventoryEntryQuantitySetMessage setVersion(int $version = null)
17+
* @method DateTimeDecorator getCreatedAt()
18+
* @method InventoryEntryQuantitySetMessage setCreatedAt(DateTime $createdAt = null)
19+
* @method DateTimeDecorator getLastModifiedAt()
20+
* @method InventoryEntryQuantitySetMessage setLastModifiedAt(DateTime $lastModifiedAt = null)
21+
* @method int getSequenceNumber()
22+
* @method InventoryEntryQuantitySetMessage setSequenceNumber(int $sequenceNumber = null)
23+
* @method Reference getResource()
24+
* @method InventoryEntryQuantitySetMessage setResource(Reference $resource = null)
25+
* @method int getResourceVersion()
26+
* @method InventoryEntryQuantitySetMessage setResourceVersion(int $resourceVersion = null)
27+
* @method string getType()
28+
* @method InventoryEntryQuantitySetMessage setType(string $type = null)
29+
* @method UserProvidedIdentifiers getResourceUserProvidedIdentifiers()
30+
* phpcs:disable
31+
* @method InventoryEntryQuantitySetMessage setResourceUserProvidedIdentifiers(UserProvidedIdentifiers $resourceUserProvidedIdentifiers = null)
32+
* phpcs:enable
33+
* @method int getOldQuantityOnStock()
34+
* @method InventoryEntryQuantitySetMessage setOldQuantityOnStock(int $oldQuantityOnStock = null)
35+
* @method int getNewQuantityOnStock()
36+
* @method InventoryEntryQuantitySetMessage setNewQuantityOnStock(int $newQuantityOnStock = null)
37+
* @method int getOldAvailableQuantity()
38+
* @method InventoryEntryQuantitySetMessage setOldAvailableQuantity(int $oldAvailableQuantity = null)
39+
* @method int getNewAvailableQuantity()
40+
* @method InventoryEntryQuantitySetMessage setNewAvailableQuantity(int $newAvailableQuantity = null)
41+
*/
42+
class InventoryEntryQuantitySetMessage extends Message
43+
{
44+
const MESSAGE_TYPE = 'InventoryEntryQuantitySet';
45+
46+
public function fieldDefinitions()
47+
{
48+
$definitions = parent::fieldDefinitions();
49+
$definitions['oldQuantityOnStock'] = [static::TYPE => 'int'];
50+
$definitions['newQuantityOnStock'] = [static::TYPE => 'int'];
51+
$definitions['oldAvailableQuantity'] = [static::TYPE => 'int'];
52+
$definitions['newAvailableQuantity'] = [static::TYPE => 'int'];
53+
54+
return $definitions;
55+
}
56+
}

src/Core/Request/Products/ProductProjectionSearchRequest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,4 +195,15 @@ public function httpRequest()
195195
$body = $this->convertToString($this->params);
196196
return new HttpRequest(HttpMethod::POST, $this->getPath(), $body, 'application/x-www-form-urlencoded');
197197
}
198+
199+
public function mapFacetsFromResponse($response)
200+
{
201+
if ($response instanceof ResponseInterface) {
202+
$response = $this->buildResponse($response);
203+
}
204+
if ($response->isError()) {
205+
return null;
206+
}
207+
return $response->getFacets();
208+
}
198209
}

src/Core/Response/PagedSearchResponse.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PagedSearchResponse extends PagedQueryResponse
2828
public function getFacets()
2929
{
3030
if (is_null($this->facets)) {
31-
$this->facets = FacetResultCollection::fromArray($this->getResponseKey(static::FACETS));
31+
$this->facets = FacetResultCollection::fromArray($this->getResponseKey(static::FACETS), $this->getContext());
3232
}
3333
return $this->facets;
3434
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Fixtures\Error;
4+
5+
use Commercetools\Core\Error\ApiException;
6+
use GuzzleHttp\Psr7\Request;
7+
use PHPUnit\Framework\TestCase;
8+
9+
class ApiExceptionTest extends TestCase
10+
{
11+
12+
public function testIncompleteRequest()
13+
{
14+
$request = $this->createMock(Request::class);
15+
$e = ApiException::create($request, null);
16+
$this->assertSame(0, $e->getCode());
17+
$this->assertSame('Error completing request', $e->getMessage());
18+
}
19+
20+
public function testIncompleteRequestWithPrevious()
21+
{
22+
$request = $this->createMock(Request::class);
23+
$previous = new \Exception("foo", 4);
24+
25+
$e = ApiException::create($request, null, $previous);
26+
$this->assertSame(4, $e->getCode());
27+
$this->assertSame('Error completing request: foo', $e->getMessage());
28+
}
29+
}

0 commit comments

Comments
 (0)