Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Add to Cart Workflow broken since last update #10644

Open
fxmb opened this issue Dec 17, 2024 · 4 comments
Open

[Bug]: Add to Cart Workflow broken since last update #10644

fxmb opened this issue Dec 17, 2024 · 4 comments

Comments

@fxmb
Copy link

fxmb commented Dec 17, 2024

Package.json file

The commit 8 hours ago broke the add to cart workflow I believe:

   const cart = transform({ cartQuery }, ({ cartQuery }) => {
      return cartQuery.data[0]
    })

This query result from here: https://github.com/medusajs/medusa/blob/develop/packages/core/core-flows/src/cart/workflows/add-to-cart.ts#L47

returns the first cart that was created in the database.

I always get this error when trying to add to the cart using the addToCart Workflow:

Cart cart_01J801RD5JEWMPDS0V1AZZM0FP is already completed.

However, this cart (ending on FP) is not the one I am sending to the server, its an old cart from another customer...

This is the first cart ever created in our db, hence I assume some query is failing, sorted by date and returning the first [0] cart since its sorted by created_at.

Node.js version

20

Database and its version

16

Operating system name and version

..

Browser name

No response

What happended?

see above

Expected behavior

see above

Actual behavior

see above

Link to reproduction repo

no link

@olivermrbl
Copy link
Contributor

olivermrbl commented Dec 17, 2024

@fxmb, thanks for the report. How are you consuming the workflow? Its input type changed in the latest release. You should pass the cart_id instead of cart now.

I'll add this to the release notes.

@fxmb
Copy link
Author

fxmb commented Dec 17, 2024

Ha that fixed it! Thanks for pointing this out so quickly

For everyone else:

 const workflowInput = {
    items: line_items,
    cart
  };

  await addToCartWorkflow(req.scope).run({
    input: workflowInput,
  });

becomes:

    items: line_items,
    cart_id: cart.id,
  };

  await addToCartWorkflow(req.scope).run({
    input: workflowInput,
  });

@Thisisjuke
Copy link

Thisisjuke commented Dec 18, 2024

Hey,
At the moment, we are using Medusa v2.0.7 before upgrading to last version in the next weeks.
We had thus bug because of :
image

@medusajs/core-flows was not a dependency we had in our package.json, as we used this one: https://github.com/tinloof/medusa-dtc-starter-munchies/blob/main/storefront/package.json

Is it normal that we can have "@medusajs/framework": "2.0.7", and still have issues about 2.1.2 ? Did we missed something ?

We had the same error as @fxmb about already completed, and after wiping the database and starting fresh on data, now we have:
image
image

http:    GET /store/carts/cart_01JFD1KHDA6M00EC1YWZ8KYKW0?fields=%2Bitems%2C%20%2Bregion%2C%20%2Bitems
│ .product.%2A%2C%20%2Bitems.variant.image%2C%20%2Bitems.variant.%2A%2C%20%2Bitems.thumbnail%2C%20%2Bite
│ ms.metadata%2C%20%2Bpromotions.%2A%2C ← - (200) - 34.256 ms
│ error:   Value for LineItem.cart_id is required, 'undefined' found
│ entity: LineItem {

Our way to fix it force the version in our yarn.lock like this:

"@medusajs/core-flows@npm:2.0.7, @medusajs/core-flows@npm:^2.0.7":
  version: 2.0.7
  resolution: "@medusajs/core-flows@npm:2.0.7"
  dependencies:
    json-2-csv: "npm:^5.5.4"
  peerDependencies:
    "@medusajs/framework": ^2.0.0
    awilix: ^8.0.1
  checksum: 10c0/0e2e1a17a9f7442345afd179c4be8ce423f8b49bc4097e04b25a6178de2233669436b514e0056a80e6ecbc0131a60ba5a863aa3270b3a0e77a3b00a74d2d291a
  languageName: node
  linkType: hard

By putting this at the root of our yarn workspace :

"resolutions": {
  "@medusajs/medusa/@medusajs/core-flows": "2.0.7"
}

😿
Do you know a proper way to not have issues related to futur version in our actual codebase & version of ALL the @medusajs packages ?

@mohamadfala
Copy link

The exact same issue is happening for me.
Running v2.1.1.

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

No branches or pull requests

5 participants