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]: Cart metadata does not get assigned to order metadata on order completion #10629

Open
damianr13 opened this issue Dec 17, 2024 · 1 comment · May be fixed by #10631
Open

[Bug]: Cart metadata does not get assigned to order metadata on order completion #10629

damianr13 opened this issue Dec 17, 2024 · 1 comment · May be fixed by #10631

Comments

@damianr13
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",
    "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.1.1",
    "@medusajs/cli": "2.1.1",
    "@medusajs/framework": "2.1.1",
    "@medusajs/medusa": "2.1.1",
    "@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.1.1",
    "@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

v22.11.0

Database and its version

PostgreSQL 16.2

Operating system name and version

MacOS Sonoma 14.6.1

Browser name

N/A

What happended?

Even though the cart metadata should be assigned to the order metadata field, this doesn't happen.

Expected behavior

The metadata of a cart should automatically transfer to the order.

Actual behavior

The order metadata is always null.

Link to reproduction repo

N/A

@Lzok
Copy link

Lzok commented Dec 17, 2024

Hi! I am facing the same issue. Just in case the desired flow from the Medusa team isn't automatically copy the metadata from the cart to the order once placed, I also tried to update the order metadata with no luck.

For me at least, it would be extreme useful that the cart's metadata is copied automatically to the order once placed.

This is the other thing I was trying:

  1. Add metadata to the current cart. Then place the order.
  2. Once the order is placed, I use the SDK method adminSdk.admin.orderEdit.initiateRequest -> Here I send some metadata I want to add to the order
  3. adminSdk.admin.orderEdit.request -> Changing the edit's status to requested
  4. adminSdk.admin.orderEdit.confirm -> Confirming changes.

After that, I cannot see any metadata into the order, neither in the Admin UI nor in the database itself. Every metadata in the order is just null

Each call I made through the SDK is returning ok as expected, the initial metadata I send is also ok.

Here's my code (collapsed for readability)

Code
import Medusa from "@medusajs/js-sdk";

const adminSdk = new Medusa({
  baseUrl: MEDUSA_BACKEND_URL,
  debug: process.env.NODE_ENV === "development",
  apiKey: process.env.MEDUSA_ADMIN_API_KEY,
});

export async function updateOrderWithMetadata(
  orderId: string,
  metadata: Record<string, unknown>
) {
  try {
    const orderEditInitiated = await initiateOrderEdit(orderId, metadata).catch(
      (error) => {
        console.error("ORDER_EDIT_INITIATED_ERROR", error);
        throw error;
      }
    );
    console.log("ORDER_EDIT_INITIATED", orderEditInitiated);
    const orderEditRequested = await requestOrderEdit(orderId).catch(
      (error) => {
        console.error("ORDER_EDIT_REQUESTED", error);
        throw error;
      }
    );
    console.log("ORDER_EDIT_REQUESTED", orderEditRequested);

    const orderEditConfirmed = await confirmOrderEdit(orderId).catch(
      (error) => {
        console.error("ORDER_EDIT_CONFIRMED", error);
        throw error;
      }
    );
    console.log("ORDER_EDIT_CONFIRMED", orderEditConfirmed);
  } catch (error) {
    throw error;
  }
}

async function initiateOrderEdit(
  orderId: string,
  metadata: Record<string, unknown>
) {
  const { order_change } = await adminSdk.admin.orderEdit.initiateRequest({
    order_id: orderId,
    metadata,
  });

  return order_change;
}

async function requestOrderEdit(orderEditId: string) {
  const { order_preview } = await adminSdk.admin.orderEdit.request(orderEditId);

  return order_preview;
}

async function confirmOrderEdit(orderEditId: string) {
  const { order_preview } = await adminSdk.admin.orderEdit.confirm(orderEditId);

  return order_preview;
}

SDK Version I am using: "@medusajs/js-sdk": "2.1.2"

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.

3 participants