Skip to content

Commit f5d721e

Browse files
committed
refactor(api): use query parameters for product search endpoint
Changed the product search endpoint from: GET /products/search/{phrase}/{resultsLimit}/{isoCode} To: GET /products/search/{phrase}?resultsLimit=20&isoCode=EUR Benefits: - Query parameters are properly typed by API Platform automatically - No need for custom denormalizer to handle string-to-int conversion - More RESTful design (only essential identifier in path) - Parameters can be optional or have defaults - Cleaner OpenAPI documentation with parameter descriptions This removes the need for SearchProductsDenormalizer entirely, as API Platform handles query parameter type conversion natively. Fixes #34486
1 parent 6cc710b commit f5d721e

File tree

3 files changed

+8
-102
lines changed

3 files changed

+8
-102
lines changed

config/admin/services.yml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,3 @@ services:
2929
arguments:
3030
- '@prestashop.adapter.legacy.configuration'
3131

32-
# Custom denormalizer to handle type conversion for SearchProducts query
33-
PrestaShop\Module\APIResources\Normalizer\SearchProductsDenormalizer:
34-
autowire: true
35-
tags:
36-
- { name: 'serializer.normalizer', priority: 10 }

src/ApiPlatform/Resources/Product/FoundProduct.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
#[ApiResource(
3131
operations: [
3232
new CQRSGetCollection(
33-
uriTemplate: '/products/search/{phrase}/{resultsLimit}/{isoCode}',
33+
uriTemplate: '/products/search/{phrase}',
3434
scopes: [
3535
'product_read',
3636
],
@@ -40,26 +40,30 @@
4040
[
4141
'name' => 'phrase',
4242
'in' => 'path',
43+
'description' => 'Search phrase to find products',
4344
'required' => true,
4445
'schema' => [
4546
'type' => 'string',
4647
],
4748
],
4849
[
4950
'name' => 'resultsLimit',
50-
'in' => 'path',
51+
'in' => 'query',
5152
'required' => true,
5253
'schema' => [
5354
'type' => 'integer',
55+
'default' => 20,
5456
],
57+
'description' => 'Maximum number of results to return',
5558
],
5659
[
5760
'name' => 'isoCode',
58-
'in' => 'path',
61+
'in' => 'query',
5962
'required' => true,
6063
'schema' => [
6164
'type' => 'string',
6265
],
66+
'description' => 'Currency ISO code (e.g., EUR, USD)',
6367
],
6468
[
6569
'name' => 'orderId',
@@ -68,6 +72,7 @@
6872
'schema' => [
6973
'type' => 'integer',
7074
],
75+
'description' => 'Optional order ID for context-specific pricing',
7176
],
7277
],
7378
]

src/Normalizer/SearchProductsDenormalizer.php

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)