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]: Error "Sales channel xxx is not associated with any stock location" when add variant with backorder to cart." #10694

Open
Deroswent opened this issue Dec 22, 2024 · 0 comments

Comments

@Deroswent
Copy link

Deroswent commented Dec 22, 2024

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": "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"
  },
  "dependencies": {
    "@medusajs/admin-sdk": "latest",
    "@medusajs/cli": "latest",
    "@medusajs/framework": "latest",
    "@medusajs/medusa": "latest",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "1c_integration": "github:Deroswent/1c_integration",
    "awilix": "^8.0.1",
    "exceljs": "^4.4.0",
    "managers": "github:Deroswent/managers",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "latest",
    "@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

v20.15.0

Database and its version

PostgreSQL 16.4

Operating system name and version

Windows 11

Browser name

No response

What happended?

If your product variant has the settings: Managed Inventory = true and Allowed backorders = true, but no Stock Locations are added for Inventory Item of this variant and when you try to add it to cart you will get error 400: stack: 'Error: Sales channel sc_01JCHCH6E5ZF7760H5J5WFC4T3SZY is not associated with any stock location.\n'+'

It's how to reproduce the problem:

  1. for any product variant, set the settings: Managed Inventory = true and Allowed backorders = true

2024-12-22_03-48

  1. Create an Inventory Item and link it to your product variant.

2024-12-22_03-59

  1. Go to our Inventory Item, and make sure no locations are added.

2024-12-22_04-01

  1. Try to add our variant to cart - you'll receive server error 400: "Sales channel xxx is not associated with any stock location" when add variant with backorder to cart."

Expected behavior

It is expected that the variant will be added to the cart since the "Allowed backorders = true" option is enabled

Actual behavior

You're getting server error 400. Here is the full server error code.
(Actually the error sounds strange, because this sales channel has a connection to several Locations. It's just that these locations are not added specifically to our test case.)


error:   Sales channel sc_01JCH6E5ZF7760H5JWFC4T3SZY is not associated with any stock location.
{
  message: 'Sales channel sc_01JCH6E5ZF7760H5JWFC4T3SZY is not associated with any stock location.',
  name: 'Error',
  stack: 'Error: Sales channel sc_01JCH6E5ZF7760H5JWFC4T3SZY is not associated with any stock location.\n' +
    '    at Function.prepareConfirmInventoryInput (/root/backend-server/node_modules/@medusajs/core-flows/src/cart/utils/prepare-confirm-inventory-input.ts:104:11)\n' +
    '    at Proxy.returnFn (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/transform.ts:192:30)\n' +
    '    at processTicksAndRejections (node:internal/process/task_queues:105:5)\n' +
    '    at async resolveProperty (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/resolve-value.ts:17:11)\n' +
    '    at async resolveValue (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/resolve-value.ts:78:7)\n' +
    '    at async Object.invoke (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:71:32)\n' +
    '    at async DistributedTransaction.handler (/root/backend-server/node_modules/@medusajs/orchestration/src/workflow/workflow-manager.ts:214:16)\n' +
    '    at async stepHandler (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:827:20)\n' +
    '    at async Promise.allSettled (index 0)\n' +
    '    at async promiseAll (/root/backend-server/node_modules/@medusajs/utils/src/common/promise-all.ts:27:18)\n' +
    '    at async TransactionOrchestrator.executeNext (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:965:7)\n' +
    '    at async executeNext (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1013:14)\n' +
    '    at async TransactionOrchestrator.resume (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1028:5)\n' +
    '    at async LocalWorkflow.run (/root/backend-server/node_modules/@medusajs/orchestration/src/workflow/local-workflow.ts:371:5)\n' +
    '    at async originalExecution (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:111:26)\n' +
    '    at async newRun (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:190:12)\n' +
    '    at async Function.exportedWorkflow.run (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:417:12)\n' +
    '    at async Object.async.container.container (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/create-workflow.ts:193:29)\n' +
    '    at async Object.invoke (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/create-step-handler.ts:72:52)\n' +
    '    at async DistributedTransaction.handler (/root/backend-server/node_modules/@medusajs/orchestration/src/workflow/workflow-manager.ts:214:16)\n' +
    '    at async stepHandler (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:827:20)\n' +
    '    at async Promise.allSettled (index 0)\n' +
    '    at async promiseAll (/root/backend-server/node_modules/@medusajs/utils/src/common/promise-all.ts:27:18)\n' +
    '    at async TransactionOrchestrator.executeNext (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:965:7)\n' +
    '    at async executeNext (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1013:14)\n' +
    '    at async TransactionOrchestrator.resume (/root/backend-server/node_modules/@medusajs/orchestration/src/transaction/transaction-orchestrator.ts:1028:5)\n' +
    '    at async LocalWorkflow.run (/root/backend-server/node_modules/@medusajs/orchestration/src/workflow/local-workflow.ts:371:5)\n' +
    '    at async originalExecution (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:111:26)\n' +
    '    at async LocalWorkflow.newRun [as run] (/root/backend-server/node_modules/@medusajs/workflows-sdk/src/helper/workflow-export.ts:190:12)\n' +
    '    at async POST (/root/backend-server/node_modules/@medusajs/medusa/src/api/store/carts/[id]/line-items/route.ts:11:3)\n' +
    '    at async /root/backend-server/node_modules/@medusajs/utils/src/common/wrap-handler.ts:17:14\n' +
    '⮑ sat /root/backend-server/node_modules/@medusajs/core-flows/dist/cart/workflows/confirm-variant-inventory.js: [confirm-item-inventory -> confirm-inventory-step (invoke)]\n' +
    '⮑ sat /root/backend-server/node_modules/@medusajs/core-flows/dist/cart/workflows/add-to-cart.js: [add-to-cart -> confirm-item-inventory-as-step (invoke)]',
  __isMedusaError: true,
  type: 'invalid_data',
  code: undefined,
  date: 2024-12-22T01:45:03.046Z

Link to reproduction repo

https://github.com/medusajs/medusa/

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

1 participant