commercetools-sdk-php-v2
The commercetools platform, import-api and PHP sdks generated from our api reference.
Loading...
Searching...
No Matches
ByProjectKeyVariantProjectionsGet.php
1<?php
2
3declare(strict_types=1);
10
22use GuzzleHttp\ClientInterface;
23use GuzzleHttp\Exception\ClientException;
24use GuzzleHttp\Exception\RequestException;
25use GuzzleHttp\Exception\ServerException;
26use GuzzleHttp\Promise\PromiseInterface;
27
28use Psr\Http\Message\ResponseInterface;
29
45{
50 public function __construct(string $projectKey, $body = null, array $headers = [], ?ClientInterface $client = null)
51 {
52 $uri = str_replace(['{projectKey}'], [self::encodePathParam($projectKey)], '{projectKey}/variant-projections');
53 parent::__construct($client, 'GET', $uri, $headers, is_object($body) || is_array($body) ? json_encode($body) : $body);
54 }
55
61 public function mapFromResponse(?ResponseInterface $response, ?string $resultType = null)
62 {
63 if (is_null($response)) {
64 return null;
65 }
66 if (is_null($resultType)) {
67 switch ($response->getStatusCode()) {
68 case '200':
69 $resultType = VariantProjectionPagedQueryResponseModel::class;
70
71 break;
72 case '400':
73 $resultType = ErrorResponseModel::class;
74
75 break;
76 case '401':
77 $resultType = ErrorResponseModel::class;
78
79 break;
80 case '403':
81 $resultType = ErrorResponseModel::class;
82
83 break;
84 case '500':
85 $resultType = ErrorResponseModel::class;
86
87 break;
88 case '502':
89 $resultType = ErrorResponseModel::class;
90
91 break;
92 case '503':
93 $resultType = ErrorResponseModel::class;
94
95 break;
96 default:
97 $resultType = JsonObjectModel::class;
98
99 break;
100 }
101 }
102
103 return $resultType::of($this->responseData($response));
104 }
105
112 public function execute(array $options = [], ?string $resultType = null)
113 {
114 try {
115 $response = $this->send($options);
116 } catch (ServerException $e) {
117 $response = $e->getResponse();
118 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
119 throw $e;
120 } catch (ClientException $e) {
121 $response = $e->getResponse();
122 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
123 throw $e;
124 }
125
126 return $this->mapFromResponse($response, $resultType);
127 }
128
135 public function executeAsync(array $options = [], ?string $resultType = null)
136 {
137 return $this->sendAsync($options)->then(
138 function (ResponseInterface $response) use ($resultType) {
139 return $this->mapFromResponse($response, $resultType);
140 },
141 function (RequestException $e) use ($resultType) {
142 $response = $e->getResponse();
143 if ($e instanceof ServerException) {
144 $e = ExceptionFactory::createServerException($e, $this, $response, $this->mapFromResponse($response, $resultType));
145 }
146 if ($e instanceof ClientException) {
147 $e = ExceptionFactory::createClientException($e, $this, $response, $this->mapFromResponse($response, $resultType));
148 }
149 throw $e;
150 }
151 );
152 }
153
159 {
160 return $this->withQueryParam('staged', $staged);
161 }
162
168 {
169 return $this->withQueryParam('priceCurrency', $priceCurrency);
170 }
171
177 {
178 return $this->withQueryParam('priceCountry', $priceCountry);
179 }
180
185 public function withPriceCustomerGroup($priceCustomerGroup): ByProjectKeyVariantProjectionsGet
186 {
187 return $this->withQueryParam('priceCustomerGroup', $priceCustomerGroup);
188 }
189
194 public function withPriceCustomerGroupAssignments($priceCustomerGroupAssignments): ByProjectKeyVariantProjectionsGet
195 {
196 return $this->withQueryParam('priceCustomerGroupAssignments', $priceCustomerGroupAssignments);
197 }
198
204 {
205 return $this->withQueryParam('priceChannel', $priceChannel);
206 }
207
212 public function withPriceRecurrencePolicy($priceRecurrencePolicy): ByProjectKeyVariantProjectionsGet
213 {
214 return $this->withQueryParam('priceRecurrencePolicy', $priceRecurrencePolicy);
215 }
216
221 public function withLocaleProjection($localeProjection): ByProjectKeyVariantProjectionsGet
222 {
223 return $this->withQueryParam('localeProjection', $localeProjection);
224 }
225
230 public function withFilterAttributes($filterAttributes): ByProjectKeyVariantProjectionsGet
231 {
232 return $this->withQueryParam('filter[attributes]', $filterAttributes);
233 }
234
240 {
241 return $this->withQueryParam('expand', $expand);
242 }
243
249 {
250 return $this->withQueryParam('sort', $sort);
251 }
252
258 {
259 return $this->withQueryParam('limit', $limit);
260 }
261
267 {
268 return $this->withQueryParam('offset', $offset);
269 }
270
276 {
277 return $this->withQueryParam('withTotal', $withTotal);
278 }
279
285 {
286 return $this->withQueryParam('where', $where);
287 }
288
293 public function withPredicateVar(string $varName, $predicateVar): ByProjectKeyVariantProjectionsGet
294 {
295 return $this->withQueryParam(sprintf('var.%s', $varName), $predicateVar);
296 }
297}
__construct(string $projectKey, $body=null, array $headers=[], ?ClientInterface $client=null)
mapFromResponse(?ResponseInterface $response, ?string $resultType=null)
responseData(ResponseInterface $response)
withQueryParam(string $parameterName, $value)