Skip to content

Latest commit

 

History

History
832 lines (637 loc) · 19.7 KB

File metadata and controls

832 lines (637 loc) · 19.7 KB
products
customer
cart
fulfillment
payment
product
promotion
region
sales channel

import { CodeTabs, CodeTab, Table } from "docs-ui"

export const metadata = { title: Links between Order Module and Other Modules, }

{metadata.title}

This document showcases the module links defined between the Order Module and other Commerce Modules.

Summary

The Order Module has the following links to other modules:

Read-only links are used to query data across modules, but the relations aren't stored in a pivot table in the database.

First Data Model Second Data Model Type Description [OrderShippingMethod](/references/order/models/OrderShippingMethod) [ShippingOption](/references/fulfillment/models/ShippingOption) in [Fulfillment Module](../../fulfillment/page.mdx) Read-only - has one [Learn more](#fulfillment-module-shipping-option) [Order](/references/order/models/Order) [Customer](/references/customer/models/Customer) in [Customer Module](../../customer/page.mdx) Read-only - has one [Learn more](#customer-module) [Order](/references/order/models/Order) [Cart](/references/cart/models/Cart) in [Cart Module](../../cart/page.mdx) Stored - one-to-one [Learn more](#cart-module) [Order](/references/order/models/Order) [Fulfillment](/references/fulfillment/models/Fulfillment) in [Fulfillment Module](../../fulfillment/page.mdx) Stored - one-to-many [Learn more](#fulfillment-module) [Return](/references/order/models/Return) [Fulfillment](/references/fulfillment/models/Fulfillment) in [Fulfillment Module](../../fulfillment/page.mdx) Stored - one-to-many [Learn more](#fulfillment-module) [Order](/references/order/models/Order) [PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) Stored - one-to-many [Learn more](#payment-module) [OrderClaim](/references/order/models/OrderClaim) [PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) Stored - one-to-many [Learn more](#payment-module) [OrderExchange](/references/order/models/OrderExchange) [PaymentCollection](/references/payment/models/PaymentCollection) in [Payment Module](../../payment/page.mdx) Stored - one-to-many [Learn more](#payment-module) [OrderLineItem](/references/order/models/OrderLineItem) [Product](/references/product/models/Product) in [Product Module](../../product/page.mdx) Read-only - has many [Learn more](#product-module) [Order](/references/order/models/Order) [Promotion](/references/promotion/models/Promotion) in [Promotion Module](../../promotion/page.mdx) Stored - many-to-many [Learn more](#promotion-module) [Order](/references/order/models/Order) [Region](/references/region/models/Region) in [Region Module](../../region/page.mdx) Read-only - has one [Learn more](#region-module) [Order](/references/order/models/Order) [SalesChannel](/references/sales-channel/models/SalesChannel) in [Sales Channel Module](../../sales-channel/page.mdx) Read-only - has one [Learn more](#sales-channel-module)

Fulfillment Module - Shipping Option

Medusa defines a read-only link between the OrderShippingMethod data model and the Fulfillment Module's ShippingOption data model. This means you can retrieve the details of an order shipping method's shipping option, but you don't manage the links in a pivot table in the database. The shipping option of an order shipping method is determined by the shipping_option_id property of the OrderShippingMethod data model.

Retrieve with Query

To retrieve the shipping option of an order shipping method with Query, pass shipping_option.* in fields:

const { data: orderShippingMethods } = await query.graph({
  entity: "order_shipping_method",
  fields: [
    "shipping_option.*",
  ],
})

// orderShippingMethods[0].shipping_option
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orderShippingMethods } = useQueryGraphStep({
  entity: "order_shipping_method",
  fields: [
    "shipping_option.*",
  ],
})

// orderShippingMethods[0].shipping_option

Customer Module

Medusa defines a read-only link between the Order data model and the Customer Module's Customer data model. This means you can retrieve the details of an order's customer, but you don't manage the links in a pivot table in the database. The customer of an order is determined by the customer_id property of the Order data model.

Retrieve with Query

To retrieve the customer of an order with Query, pass customer.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "customer.*",
  ],
})

// orders[0].customer
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "customer.*",
  ],
})

// orders[0].customer

Cart Module

The Cart Module provides cart-management features.

Medusa defines a link between the Order and Cart data models. The order is linked to the cart used for the purchased.

A diagram showcasing an example of how data models from the Cart and Order modules are linked

Retrieve with Query

To retrieve the cart of an order with Query, pass cart.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "cart.*",
  ],
})

// orders[0].cart
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "cart.*",
  ],
})

// orders[0].cart

Manage with Link

To manage the cart of an order, use Link:

import { Modules } from "@medusajs/framework/utils"

// ...

await link.create({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.CART]: {
    cart_id: "cart_123",
  },
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"

// ...

createRemoteLinkStep({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.CART]: {
    cart_id: "cart_123",
  },
})

