diff --git a/src/BaseClient.php b/src/BaseClient.php index ab89b9d..36b15c9 100644 --- a/src/BaseClient.php +++ b/src/BaseClient.php @@ -423,6 +423,11 @@ private function prepareAndExecuteRequest(string $method, string $url, array $op 'Authorization' => sprintf('Bearer %s', $this->accessToken->getToken()), ]; + // pass through Accept-Language header + if (!empty($options['language'])) { + $httpOptions['headers']['Accept-Language'] = $options['language']; + } + // encode the body if a model is supplied for it if (isset($options['body']) && $options['body'] instanceof AbstractModel) { $httpOptions['headers']['Content-Type'] = $options['consumes'] ?? static::API_CONTENT_TYPE_FALLBACK; diff --git a/src/Client.php b/src/Client.php index 1534bf3..f984db0 100644 --- a/src/Client.php +++ b/src/Client.php @@ -105,6 +105,7 @@ public function getCatalogProduct(string $ean, ?string $AcceptLanguage = null): $url = "retailer/content/catalog-products/{$ean}"; $options = [ 'produces' => 'application/vnd.retailer.v10+json', + 'language' => $AcceptLanguage, ]; $responseTypes = [ '200' => Model\CatalogProduct::class, @@ -280,6 +281,7 @@ public function getProductRanks(string $ean, string $date, ?Enum\GetProductRanks 'page' => $page, ], 'produces' => 'application/vnd.retailer.v10+json', + 'language' => $AcceptLanguage, ]; $responseTypes = [ '200' => Model\ProductRanks::class, @@ -831,6 +833,7 @@ public function getProductList(Model\ProductListRequest $productListRequest, ?st 'body' => $productListRequest, 'produces' => 'application/vnd.retailer.v10+json', 'consumes' => 'application/json', + 'language' => $AcceptLanguage, ]; $responseTypes = [ '200' => Model\ProductListResponse::class, @@ -864,6 +867,7 @@ public function getProductListFilters(?Enum\GetProductListFiltersCountryCode $co 'category-id' => $categoryId, ], 'produces' => 'application/vnd.retailer.v10+json', + 'language' => $AcceptLanguage, ]; $responseTypes = [ '200' => Model\ProductListFiltersResponse::class, @@ -958,6 +962,7 @@ public function getProductPlacement(string $ean, ?Enum\GetProductPlacementCountr 'country-code' => $countryCode?->value, ], 'produces' => 'application/vnd.retailer.v10+json', + 'language' => $AcceptLanguage, ]; $responseTypes = [ '200' => Model\ProductPlacementResponse::class, diff --git a/src/OpenApi/ClientGenerator.php b/src/OpenApi/ClientGenerator.php index cd59794..e2e1e12 100644 --- a/src/OpenApi/ClientGenerator.php +++ b/src/OpenApi/ClientGenerator.php @@ -64,6 +64,27 @@ public function generateClient() file_put_contents(__DIR__ . '/../Client.php', implode("\n", $code)); } + + /** + * @param array $methodDefinition + * @param string $parameterName; + * @return array|null + */ + public function findMethodDefinitionParameter(array $methodDefinition, string $parameterName): array|null + { + if (empty($methodDefinition['parameters'])) { + return null; + } + + foreach ($methodDefinition['parameters'] as $parameter) { + if ($parameter['name'] === $parameterName) { + return $parameter; + } + } + + return null; + } + protected function generateMethod(string $path, string $httpMethod, array &$code): void { $methodDefinition = $this->specs['paths'][$path][$httpMethod]; @@ -122,6 +143,12 @@ protected function generateMethod(string $path, string $httpMethod, array &$code $code[] = ' ];'; $options = '$options'; + $acceptLanguage = $this->findMethodDefinitionParameter($methodDefinition, 'Accept-Language'); + + if ($acceptLanguage !== null) { + $code[] = sprintf(' \'language\' => %s,', '$AcceptLanguage'); + } + $this->addResponseTypes($methodDefinition['responses'], $code); $code[] = '';