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]: Custom line items cause error in shipping options retrieval #11587

Open
jkuzmanovik opened this issue Feb 24, 2025 · 1 comment · May be fixed by #11588
Open

[Bug]: Custom line items cause error in shipping options retrieval #11587

jkuzmanovik opened this issue Feb 24, 2025 · 1 comment · May be fixed by #11588

Comments

@jkuzmanovik
Copy link

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",
    "predeploy": "medusa db:migrate",
    "codegen": "graphql-codegen",
    "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.5.1",
    "@medusajs/cli": "2.5.1",
    "@medusajs/framework": "2.5.1",
    "@medusajs/medusa": "2.5.1",
    "@mikro-orm/core": "6.4.3",
    "@mikro-orm/knex": "6.4.3",
    "@mikro-orm/migrations": "6.4.3",
    "@mikro-orm/postgresql": "6.4.3",
    "@sanity/client": "^6.24.1",
    "awilix": "^8.0.1",
    "graphql-tag": "^2.12.6",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@graphql-codegen/cli": "^5.0.3",
    "@graphql-codegen/typescript": "^4.1.2",
    "@graphql-codegen/typescript-operations": "^4.4.0",
    "@medusajs/test-utils": "latest",
    "@mikro-orm/cli": "6.4.3",
    "@swc/core": "^1.7.28",
    "@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

v21.0.0

Database and its version

Postgresql 16.0

Operating system name and version

Mac os

Browser name

Chrome

What happended?

The error occurs because the list-shipping-options-for-cart.ts workflow in @medusajs/core-flows assumes all line items have a variant property with manage_inventory and other inventory-related fields. However, custom line items do not have a variant property, causing the code to attempt to access properties on an undefined object.

In packages/core/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts:

const cartQuery = useQueryGraphStep({
entity: "cart",
filters: { id: input.cart_id },
fields: [
...cartFieldsForPricingContext,
"items.",
"items.variant.manage_inventory",
"items.variant.inventory_items.inventory_item_id",
"items.variant.inventory_items.inventory.requires_shipping",
"items.variant.inventory_items.inventory.location_levels.
",
],
options: { throwIfKeyNotFound: true },
}).config({ name: "get-cart" })

Expected behavior

The workflow should handle both standard line items (with variants) and custom line items (without variants) when retrieving shipping options for a cart.

Actual behavior

{{baseUrl}}/store/shipping-options?cart_id=cart_01JMW1V9FBRXZ7047Z600PT8GQ

And at backend i am getting this error:
GET /store/shipping-options?cart_id=cart_01JMW1V9FBRXZ7047Z600PT8GQ ← - (500) - 3972.160 ms
error: Cannot read properties of undefined (reading 'manage_inventory')
TypeError: Cannot read properties of undefined (reading 'manage_inventory')
at /Users/jkuzmanovik/project/backend/node_modules/@medusajs/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts:175:33
at Array.filter ()
at /Users/jkuzmanovik/project/backend/node_modules/@medusajs/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts:173:70
at Array.map ()
at Function. (/Users/jkuzmanovik/project/backend/node_modules/@medusajs/core-flows/src/cart/workflows/list-shipping-options-for-cart.ts:167:25)
at Proxy.returnFn (/Users/jkuzmanovik/project/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/transform.ts:192:30)
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at async resolveProperty (/Users/jkuzmanovik/project/backend/node_modules/@medusajs/workflows-sdk/src/utils/composer/helpers/resolve-value.ts:17:11)

Link to reproduction repo

/

@fPolic
Copy link
Contributor

fPolic commented Feb 24, 2025

Thanks for the report @jkuzmanovik, I opened a PR.

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

Successfully merging a pull request may close this issue.

2 participants