Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42987c8

Browse files
authored
refactor #12034 [API][Product] Change identifier for shop endpoint from slug to code (GSadee)
This PR was merged into the 1.9-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | based on Sylius/Sylius#11925 | License | MIT Commits ------- 58ce6bd3d4745cb281ed97374f2324fd9e0af66d [API][Product] Change identifier for shop endpoint from slug to code
2 parents d161170 + fcc638d commit 42987c8

3 files changed

Lines changed: 6 additions & 33 deletions

File tree

DataProvider/ProductItemDataProvider.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@ public function getItem(string $resourceClass, $id, string $operationName = null
4747
}
4848

4949
Assert::keyExists($context, ContextKeys::CHANNEL);
50-
Assert::keyExists($context, ContextKeys::LOCALE_CODE);
5150

5251
/** @var ChannelInterface $channel */
5352
$channel = $context[ContextKeys::CHANNEL];
54-
$locale = $context[ContextKeys::LOCALE_CODE];
5553

56-
return $this->productRepository->findOneByChannelAndSlug($channel, $locale, $id);
54+
return $this->productRepository->findOneByChannelAndCode($channel, $id);
5755
}
5856

5957
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool

Resources/config/api_resources/Product.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
<attribute name="method">GET</attribute>
7272
<attribute name="path">/shop/products/{id}</attribute>
7373
<attribute name="openapi_context">
74-
<attribute name="summary">Use $slug to retrieve a product resource.</attribute>
74+
<attribute name="summary">Use code to retrieve a product resource.</attribute>
7575
</attribute>
7676
</itemOperation>
7777

spec/DataProvider/ProductItemDataProviderSpec.php

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -41,25 +41,7 @@ function it_throws_an_exception_if_context_has_no_channel(): void
4141
{
4242
$this
4343
->shouldThrow(\InvalidArgumentException::class)
44-
->during('getItem', [
45-
ProductInterface::class,
46-
'ford',
47-
Request::METHOD_GET,
48-
[ContextKeys::LOCALE_CODE => 'en_US'],
49-
])
50-
;
51-
}
52-
53-
function it_throws_an_exception_if_context_has_no_locale_code(ChannelInterface $channel): void
54-
{
55-
$this
56-
->shouldThrow(\InvalidArgumentException::class)
57-
->during('getItem', [
58-
ProductInterface::class,
59-
'ford',
60-
Request::METHOD_GET,
61-
[ContextKeys::CHANNEL => $channel],
62-
])
44+
->during('getItem', [ProductInterface::class, 'ford', Request::METHOD_GET, []])
6345
;
6446
}
6547

@@ -75,12 +57,7 @@ function it_provides_product_by_code_for_a_logged_in_admin_user(
7557
$productRepository->findOneByCode('FORD_FOCUS')->willReturn($product);
7658

7759
$this
78-
->getItem(
79-
ProductInterface::class,
80-
'FORD_FOCUS',
81-
Request::METHOD_GET,
82-
[]
83-
)
60+
->getItem(ProductInterface::class, 'FORD_FOCUS', Request::METHOD_GET, [])
8461
->shouldReturn($product)
8562
;
8663
}
@@ -95,7 +72,7 @@ function it_provides_product_by_slug_for_a_logged_in_shop_user(
9572
$userContext->getUser()->willReturn($user);
9673
$user->getRoles()->willReturn([]);
9774

98-
$productRepository->findOneByChannelAndSlug($channel, 'en_US', 'FORD_FOCUS')->willReturn($product);
75+
$productRepository->findOneByChannelAndCode($channel, 'FORD_FOCUS')->willReturn($product);
9976

10077
$this
10178
->getItem(
@@ -104,7 +81,6 @@ function it_provides_product_by_slug_for_a_logged_in_shop_user(
10481
Request::METHOD_GET,
10582
[
10683
ContextKeys::CHANNEL => $channel,
107-
ContextKeys::LOCALE_CODE => 'en_US',
10884
]
10985
)
11086
->shouldReturn($product)
@@ -119,7 +95,7 @@ function it_provides_product_by_slug_if_there_is_no_logged_in_user(
11995
): void {
12096
$userContext->getUser()->willReturn(null);
12197

122-
$productRepository->findOneByChannelAndSlug($channel, 'en_US', 'FORD_FOCUS')->willReturn($product);
98+
$productRepository->findOneByChannelAndCode($channel, 'FORD_FOCUS')->willReturn($product);
12399

124100
$this
125101
->getItem(
@@ -128,7 +104,6 @@ function it_provides_product_by_slug_if_there_is_no_logged_in_user(
128104
Request::METHOD_GET,
129105
[
130106
ContextKeys::CHANNEL => $channel,
131-
ContextKeys::LOCALE_CODE => 'en_US',
132107
]
133108
)
134109
->shouldReturn($product)

0 commit comments

Comments
 (0)