Skip to content

Add order duplicate-cart endpoint#327

Open
PrestaEdit wants to merge 3 commits into
PrestaShop:devfrom
PrestaEdit:add-order-duplicate-cart
Open

Add order duplicate-cart endpoint#327
PrestaEdit wants to merge 3 commits into
PrestaShop:devfrom
PrestaEdit:add-order-duplicate-cart

Conversation

@PrestaEdit

Copy link
Copy Markdown
Contributor
Questions Answers
Branch? dev
Description? Fills the DuplicateOrderCartCommand gap: PUT /orders/{orderId}/cart-duplications (scope order_write) to duplicate an order's cart. Returns the new cart id along with the source orderId.
Type? improvement
BC breaks? no
Deprecations? no
Fixed ticket? Related to PrestaShop/PrestaShop#39630
How to test? PUT /orders/{id}/cart-duplications (client granted order_write) returns { orderId, cartId } with the new cart id. Covered by OrderCartDuplicationEndpointTest.
Possible impacts? Creates a new cart duplicated from the order's cart.

Fill the DuplicateOrderCartCommand gap: PUT /orders/{orderId}/cart-duplications
(scope order_write) to duplicate an order's cart. Returns the new cart id.

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.

OrderNotFoundException => 404 is missing from exceptionToStatus. Only DuplicateOrderCartException => 422 is mapped, so a bad orderId currently surfaces as 422 rather than a clean 404. Order endpoints should map the not-found case to 404.

Also missing a not-found / invalid negative test.

@ps-jarvis ps-jarvis moved this from Ready for review to Waiting for author in PR Dashboard Jul 13, 2026
- Add OrderNotFoundException => HTTP_NOT_FOUND to exceptionToStatus.
  A bad orderId used to surface as 422; it now returns 404 cleanly.
- Add testDuplicateNotFoundOrderCart covering PUT /orders/99999/... => 404.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@PrestaEdit

Copy link
Copy Markdown
Contributor Author

Thanks @mattgoud — addressed in the last push.

  • Added OrderNotFoundException::class => Response::HTTP_NOT_FOUND to exceptionToStatus, exactly as flagged. A bad orderId no longer falls through to 422; it returns 404.
  • Added testDuplicateNotFoundOrderCart — PUT /orders/99999/cart-duplications asserts 404.

Ready for another look.

@mattgoud

Copy link
Copy Markdown
Contributor

The OrderNotFoundException => 404 mapping is in place now, but it never gets reached and CI is red on the new testDuplicateNotFoundOrderCart. For an order with no cart, the core handler blows up first:

TypeError: PrestaShop\PrestaShop\Adapter\ContextStateManager::setCart():
Argument #1 ($cart) must be of type ?Cart, false given,
called in src/Adapter/Order/CommandHandler/DuplicateOrderCartHandler.php on line 47

Cart::getCartByOrderId() returns false and is passed straight to setCart(), so a bad orderId yields a 500, not a 404. This can't be fixed from the module: the core handler needs a guard (e.g. throw OrderNotFoundException / DuplicateOrderCartException when the cart is missing). I'd suggest a small core PR for the guard, then re-point the negative test at it.

Without the core guard, DuplicateOrderCartHandler feeds false into
ContextStateManager::setCart(?Cart) and produces a TypeError (500)
before the 404 mapping can fire. Re-enable once the core PR lands.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@PrestaEdit

Copy link
Copy Markdown
Contributor Author

Good catch @mattgoud — confirmed, Cart::getCartByOrderId() returns false and the handler feeds it straight into ContextStateManager::setCart(?Cart), so the OrderNotFoundException → 404 mapping never gets a chance.

Opened a core PR to add the guard: PrestaShop/PrestaShop#42065 (throws OrderNotFoundException when the cart is missing).

In the meantime I marked testDuplicateNotFoundOrderCart as skipped here (with a reference to that PR) so CI goes green. I'll un-skip it as soon as the core guard lands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Waiting for author

Development

Successfully merging this pull request may close these issues.

3 participants