Fulfillment Module

A fulfillment is created for an orders' items. Medusa defines a link between the Fulfillment and Order data models.

A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked

A fulfillment is also created for a return's items. So, Medusa defines a link between the Fulfillment and Return data models.

A diagram showcasing an example of how data models from the Fulfillment and Order modules are linked

Retrieve with Query

To retrieve the fulfillments of an order with Query, pass fulfillments.* in fields:

To retrieve the fulfillments of a return, pass fulfillments.* in fields.

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "fulfillments.*",
  ],
})

// orders[0].fulfillments
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "fulfillments.*",
  ],
})

// orders[0].fulfillments

Manage with Link

To manage the fulfillments of an order, use Link:

import { Modules } from "@medusajs/framework/utils"

// ...

await link.create({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.FULFILLMENT]: {
    fulfillment_id: "ful_123",
  },
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"

// ...

createRemoteLinkStep({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.FULFILLMENT]: {
    fulfillment_id: "ful_123",
  },
})

Payment Module

An order's payment details are stored in a payment collection. This also applies for claims and exchanges.

So, Medusa defines links between the PaymentCollection data model and the Order, OrderClaim, and OrderExchange data models.

A diagram showcasing an example of how data models from the Order and Payment modules are linked

Retrieve with Query

To retrieve the payment collections of an order, order exchange, or order claim with Query, pass payment_collections.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "payment_collections.*",
  ],
})

// orders[0].payment_collections
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "payment_collections.*",
  ],
})

// orders[0].payment_collections

Manage with Link

To manage the payment collections of an order, use Link:

import { Modules } from "@medusajs/framework/utils"

// ...

await link.create({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.PAYMENT]: {
    payment_collection_id: "paycol_123",
  },
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"

// ...

createRemoteLinkStep({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.PAYMENT]: {
    payment_collection_id: "paycol_123",
  },
})

Product Module

Medusa defines read-only links between:

  • the OrderLineItem data model and the Product Module's Product data model. This means you can retrieve the details of a line item's product, but you don't manage the links in a pivot table in the database. The product of a line item is determined by the product_id property of the OrderLineItem data model.
  • the OrderLineItem data model and the Product Module's ProductVariant data model. This means you can retrieve the details of a line item's variant, but you don't manage the links in a pivot table in the database. The variant of a line item is determined by the variant_id property of the OrderLineItem data model.

Retrieve with Query

To retrieve the variant of a line item with Query, pass variant.* in fields:

To retrieve the product, pass product.* in fields.

const { data: lineItems } = await query.graph({
  entity: "order_line_item",
  fields: [
    "variant.*",
  ],
})

// lineItems.variant
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: lineItems } = useQueryGraphStep({
  entity: "order_line_item",
  fields: [
    "variant.*",
  ],
})

// lineItems.variant

Promotion Module

An order is associated with the promotion applied on it. Medusa defines a link between the Order and Promotion data models.

A diagram showcasing an example of how data models from the Order and Promotion modules are linked

Retrieve with Query

To retrieve the promotion applied on an order with Query, pass promotion.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "promotions.*",
  ],
})

// orders[0].promotions
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "promotions.*",
  ],
})

// orders[0].promotions

Manage with Link

To manage the promotion of an order, use Link:

import { Modules } from "@medusajs/framework/utils"

// ...

await link.create({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.PROMOTION]: {
    promotion_id: "promo_123",
  },
})
import { Modules } from "@medusajs/framework/utils"
import { createRemoteLinkStep } from "@medusajs/medusa/core-flows"

// ...

createRemoteLinkStep({
  [Modules.ORDER]: {
    order_id: "order_123",
  },
  [Modules.PROMOTION]: {
    promotion_id: "promo_123",
  },
})

Region Module

Medusa defines a read-only link between the Order data model and the Region Module's Region data model. This means you can retrieve the details of an order's region, but you don't manage the links in a pivot table in the database. The region of an order is determined by the region_id property of the Order data model.

Retrieve with Query

To retrieve the region of an order with Query, pass region.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "region.*",
  ],
})

// orders[0].region
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "region.*",
  ],
})

// orders[0].region

Sales Channel Module

Medusa defines a read-only link between the Order data model and the Sales Channel Module's SalesChannel data model. This means you can retrieve the details of an order's sales channel, but you don't manage the links in a pivot table in the database. The sales channel of an order is determined by the sales_channel_id property of the Order data model.

Retrieve with Query

To retrieve the sales channel of an order with Query, pass sales_channel.* in fields:

const { data: orders } = await query.graph({
  entity: "order",
  fields: [
    "sales_channel.*",
  ],
})

// orders[0].sales_channel
import { useQueryGraphStep } from "@medusajs/medusa/core-flows"

// ...

const { data: orders } = useQueryGraphStep({
  entity: "order",
  fields: [
    "sales_channel.*",
  ],
})

// orders[0].sales_channel