diff --git a/changes.md b/changes.md index 2c072c4fdc..b97981e2b5 100644 --- a/changes.md +++ b/changes.md @@ -42,6 +42,13 @@ - added enum `product-tailoring` to type `ResourceTypeId` + +
+Added Method(s) + +- added method `$apiRoot->withProjectKey()->productTailoring()->head()` +
+ **Import changes**
diff --git a/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyProductTailoringTest.php b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyProductTailoringTest.php index 8b2a228d44..07b606108f 100644 --- a/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyProductTailoringTest.php +++ b/lib/commercetools-api-tests/test/unit/Client/Resource/ResourceByProjectKeyProductTailoringTest.php @@ -24,6 +24,7 @@ /** * @covers \Commercetools\Api\Client\Resource\ByProjectKeyProductTailoringGet + * @covers \Commercetools\Api\Client\Resource\ByProjectKeyProductTailoringHead * @covers \Commercetools\Api\Client\Resource\ByProjectKeyProductTailoringPost * @covers \Commercetools\Api\Client\Resource\ResourceByProjectKeyProductTailoring */ @@ -189,6 +190,27 @@ function (ApiRequestBuilder $builder): RequestInterface { 'get', 'test_projectKey/product-tailoring', ], + 'ByProjectKeyProductTailoringHead_withWhere' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey('test_projectKey') + ->productTailoring() + ->head() + ->withWhere('where'); + }, + 'head', + 'test_projectKey/product-tailoring?where=where', + ], + 'ByProjectKeyProductTailoringHead' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("test_projectKey") + ->productTailoring() + ->head(); + }, + 'head', + 'test_projectKey/product-tailoring', + ], 'ByProjectKeyProductTailoringPost_withExpand' => [ function (ApiRequestBuilder $builder): RequestInterface { return $builder @@ -252,6 +274,14 @@ function (ApiRequestBuilder $builder): RequestInterface { ->get(); } ], + 'ByProjectKeyProductTailoringHead' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + } + ], 'ByProjectKeyProductTailoringPost' => [ function (ApiRequestBuilder $builder): RequestInterface { return $builder @@ -347,6 +377,87 @@ function (ApiRequestBuilder $builder): RequestInterface { }, 599 ], + 'ByProjectKeyProductTailoringHead_200' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 200 + ], + 'ByProjectKeyProductTailoringHead_404' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 404 + ], + 'ByProjectKeyProductTailoringHead_400' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 400 + ], + 'ByProjectKeyProductTailoringHead_401' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 401 + ], + 'ByProjectKeyProductTailoringHead_403' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 403 + ], + 'ByProjectKeyProductTailoringHead_500' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 500 + ], + 'ByProjectKeyProductTailoringHead_502' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 502 + ], + 'ByProjectKeyProductTailoringHead_503' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 503 + ], + 'ByProjectKeyProductTailoringHead_599' => [ + function (ApiRequestBuilder $builder): RequestInterface { + return $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); + }, + 599 + ], 'ByProjectKeyProductTailoringPost_201' => [ function (ApiRequestBuilder $builder): RequestInterface { return $builder diff --git a/lib/commercetools-api/docs/RequestBuilder.md b/lib/commercetools-api/docs/RequestBuilder.md index 31aae6f2b8..12baef15fa 100644 --- a/lib/commercetools-api/docs/RequestBuilder.md +++ b/lib/commercetools-api/docs/RequestBuilder.md @@ -8771,6 +8771,20 @@ $request = $builder ->productTailoring() ->get(); ``` +## `withProjectKey("projectKey")->productTailoring()->head()` + +Checks if a ProductTailoring exists for a given Query Predicate. Returns a `200 OK` status if any ProductTailoring match the Query Predicate or a `404 Not Found` otherwise. + +### Example +```php +use Commercetools\Api\Client\ApiRequestBuilder; + +$builder = new ApiRequestBuilder(); +$request = $builder + ->withProjectKey("projectKey") + ->productTailoring() + ->head(); +``` ## `withProjectKey("projectKey")->productTailoring()->post(null)` Generates the [ProductTailoringCreated](ctp:api:type:ProductTailoringCreatedMessage) Message. diff --git a/lib/commercetools-api/src/Client/Resource/ByProjectKeyProductTailoringHead.php b/lib/commercetools-api/src/Client/Resource/ByProjectKeyProductTailoringHead.php new file mode 100644 index 0000000000..69bf68057d --- /dev/null +++ b/lib/commercetools-api/src/Client/Resource/ByProjectKeyProductTailoringHead.php @@ -0,0 +1,148 @@ + + * @template-implements Deprecatable200 + */ +class ByProjectKeyProductTailoringHead extends ApiRequest implements Errorable, Deprecatable200 +{ + /** + * @param ?object|array|string $body + * @psalm-param array $headers + */ + public function __construct(string $projectKey, $body = null, array $headers = [], ClientInterface $client = null) + { + $uri = str_replace(['{projectKey}'], [$projectKey], '{projectKey}/product-tailoring'); + parent::__construct($client, 'HEAD', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * @return ErrorResponse|JsonObject|T|null + */ + public function mapFromResponse(?ResponseInterface $response, string $resultType = null) + { + if (is_null($response)) { + return null; + } + if (is_null($resultType)) { + switch ($response->getStatusCode()) { + case '400': + $resultType = ErrorResponseModel::class; + + break; + case '401': + $resultType = ErrorResponseModel::class; + + break; + case '403': + $resultType = ErrorResponseModel::class; + + break; + case '500': + $resultType = ErrorResponseModel::class; + + break; + case '502': + $resultType = ErrorResponseModel::class; + + break; + case '503': + $resultType = ErrorResponseModel::class; + + break; + default: + $resultType = JsonObjectModel::class; + + break; + } + } + + return $resultType::of($this->responseData($response)); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * + * @return null|T|ErrorResponse|JsonObject + */ + public function execute(array $options = [], string $resultType = null) + { + try { + $response = $this->send($options); + } catch (ServerException $e) { + $response = $e->getResponse(); + $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + throw $e; + } catch (ClientException $e) { + $response = $e->getResponse(); + $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + throw $e; + } + + return $this->mapFromResponse($response, $resultType); + } + + /** + * @template T of JsonObject + * @psalm-param ?class-string $resultType + * + * @return PromiseInterface + */ + public function executeAsync(array $options = [], string $resultType = null) + { + return $this->sendAsync($options)->then( + function (ResponseInterface $response) use ($resultType) { + return $this->mapFromResponse($response, $resultType); + }, + function (RequestException $e) use ($resultType) { + $response = $e->getResponse(); + if ($e instanceof ServerException) { + $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + } + if ($e instanceof ClientException) { + $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType)); + } + throw $e; + } + ); + } + + /** + * + * @psalm-param scalar|scalar[] $where + */ + public function withWhere($where): ByProjectKeyProductTailoringHead + { + return $this->withQueryParam('where', $where); + } +} diff --git a/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyProductTailoring.php b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyProductTailoring.php index 4246ae16bd..a327a955f2 100644 --- a/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyProductTailoring.php +++ b/lib/commercetools-api/src/Client/Resource/ResourceByProjectKeyProductTailoring.php @@ -59,6 +59,16 @@ public function get($body = null, array $headers = []): ByProjectKeyProductTailo return new ByProjectKeyProductTailoringGet($args['projectKey'], $body, $headers, $this->getClient()); } + /** + * @psalm-param ?object|array|string $body + * @psalm-param array $headers + */ + public function head($body = null, array $headers = []): ByProjectKeyProductTailoringHead + { + $args = $this->getArgs(); + + return new ByProjectKeyProductTailoringHead($args['projectKey'], $body, $headers, $this->getClient()); + } /** * @psalm-param ?ProductTailoringDraft $body * @psalm-param array $headers diff --git a/references.txt b/references.txt index 2b18e589a8..d45634a22f 100644 --- a/references.txt +++ b/references.txt @@ -308,3 +308,4 @@ c77ec902f368c2c31505fcb65a835ce148350077 e985f4b7aa55610705ee49bd3eb645c2fd03eb6c 7b61d389a7b8bd5dac2d780c6b6fbea0b881400c 3bde1efd0d5dbff77065d355e9d00e8a0e8f466a +c27603f949e869148570ebb8bd3ec6db34a985b7