Skip to content

Add Product stock update endpoint - #256

Closed
PrestaEdit wants to merge 2 commits into
PrestaShop:devfrom
PrestaEdit:add-product-stock
Closed

PrestaEdit wants to merge 2 commits into
PrestaShop:devfrom
PrestaEdit:add-product-stock

Conversation

@PrestaEdit

@PrestaEdit PrestaEdit commented Jun 23, 2026 •

Copy link
Copy Markdown
Contributor
Questions Answers
Description? Add the Product stock update endpoint
Type? new feature
BC breaks? no
Deprecations? no
Fixed ticket? Related to PrestaShop/PrestaShop#39630
Sponsor company

Adds PUT /products/{productId}/stocks — UpdateProductStockAvailableCommand: adjusts a
product's available stock via deltaQuantity (positive to add, negative to remove), and optionally
its out-of-stock behaviour (outOfStockType) and stock location. The shop constraint is taken
from the request context. 404 when the product does not exist.

⚠️ Depends on a core fix — kept as a draft

A stock quantity change records a StockMvt attributed to the current employee. In the API context
there is no logged-in employee, so StockManager called StockMvt::setIdEmployee(null) →
TypeError. The core PR PrestaShop/PrestaShop#41803 guards that (keeps id_employee = 0 when the
context employee has no id). This PR stays a draft and red on the released-core matrices until that
fix ships; it goes green on develop once #41803 is merged.

The integration test picks a simple fixture product (no combinations), applies a +5 delta and
verifies the resulting quantity via StockAvailable. Reuses the product_write scope.

PUT /products/{productId}/stocks (UpdateProductStockAvailableCommand) adjusts a product's
available stock (deltaQuantity), and optionally its out-of-stock behaviour and stock location.
The shop constraint is taken from the request context. 404 when the product does not exist.

The integration test picks a simple fixture product (no combinations), applies a +5 delta and
verifies the new quantity via StockAvailable.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to Ready for review in PR Dashboard Jun 23, 2026
UpdateProductStockAvailableCommand requires a $shopConstraint constructor argument; the API
provides it under _context, so map [_context][shopConstraint] to [shopConstraint] like the other
Product resources.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@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: the URI becomes PUT /products/{productId}/stock (singular — a product has one stock) in #410, and the operation returns the updated stock state. The red CI of this PR was actually caused by a core bug: any stock update through the Admin API hits a StockMvt::setIdEmployee(null) TypeError — the fix is PrestaShop/PrestaShop#41803, which #410 depends on.

@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
@ps-jarvis ps-jarvis moved this from Closed to Ready for review 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 Aug 13, 2026
All fixtures are created through the Admin API itself (products,
suppliers, attribute groups, attributes, combinations, images, stock)
instead of ObjectModel instances, command-bus seeding or raw SQL
lookups of existing data: the tests now prove the whole flow is
achievable with the API alone. Assertions compare the complete JSON
structure of each entity with a single assertEquals (dynamically
generated ids and dates are injected into the expected arrays), so
missing or unexpected fields fail the test.

- ProductSuppliersEndpointTest: full lifecycle over the five supplier
  operations, suppliers created via POST /suppliers.
- ProductAttributeGroupListEndpointTest: attribute group + attributes
  created via the API, combinations generated on an API-created
  product; also locks the 200 [] contract for unknown products.
- ProductStockEndpointTest / ProductStockMovementsEndpointTest: stock
  updated via the new PUT /products/{productId}/stock endpoint, which
  makes the movements fixture fully API-based, including pagination.
  Requires the StockMvt employee guard from
  PrestaShop/PrestaShop#41803 (without it any stock update through the
  Admin API fails with a TypeError, which is also why the original
  PR PrestaShop#256 CI was red).
- ShopProductImagesEndpointTest: multishop setup, two images uploaded
  via the API, GET + PUT asserted on the shared shopImages resource on
  both shops.
- VirtualProductFileEndpointTest: add, update, delete plus read-back
  through the product's virtualProductFile, and the invalid product
  type error case.
- FreeGiftCandidateEndpointTest: deterministic disabled/eligible
  scenarios driven by the PS_ORDER_OUT_OF_STOCK configuration,
  version-gated with markTestSkippedByMinVersion.

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>
jolelievre added a commit to jolelievre/ps_apiresources that referenced this pull request Sep 15, 2026
All fixtures are created through the Admin API itself (products,
suppliers, attribute groups, attributes, combinations, images, stock)
instead of ObjectModel instances, command-bus seeding or raw SQL
lookups of existing data: the tests now prove the whole flow is
achievable with the API alone. Assertions compare the complete JSON
structure of each entity with a single assertEquals (dynamically
generated ids and dates are injected into the expected arrays), so
missing or unexpected fields fail the test.

- ProductSuppliersEndpointTest: full lifecycle over the five supplier
  operations, suppliers created via POST /suppliers.
- ProductAttributeGroupListEndpointTest: attribute group + attributes
  created via the API, combinations generated on an API-created
  product; also locks the 200 [] contract for unknown products.
- ProductStockEndpointTest / ProductStockMovementsEndpointTest: stock
  updated via the new PUT /products/{productId}/stock endpoint, which
  makes the movements fixture fully API-based, including pagination.
  Requires the StockMvt employee guard from
  PrestaShop/PrestaShop#41803 (without it any stock update through the
  Admin API fails with a TypeError, which is also why the original
  PR PrestaShop#256 CI was red).
- ShopProductImagesEndpointTest: multishop setup, two images uploaded
  via the API, GET + PUT asserted on the shared shopImages resource on
  both shops.
- VirtualProductFileEndpointTest: add, update, delete plus read-back
  through the product's virtualProductFile, and the invalid product
  type error case.
- FreeGiftCandidateEndpointTest: deterministic disabled/eligible
  scenarios driven by the PS_ORDER_OUT_OF_STOCK configuration,
  version-gated with markTestSkippedByMinVersion.

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.

3 participants