Skip to content

validation function can trap cart in invalid state #590

Open
@aaaaargZombies

Description

@aaaaargZombies

Which template or example

  • cart_checkout_validation
  • typescript

Describe the bug

trapped-in-invalid-state.mp4

Validation function can trap cart in invalid state. I believe this is the same issue "Issue with Cart Validation Blocking Product Deletion" discussed in community with no resolution, attributed to a race condition there. I could not alter existing items, delete exiting items or add new items to the cart.

My understanding is that the validation function checks the new state of a cart on modification, blocking the change if it fails the validation.

This does not account for external effects such as changes to metafields accessed by the function, time or the initial state of the cart at time the validation is activated. This means that a previously valid cart can fall into an invalid state and there is then not a way for a user to correct it.


example usecase: a product is reserved for a period of time when added to a cart, if the product is still in the cart after the reservation expires then it cannot be purchased. If they were to remove the item from the cart it would be valid again.

Steps to reproduce

based on this tutorial / documentation

This is the simplest way to produce the invalid state, using the default template.

  • run shopify app generate extension --template cart_checkout_validation --name cart-checkout-validation
  • select typescript
  • run npm run dev
  • add an item to the cart
  • increase quantity to more than one
  • enable validation in store settings, uncheck "Allow all customers to complete checkout"
  • attempt to alter cart. changing quantity, deleting item and adding a new item to the cart are blocked.

Expected behavior

Once a cart has reached an invalid state, modifications that could bring the cart into a valid state should be allowed. Perhaps allowing all modification and displaying warnings but not allowing creation of an order if state is invalid.

Environment

  • Linux
  • Shopify CLI version @shopify/cli/3.70.0 linux-x64 node-v20.13.1

Additional context

I hope this is the correct place to file an issue, I apologize if this is not actually a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions