Skip to content

Add SearchProductsForFreeGift Admin API endpoint - #374

Closed
PrestaEdit wants to merge 1 commit into
PrestaShop:devfrom
PrestaEdit:add-free-gift-search-endpoint
Closed

PrestaEdit wants to merge 1 commit into
PrestaShop:devfrom
PrestaEdit:add-free-gift-search-endpoint

Conversation

@PrestaEdit

Copy link
Copy Markdown
Contributor
Questions Answers
Branch? dev
Description? 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: productId, name, reference, imagePath, productType, disabled, disabledReason.
Type? new feature
Category? CO
BC breaks? no
Deprecations? no
Fixed ticket? Related to PrestaShop/PrestaShop#39630
How to test? Run composer phpunit-integration; FreeGiftCandidateEndpointTest searches for hum against the demo catalog (Hummingbird products).

⚠️ Depends on PR #220 — SearchProductsForFreeGift was 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.

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 mattgoud left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A couple of real defects here beyond the CI-matrix dependency:

  1. disabledReason must be nullable. The core DTO getter is ProductForFreeGift::getDisabledReason(): ?string and the handler returns null for eligible products (return [false, null];). The resource declares public string $disabledReason; (non-nullable), so denormalizing an eligible product throws The 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;.

  2. imagePath doesn't map to the DTO. The DTO exposes getImageUrl() (key imageUrl), not imagePath, and there's no ApiResourceMapping, so imagePath is never populated (currently masked by defect #1). Rename the property to imageUrl, or add ApiResourceMapping ['[imagePath]' => '[imageUrl]'].

  3. Dependency is under-stated. SearchProductsForFreeGift was 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 on class_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.

@jolelievre

Copy link
Copy Markdown
Contributor

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.

@jolelievre jolelievre closed this Aug 11, 2026
@github-project-automation github-project-automation Bot moved this from Ready for review to Closed in PR Dashboard Aug 11, 2026
jolelievre added a commit to jolelievre/ps_apiresources that referenced this pull request Aug 13, 2026
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>
jolelievre added a commit to jolelievre/ps_apiresources that referenced this pull request Sep 15, 2026
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

4 participants