| @@ 29-46 (lines=18) @@ | ||
| 26 | * |
|
| 27 | * @return Model|ResponseInterface |
|
| 28 | */ |
|
| 29 | public function get(int $id) |
|
| 30 | { |
|
| 31 | if (empty($id)) { |
|
| 32 | throw new InvalidArgumentException('Id cannot be empty'); |
|
| 33 | } |
|
| 34 | ||
| 35 | $response = $this->httpGet('/api/v1/carts/'.$id); |
|
| 36 | if (!$this->hydrator) { |
|
| 37 | return $response; |
|
| 38 | } |
|
| 39 | ||
| 40 | // Use any valid status code here |
|
| 41 | if (200 !== $response->getStatusCode()) { |
|
| 42 | $this->handleErrors($response); |
|
| 43 | } |
|
| 44 | ||
| 45 | return $this->hydrator->hydrate($response, Model::class); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * @throws Exception |
|
| @@ 33-46 (lines=14) @@ | ||
| 30 | * |
|
| 31 | * @return Model|ResponseInterface |
|
| 32 | */ |
|
| 33 | public function get(string $productCode) |
|
| 34 | { |
|
| 35 | $response = $this->httpGet('/api/v1/products/'.$productCode); |
|
| 36 | if (!$this->hydrator) { |
|
| 37 | return $response; |
|
| 38 | } |
|
| 39 | ||
| 40 | // Use any valid status code here |
|
| 41 | if (200 !== $response->getStatusCode()) { |
|
| 42 | $this->handleErrors($response); |
|
| 43 | } |
|
| 44 | ||
| 45 | return $this->hydrator->hydrate($response, Model::class); |
|
| 46 | } |
|
| 47 | ||
| 48 | /** |
|
| 49 | * {@link https://docs.sylius.com/en/1.3/api/products.html#creating-a-product}. |
|
| @@ 98-112 (lines=15) @@ | ||
| 95 | * |
|
| 96 | * @return ProductCollection|ResponseInterface |
|
| 97 | */ |
|
| 98 | public function getAll(array $params = []) |
|
| 99 | { |
|
| 100 | $response = $this->httpGet('/api/v1/products/', $params); |
|
| 101 | if (!$this->hydrator) { |
|
| 102 | return $response; |
|
| 103 | } |
|
| 104 | ||
| 105 | // Use any valid status code here |
|
| 106 | if (200 !== $response->getStatusCode()) { |
|
| 107 | $this->handleErrors($response); |
|
| 108 | } |
|
| 109 | ||
| 110 | return $this->hydrator->hydrate($response, ProductCollection::class); |
|
| 111 | } |
|
| 112 | } |
|
| 113 | ||
| @@ 29-42 (lines=14) @@ | ||
| 26 | * |
|
| 27 | * @return ResponseInterface|VariantCollection |
|
| 28 | */ |
|
| 29 | public function getAll(string $productCode, array $params = []) |
|
| 30 | { |
|
| 31 | $response = $this->httpGet(\sprintf('/api/v1/products/%s/variants/', $productCode), $params); |
|
| 32 | if (!$this->hydrator) { |
|
| 33 | return $response; |
|
| 34 | } |
|
| 35 | ||
| 36 | // Use any valid status code here |
|
| 37 | if (200 !== $response->getStatusCode()) { |
|
| 38 | $this->handleErrors($response); |
|
| 39 | } |
|
| 40 | ||
| 41 | return $this->hydrator->hydrate($response, VariantCollection::class); |
|
| 42 | } |
|
| 43 | ||
| 44 | /** |
|
| 45 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#getting-a-single-product-variant}. |
|
| @@ 51-64 (lines=14) @@ | ||
| 48 | * |
|
| 49 | * @return Model|ResponseInterface |
|
| 50 | */ |
|
| 51 | public function get(string $productCode, string $code) |
|
| 52 | { |
|
| 53 | $response = $this->httpGet(sprintf('/api/v1/products/%s/variants/%s', $productCode, $code)); |
|
| 54 | if (!$this->hydrator) { |
|
| 55 | return $response; |
|
| 56 | } |
|
| 57 | ||
| 58 | // Use any valid status code here |
|
| 59 | if (200 !== $response->getStatusCode()) { |
|
| 60 | $this->handleErrors($response); |
|
| 61 | } |
|
| 62 | ||
| 63 | return $this->hydrator->hydrate($response, Model::class); |
|
| 64 | } |
|
| 65 | ||
| 66 | /** |
|
| 67 | * {@link https://docs.sylius.com/en/1.3/api/product_variants.html#creating-a-product-variant}. |
|