medusajs / medusa

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

[Bug]: Issue completing cart with Custom Line Item #9995

Open matt-rolley opened 1 week ago

matt-rolley commented 1 week ago

Package.json file

{
  "name": "",
  "version": "0.0.1",
  "description": "",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "engines": {
    "node": ">=20"
  },
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "predeploy": "medusa db:migrate",
    "test:integration:http": "TEST_TYPE=integration:http NODE_OPTIONS=--experimental-vm-modules jest --silent=false --runInBand --forceExit",
    "test:integration:modules": "TEST_TYPE=integration:modules NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit",
    "test:unit": "TEST_TYPE=unit NODE_OPTIONS=--experimental-vm-modules jest --silent --runInBand --forceExit"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.0.2",
    "@medusajs/cli": "2.0.2",
    "@medusajs/framework": "2.0.2",
    "@medusajs/medusa": "2.0.2",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.0.2",
    "@mikro-orm/cli": "5.9.7",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/jest": "^29.5.13",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@types/react-dom": "^18.2.25",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "react": "^18.2.0",
    "react-dom": "^18.2.0",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2",
    "vite": "^5.2.11"
  }
}

Node.js version

v20.11.1

Database and its version

PostgresSQL 16

Operating system name and version

Docker

Browser name

No response

What happended?

In the complete-cart workflow, the cart transforms the line items using prepareLineItemData but this requires a variant to be set.

Other times that prepareLineItemData are used, there seems to be a variant check first, then it uses a prepareCustomLineItemData instead.

There are a few places that only use prepareLineItemData without checking if a variant exists, so not sure if adding the prepareCustomLineItemData will solve a few other bugs?

Expected behavior

  1. Add a custom line item using cartModuleService.addLineItems
  2. Initiate payment session using store.payment.initiatePaymentSession
  3. Call store.cart.complete to complete the order in the admin panel

Actual behavior

  1. Add a custom line item using cartModuleService.addLineItems
  2. Initiate payment session using store.payment.initiatePaymentSession
  3. Call store.cart.complete to complete the order (FAILS: "Cannot read properties of undefined (reading 'product')")

Link to reproduction repo

TODO

jkuzmanovik commented 2 days ago

Any update on this?