Skip to content

Fix removal of deleted variants on Edit Order screen#14414

Open
BethanOFN wants to merge 2 commits into
openfoodfoundation:masterfrom
BethanOFN:4203-remove-deleted-variant-from-order
Open

Fix removal of deleted variants on Edit Order screen#14414
BethanOFN wants to merge 2 commits into
openfoodfoundation:masterfrom
BethanOFN:4203-remove-deleted-variant-from-order

Conversation

@BethanOFN

Copy link
Copy Markdown
Contributor

What? Why?

When a supplier deletes a product/variant that has already been ordered, the Edit Order screen fails to process those line items — the shipments API returns 404 errors because it can't find soft-deleted variants. Users can't remove deleted products from an order, and no error is displayed to alert them.

  • Updated scoped_variant to use Spree::Variant.with_deleted.find so the shipments API can locate soft-deleted variants
  • Added a variant-deleted data attribute to the shipment manifest so the frontend knows when a variant has been removed
  • Disabled the restock checkbox with a tooltip when the variant is deleted, preventing attempts to restock unavailable items

This resolves the cascading failure where hub operators couldn't edit orders containing deleted products, forcing them to issue incorrect invoices and process manual refunds.

What should we test?

  1. Create an order containing a product
  2. Delete the product (soft-delete via admin/products)
  3. Open the order on the Edit Order screen
  4. Verify you can adjust quantities or remove the deleted product/variant without 404 errors
  5. Verify the restock checkbox is disabled with a tooltip for the deleted variant

Release notes

Changelog Category (reviewers may add a label for the release notes):

  • User facing changes
  • API changes (V0, V1, DFC or Webhook)
  • Technical changes only
  • Feature toggled

…creen

- Use Spree::Variant.with_deleted.find in scoped_variant so soft-deleted
  variants can be found by the shipments API remove action (previously
  returned 404, silently doing nothing)
- Pass variant-deleted data attribute from shipment manifest to JS so
  the frontend knows when a variant has been deleted
- Show restock checkbox as disabled with tooltip when variant is deleted,
  since restocking a deleted item is not possible

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-project-automation github-project-automation Bot moved this to All the things 💤 in OFN Delivery board Jun 15, 2026
@BethanOFN BethanOFN marked this pull request as draft June 15, 2026 15:17
ofnConfirm relied on window.event (non-standard) to read the clicked
element's data-variant-deleted attribute. In headless Chrome this is
unreliable, so the click event is now passed explicitly as a parameter.

The soft-delete controller spec was soft-deleting an unrelated variant
(the outer admin-context variant) rather than the one referenced in
params[:variant_id], making the test vacuous. It now deletes the same
variant that the remove action will look up via with_deleted.find.
@BethanOFN BethanOFN marked this pull request as ready for review June 15, 2026 17:05
@BethanOFN

Copy link
Copy Markdown
Contributor Author

FYI - I am not sure why the test above is failing as I've done nothing to do with order cycles in this PR. Feedback welcome, I did this with Claude Code and Claude is suggesting to just re-run the job, which I don't have privileges to do. I'm on leave now until 29th June but will pick up any feedback on my return! Thank you

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

Labels

None yet

Projects

Status: All the things 💤

Development

Successfully merging this pull request may close these issues.

Delete a product that has been ordered and orders/invoices cannot be updated

1 participant