vendure-ecommerce/vendure

Deleting a variant does not remove it from active orders

Opened this issue · 1 comments

Describe the bug
Whenever a product variant is deleted, it can still be in a customers active order. When this happens, the order of the customer is 'stuck', as in that it can not transition to ArranginPayment anymore. Trying to do so results in the error Cannot transition to "ArrangingPayment" because the Order contains ProductVariants which are no longer available.

To Reproduce
Steps to reproduce the behavior:

  1. Add a variant to order
  2. Go to the Admin and delete it.
  3. Transition it to ArrangingPayment via the Admin UI
  4. See error.

Expected behavior
I would expect the product variant to be removed from all active orders.

  • Is this something we want in Vendure core? Or does this belong in a plugin?
  • Should it be configurable behavior somehow?
  • Do we create some history entry or similar on the order to notify that removing the order line happened?

Environment (please complete the following information):

  • @vendure/core version: 2.2.7
  • Nodejs version 18
  • Database (mysql/postgres etc): mysql

Additional context
If we are to add this to Vendure core, I would expect the implementation to look something like this:

  • On every ProductVariantEvent + deleted event, a job is added to the queue remove-variants-from-active-orders: {variantIds: ID[]}
  • The worker fetches all active orders with the variants connected to the orderLines
  • For each order, the orderLine is removed from the active order
  • Add a public History Entry to the order with something like Orderline 1 was removed because it's related variant was removed

Also no validation on product updates either added to a draft order .. product name / prices or stock levels get changed it keep on old data in the draft order without any checks.
@michaelbromley