Skip to content

[Bug]: Order Transfer Email Sent to Wrong Recipient on Re-Transfer #14161

@julianengel

Description

@julianengel

Package.json file

{
  "name": "medusa",
  "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",
    "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": {
    "@getbrevo/brevo": "^3.0.1",
    "@medusajs/admin-sdk": "2.11.3",
    "@medusajs/cli": "2.11.3",
    "@medusajs/framework": "2.11.3",
    "@medusajs/medusa": "2.11.3",
    "@mikro-orm/core": "6.4.16",
    "@mikro-orm/knex": "6.4.16",
    "@mikro-orm/migrations": "6.4.16",
    "@mikro-orm/postgresql": "6.4.16",
    "@react-email/components": "0.3.1",
    "awilix": "^8.0.1",
    "pg": "^8.13.0"
  },
  "devDependencies": {
    "@medusajs/test-utils": "2.11.3",
    "@mikro-orm/cli": "6.4.16",
    "@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",
    "yalc": "^1.0.0-pre.53"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

v22.20.0

Database and its version

PostgresSQL 18.0

Operating system name and version

Mac OS Latest

Browser name

No response

What happended?

When an order is transferred a second time (A→B, then B→C), there are two issues:

Issue 1: Transfer Email Sent to Wrong Recipient

The order transfer confirmation email is sent to the original owner (A) instead of the current owner (B).

This happens because any code using order.email to determine the recipient will always get the original order email - it's never updated when ownership changes via transfer.

Issue 2: Admin Activity Log Shows Wrong Email

In the Medusa Admin, the Activity log for order transfers shows the original order email instead of the current customer's email. This is confusing when viewing transfer history after multiple transfers.

Code Example (demonstrating the fix)

// This is wrong - order.email is always the original email
const originalEmail = order.email || order.customer?.email

// This is correct - order.customer.email reflects the current owner
const currentOwnerEmail = order.customer?.email || order.email

Flow Demonstrating the Bug

  1. Guest order placed with email [email protected]

  2. First transfer requested (to [email protected])

  3. Second transfer requested (to [email protected])

Expected behavior

  1. Email recipient: The order transfer confirmation email should be sent to the current owner of the order (the linked customer's email, falling back to order.email for guest orders)

  2. Activity log: The admin activity log should show the current customer's email, not the original order email

Actual behavior

  1. The email is always sent to order.email, which contains the original order email and is never updated during transfers

  2. The admin activity log displays order.email (original) instead of the current owner's email

Actual behavior

. The email is always sent to order.email, which contains the original order email and is never updated during transfers

  1. The admin activity log displays order.email (original) instead of the current owner's email

Reproduction

  1. Create a guest order with email [email protected]
  2. Request transfer to [email protected] and accept it
  3. Request transfer from customerA to [email protected]
  4. Observe:

Link to reproduction repo

N/A - This is a logic issue in how the recipient email is determined.

Link to reproduction repo

N/A

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions