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]: How to solve the error when placing order with 2 different items #10839

Open
hohai1001 opened this issue Jan 6, 2025 · 2 comments
Open

Comments

@hohai1001
Copy link

hohai1001 commented Jan 6, 2025

Package.json file

{
  "name": "medusa-starter-default",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "NODE_ENV=production medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "dev": "medusa develop",
    "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",
    "add-user": "npx medusa user -e admin-medusa@test.com -p supersecret",
    "build:docker": "docker build -t commerce-server ."
  },
  "dependencies": {
    "@medusajs/admin-sdk": "2.1.3",
    "@medusajs/cli": "2.1.3",
    "@medusajs/framework": "2.1.3",
    "@medusajs/medusa": "2.1.3",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@solana/pay": "^0.2.5",
    "@solana/spl-token": "^0.4.9",
    "@solana/web3.js": "^1.95.5",
    "awilix": "^8.0.1",
    "axios": "1.7.7",
    "axios-cache-interceptor": "^1.6.2",
    "bignumber.js": "^9.1.2",
    "bs58": "^6.0.0",
    "cloudinary": "^2.5.1",
    "cors": "^2.8.5",
    "mongodb": "^6.11.0",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.1.3",
    "@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"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v2.1.3

Database and its version

PostgreSQL 16.4

Operating system name and version

MacOS Sonama 14.1

Browser name

Brave

What happended?

The steps to get the error as shown in the picture are as follows

  1. Add 2 different items to the cart.
  2. Complete the update of address, shipping options, payment method at checkout.
    • Place order for the first time and get the error above as shown in the picture
error:   Variant variant_01JE890NNY4W30XK0WFEF481HK does not have any inventory items associated with it.
{
  message: 'Variant variant_01JE890NNY4W30XK0WFEF481HK does not have any inventory items associated with it.',
  name: 'Error',
  stack: 'Error: Variant variant_01JE890NNY4W30XK0WFEF481HK does not have any inventory items associated with it.\n' +
    '    at /Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/src/cart/utils/prepare-confirm-inventory-input.ts:151:13\n' +
    '    at Array.forEach (<anonymous>)\n' +
    '    at formatInventoryInput (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/src/cart/utils/prepare-confirm-inventory-input.ts:139:9)\n' +
    '    at Function.prepareConfirmInventoryInput (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/src/cart/utils/prepare-confirm-inventory-input.ts:110:17)\n' +
    '    at Proxy.returnFn (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/transform.ts:192:30)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async resolveProperty (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/resolve-value.ts:17:11)\n' +
    '    at async resolveValue (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/resolve-value.ts:78:7)\n' +
    '    at async invoke (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:71:32)\n' +
    '    at async Object.handle.invoke (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/create-step.ts:319:12)\n' +
    '⮑ sat /Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/dist/cart/workflows/complete-cart.js: [complete-cart -> reserve-inventory-step (invoke)]',
  __isMedusaError: true,
  type: 'invalid_data',
  code: undefined,
  date: 2025-01-06T12:23:46.115Z
}
  • From the second time onwards, get the error as shown below in the picture.
error:   Order address with id: caaddr_01JGXRY8KT24MZKXDMQAQF4YNW, already exists.
{
  message: 'Order address with id: caaddr_01JGXRY8KT24MZKXDMQAQF4YNW, already exists.',
  name: 'Error',
  stack: 'Error: Order address with id: caaddr_01JGXRY8KT24MZKXDMQAQF4YNW, already exists.\n' +
    '    at dbErrorMapper (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/utils/src/dal/mikro-orm/db-error-mapper.ts:35:11)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:95:5)\n' +
    '    at async MikroOrmBaseRepository.transaction (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/utils/src/dal/mikro-orm/mikro-orm-repository.ts:74:12)\n' +
    '    at async OrderModuleService.descriptor.value (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/utils/src/modules-sdk/decorators/inject-transaction-manager.ts:32:14)\n' +
    '    at async OrderModuleService.createOrders (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/order/src/services/order-module-service.ts:610:20)\n' +
    '    at async Proxy.<anonymous> (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/orchestration/src/workflow/local-workflow.ts:129:20)\n' +
    '    at async Object.exports.createOrdersStep.async.container.container (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/src/order/steps/create-orders.ts:14:21)\n' +
    '    at async invoke (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:72:52)\n' +
    '    at async Object.handle.invoke (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/create-step.ts:319:12)\n' +
    '    at async DistributedTransaction.handler (/Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/orchestration/src/workflow/workflow-manager.ts:214:16)\n' +
    '⮑ sat /Users/macbookpro/Documents/bit.country/sources/ecommerce-sdk/backend/node_modules/@medusajs/core-flows/dist/cart/workflows/complete-cart.js: [complete-cart -> create-orders (invoke)]',
  __isMedusaError: true,
  type: 'invalid_data',
  code: undefined,
  date: 2025-01-06T12:28:57.279Z
}

This error only occurs when the place order is from 2 or more different items. As for 1 item, the place order is always successful

Expected behavior

The order should be placed successfully when there are 2 or more items in the cart. The user should see a confirmation message without encountering any errors

Actual behavior

When placing an order with 2 or more items in the cart, the first attempt results in an error as shown in the screenshot. On subsequent attempts, another error occurs. The order cannot be placed successfully, and the process fails

Link to reproduction repo

https://store.comedian.meme/us/store

@sgirones
Copy link
Contributor

sgirones commented Jan 6, 2025

@hohai1001 are you able to place an order for only variant_01JE890NNY4W30XK0WFEF481HK? I wonder if the problem is with that specific item instead.

@sgirones sgirones self-assigned this Jan 6, 2025
@hohai1001
Copy link
Author

@hohai1001 are you able to place an order for only variant_01JE890NNY4W30XK0WFEF481HK? I wonder if the problem is with that specific item instead.

Hi @sgirones

The above error only occurs when I place an order with an order that has 2 different items in 1 cart.
If it is the same 2 items but I split the order into 2 times, meaning each time I place an order 1 item, it is working fine.

@sgirones sgirones removed their assignment Jan 15, 2025
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

2 participants