medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
26.25k stars 2.67k forks source link

Cannot add variant to cart #6659

Closed ybirader closed 8 months ago

ybirader commented 8 months ago

Bug report

I am trying to add a variant to the current cart using

const { cart } = await this.client.carts.lineItems.create(
            this.cartId!,
            {
                variant_id: variantId,
                quantity
            },
}

Describe the bug

I get a 400 error. Inspecting the server logs, I get the following error:

Cannot generate line item for variant "T-Shirt" without a price.

I have added a price to the variant. To confirm this, I queried for the variant, which indeed shows that the amount field is set.

Is there anything I need to ensure in order to add the variant to the cart?

A clear and concise description of what the bug is.

System information

Medusa version (including plugins): @medusajs/medusa-js": "^6.1.7 Node.js version: 19 Database: PostgreSQL Operating system: MacOS Browser (if relevant):

Expected behaviour

The product variant should be added to the cart.

Additional Info

The code which raises the exception can be found at at LineItemService.<anonymous> /@medusajs/medusa/dist/services/line-item.js:402:27)

olivermrbl commented 8 months ago

Can I get you to ensure, you have created a price in the currency (or region) of the cart?

ybirader commented 8 months ago

Thank you!- that works.