Skip to content

Store cart accepts fractional line-item quantity: 0.1 is stored as 0 and makes the cart uncompletable #16802

Description

@Uankur

The store cart line-items endpoint validates quantity with z.number().gt(0) but not .int(), so a
fractional quantity passes validation and is coerced on store. 0.1 becomes quantity 0, which the
completion step then refuses, so the cart can never be paid for. 1.5 becomes 2, so a shopper who
asks for 1.5 is charged for two.

Medusa 2.20.1, stock starter, Postgres.

Steps:

  1. POST /store/carts with a region_id (publishable key header set).
  2. POST /store/carts/{id}/line-items with {"variant_id":"","quantity":0.1}
  3. Returns 200. GET /store/carts/{id} shows the line item at quantity 0, item_total 0.
  4. POST /store/carts/{id}/complete fails, and the item cannot be raised off 0.

I expected quantity to be validated as an integer, the same way the endpoint already rejects 0
and -1. A quantity the cart accepts should be one checkout can take.

Same endpoint, other values: 0.5 -> 1, 1.2 -> 1, 1.5 -> 2, 2.7 -> 3. The string "3" is rejected.
So the guard catches the wrong shapes but not fractions.

In 2.20.1 the store carts validators define line-item quantity as z.number().gt(0). Adding .int()
would close it.

This is the same class as #13363, which was closed as completed, but it still reproduces on 2.20.1.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions