Skip to content

Commit 877b49d

Browse files
authored
Merge pull request #224 from akeneo/CXP-1095-alt
CXP-1095: get product with query parameters without BC break
2 parents 2f3233c + 9c336e6 commit 877b49d

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

spec/Api/ProductApiSpec.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,31 @@ function it_returns_a_product($resourceClient)
5454
];
5555

5656
$resourceClient
57-
->getResource(ProductApi::PRODUCT_URI, [$productCode])
57+
->getResource(ProductApi::PRODUCT_URI, [$productCode], [])
5858
->willReturn($product);
5959

6060
$this->get($productCode)->shouldReturn($product);
6161
}
6262

63+
function it_returns_a_product_with_query_parameters($resourceClient)
64+
{
65+
$productCode = 'foo';
66+
$product = [
67+
'identifier' => 'foo',
68+
'family' => 'tshirts',
69+
'enabled' => true,
70+
'categories' => [
71+
'bar'
72+
],
73+
];
74+
75+
$resourceClient
76+
->getResource(ProductApi::PRODUCT_URI, [$productCode], ['with_attribute_options' => true])
77+
->willReturn($product);
78+
79+
$this->get($productCode, ['with_attribute_options' => true])->shouldReturn($product);
80+
}
81+
6382
function it_returns_a_list_of_products_with_default_parameters($resourceClient, $pageFactory, PageInterface $page)
6483
{
6584
$resourceClient

src/Api/ProductApi.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ public function __construct(
4848
/**
4949
* {@inheritdoc}
5050
*/
51-
public function get(string $code): array
51+
public function get(string $code, array $queryParameters = []): array
5252
{
53-
return $this->resourceClient->getResource(static::PRODUCT_URI, [$code]);
53+
return $this->resourceClient->getResource(static::PRODUCT_URI, [$code], $queryParameters);
5454
}
5555

5656
/**

src/Api/ProductApiInterface.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
99
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceInterface;
1010
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
11+
use Akeneo\Pim\ApiClient\Exception\HttpException;
1112

1213
/**
1314
* API to manage the products.
@@ -24,4 +25,15 @@ interface ProductApiInterface extends
2425
UpsertableResourceListInterface,
2526
DeletableResourceInterface
2627
{
28+
/**
29+
* Gets a resource by its code
30+
*
31+
* @param string $code Code of the resource
32+
* @param array $queryParameters Additional query parameters to pass in the request.
33+
*
34+
* @throws HttpException If the request failed.
35+
*
36+
* @return array
37+
*/
38+
public function get(string $code, array $queryParameters = []): array;
2739
}

0 commit comments

Comments
 (0)