Add SearchProductsForFreeGift Admin API endpoint - #374
PrestaEdit wants to merge 1 commit into
Conversation
Adds GET /products/free-gift-candidates?phrase=[&limit=] using CQRSGetCollection with SearchProductsForFreeGift. Uses [_context][langId] and [_context][shopId] mappings to auto-fill the two required scoping args from the API client context. Response items expose productId, name, reference, imagePath, productType, disabled, disabledReason. The URI segment 'free-gift-candidates' is Rector-safe: 'candidates' is already plural so the last-word pluralizer is idempotent. The core SearchProductsForFreeGift query was introduced in PS 9.1+/ develop — 9.0.3 CI matrix legs will fail until PR PrestaShop#220 (drop 9.0.3 from CI) lands. Related to PrestaShop/PrestaShop#39630 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
mattgoud
left a comment
There was a problem hiding this comment.
A couple of real defects here beyond the CI-matrix dependency:
-
disabledReasonmust be nullable. The core DTO getter isProductForFreeGift::getDisabledReason(): ?stringand the handler returnsnullfor eligible products (return [false, null];). The resource declarespublic string $disabledReason;(non-nullable), so denormalizing an eligible product throwsThe type of the "disabledReason" attribute must be "string", "NULL" given.→ HTTP 500. This is why the develop/9.2.x integration legs are red. Fix:public ?string $disabledReason;. -
imagePathdoesn't map to the DTO. The DTO exposesgetImageUrl()(keyimageUrl), notimagePath, and there's noApiResourceMapping, soimagePathis never populated (currently masked by defect #1). Rename the property toimageUrl, or addApiResourceMapping ['[imagePath]' => '[imageUrl]']. -
Dependency is under-stated.
SearchProductsForFreeGiftwas introduced in 9.2.x/develop only (commit 7212d79) — it does not exist in 9.1.x. #220 drops only 9.0.3, so PHPStan(9.1.x) and the 9.1.x integration legs stay red after it merges. Either also drop 9.1.x from the matrix, or gate the resource onclass_exists.
Nit: the happy-path test doesn't assert a non-empty result set and doesn't cover imagePath/reference/disabledReason, so it wouldn't have caught #1 or #2. Worth asserting at least one row with all declared fields.
|
Closing in favor of #410, which centralizes all the pending Product-domain endpoints into a single PR: mutualizing the changes makes the review simpler, and it allowed rebuilding the integration tests so that every fixture is created through the API alone (with whole-structure assertions). @PrestaEdit your work is kept and you are co-authored on the commits of #410 — thanks! Note: #410 also fixes the nullable disabledReason (it caused a 500 for eligible products), exposes imageUrl and reference, and gates the operation with minVersion 9.2.0 since SearchProductsForFreeGift only exists since PrestaShop 9.2. |
Centralizes the pending Product-domain endpoint PRs into a single branch, as requested in PrestaShop/PrestaShop#42054 (tracking table: PrestaShop/PrestaShop#39630). Original content authored by PrestaEdit: - PrestaShop#337 GET product attribute groups - PrestaShop#353 GET product supplier options - PrestaShop#354 GET shop product images - PrestaShop#361 GET product stock movements - PrestaShop#374 GET free gift candidates - PrestaShop#383 POST/PATCH virtual product file - PrestaShop#384 PUT product image shop associations - PrestaShop#256 PUT product stock - PrestaShop#268 product suppliers (associate, default, remove all) - PrestaShop#269 PATCH product supplier details - PrestaShop#308 DELETE virtual product file (resource only; its test file collides with PrestaShop#383's and the tests are rewritten in this PR) Endpoints are imported as-is; consolidation, review fixes and test rewrites follow in dedicated commits. Co-Authored-By: Jonathan Danse <j.danse@prestaedit.com>
Centralizes the pending Product-domain endpoint PRs into a single branch, as requested in PrestaShop/PrestaShop#42054 (tracking table: PrestaShop/PrestaShop#39630). Original content authored by PrestaEdit: - PrestaShop#337 GET product attribute groups - PrestaShop#353 GET product supplier options - PrestaShop#354 GET shop product images - PrestaShop#361 GET product stock movements - PrestaShop#374 GET free gift candidates - PrestaShop#383 POST/PATCH virtual product file - PrestaShop#384 PUT product image shop associations - PrestaShop#256 PUT product stock - PrestaShop#268 product suppliers (associate, default, remove all) - PrestaShop#269 PATCH product supplier details - PrestaShop#308 DELETE virtual product file (resource only; its test file collides with PrestaShop#383's and the tests are rewritten in this PR) Endpoints are imported as-is; consolidation, review fixes and test rewrites follow in dedicated commits. Co-Authored-By: Jonathan Danse <j.danse@prestaedit.com>
GET /products/free-gift-candidates?phrase=[&limit=]usingCQRSGetCollectionwithSearchProductsForFreeGift. Uses[_context][langId]and[_context][shopId]mappings to auto-fill the two required scoping args from the API client context. Response items:productId,name,reference,imagePath,productType,disabled,disabledReason.composer phpunit-integration;FreeGiftCandidateEndpointTestsearches forhumagainst the demo catalog (Hummingbird products).SearchProductsForFreeGiftwas introduced in PS 9.1+/develop and does not exist at the 9.0.3 tag. The 9.0.3 CI matrix legs will fail here until #220 (drop 9.0.3 from CI) lands.