Skip to content

Commit

Permalink
Merge pull request #224 from akeneo/CXP-1095-alt
Browse files Browse the repository at this point in the history
CXP-1095: get product with query parameters without BC break
  • Loading branch information
LevFlavien authored Feb 15, 2022
2 parents 2f3233c + 9c336e6 commit 877b49d
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
21 changes: 20 additions & 1 deletion spec/Api/ProductApiSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,31 @@ function it_returns_a_product($resourceClient)
];

$resourceClient
->getResource(ProductApi::PRODUCT_URI, [$productCode])
->getResource(ProductApi::PRODUCT_URI, [$productCode], [])
->willReturn($product);

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

function it_returns_a_product_with_query_parameters($resourceClient)
{
$productCode = 'foo';
$product = [
'identifier' => 'foo',
'family' => 'tshirts',
'enabled' => true,
'categories' => [
'bar'
],
];

$resourceClient
->getResource(ProductApi::PRODUCT_URI, [$productCode], ['with_attribute_options' => true])
->willReturn($product);

$this->get($productCode, ['with_attribute_options' => true])->shouldReturn($product);
}

function it_returns_a_list_of_products_with_default_parameters($resourceClient, $pageFactory, PageInterface $page)
{
$resourceClient
Expand Down
4 changes: 2 additions & 2 deletions src/Api/ProductApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ public function __construct(
/**
* {@inheritdoc}
*/
public function get(string $code): array
public function get(string $code, array $queryParameters = []): array
{
return $this->resourceClient->getResource(static::PRODUCT_URI, [$code]);
return $this->resourceClient->getResource(static::PRODUCT_URI, [$code], $queryParameters);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions src/Api/ProductApiInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Akeneo\Pim\ApiClient\Api\Operation\ListableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceInterface;
use Akeneo\Pim\ApiClient\Api\Operation\UpsertableResourceListInterface;
use Akeneo\Pim\ApiClient\Exception\HttpException;

/**
* API to manage the products.
Expand All @@ -24,4 +25,15 @@ interface ProductApiInterface extends
UpsertableResourceListInterface,
DeletableResourceInterface
{
/**
* Gets a resource by its code
*
* @param string $code Code of the resource
* @param array $queryParameters Additional query parameters to pass in the request.
*
* @throws HttpException If the request failed.
*
* @return array
*/
public function get(string $code, array $queryParameters = []): array;
}

0 comments on commit 877b49d

Please sign in to comment.