Documentation Index Fetch the complete documentation index at: https://docs.mercurjs.com/llms.txt
Use this file to discover all available pages before exploring further.
Workflows
This documentation provides a reference to the getFormattedOrderSetListWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow retrieves order sets with calculated totals and aggregated statuses. An order set represents a group of orders created from a single cart in a multi-vendor marketplace. The workflow computes the overall payment status, fulfillment status, and financial totals by aggregating data from all orders within each set.
Source code
Examples
packages/modules/b2c-core/src/api/store/order-set/route.ts
import { AuthenticatedMedusaRequest , MedusaResponse } from '@medusajs/framework'
import { ContainerRegistrationKeys } from '@medusajs/framework/utils'
import { getFormattedOrderSetListWorkflow } from '../../../workflows/order-set/workflows'
import { defaultStoreRetrieveOrderSetFields } from './query-config'
export async function GET (
req : AuthenticatedMedusaRequest ,
res : MedusaResponse
) : Promise < void > {
const query = req . scope . resolve ( ContainerRegistrationKeys . QUERY )
const { data : order_set_ids , metadata } = await query . graph ({
entity: 'order_set' ,
fields: [ 'id' ],
filters: {
customer_id: req . auth_context . actor_id
},
pagination: req . queryConfig . pagination
})
const {
result : { data : order_sets }
} = await getFormattedOrderSetListWorkflow ( req . scope ). run ({
input: {
filters: { id: order_set_ids . map (( set ) => set . id ) },
fields: defaultStoreRetrieveOrderSetFields
}
})
res . json ({
order_sets ,
count: metadata ?. count ,
offset: metadata ?. skip ,
limit: metadata ?. take
})
}
packages/modules/b2c-core/src/api/store/order-set/[id]/route.ts
import { MedusaRequest , MedusaResponse } from '@medusajs/framework'
import { getFormattedOrderSetListWorkflow } from '../../../../workflows/order-set/workflows'
import { defaultStoreRetrieveOrderSetFields } from '../query-config'
export async function GET (
req : MedusaRequest ,
res : MedusaResponse
) : Promise < void > {
const { id } = req . params
const {
result : { data }
} = await getFormattedOrderSetListWorkflow ( req . scope ). run ({
input: { filters: { id }, fields: defaultStoreRetrieveOrderSetFields }
})
res . json ({
order_set: data [ 0 ]
})
}
packages/modules/b2c-core/src/api/store/carts/[id]/complete/route.ts
import { MedusaRequest , MedusaResponse } from '@medusajs/framework/http'
import { splitAndCompleteCartWorkflow } from '../../../../../workflows/cart/workflows'
import { getFormattedOrderSetListWorkflow } from '../../../../../workflows/order-set/workflows'
export const POST = async ( req : MedusaRequest , res : MedusaResponse ) => {
const cart_id = req . params . id
const { result } = await splitAndCompleteCartWorkflow ( req . scope ). run ({
input: { id: cart_id },
context: { transactionId: cart_id }
})
const {
result : { data }
} = await getFormattedOrderSetListWorkflow ( req . scope ). run ({
input: { filters: { id: result . id } }
})
res . json ({
order_set: data [ 0 ]
})
}
Steps
useQueryGraphStep : Fetches order sets with related orders, items, fulfillments, and payment data.
transform (formatOrderSets) : Aggregates order data to calculate totals and statuses for the entire order set.
The order set query parameters. Array of fields to include in the response. The workflow automatically adds required fields including order details, customer info, and fulfillments.
Filters to apply to the order set query. Filter by order set ID(s).
Filter by creation date range.
Pagination configuration. The number of items to skip.
The number of items to return.
Output
Array of formatted order sets with calculated totals and statuses. The display ID of the order set.
The ID of the customer who created the order set.
The ID of the original cart.
The original cart details.
The ID of the payment collection.
The payment collection details.
Array of orders in this order set, each with aggregated fulfillment and payment status.
The aggregated order status. Determined by:
completed - All orders are completed
canceled - All orders are canceled
requires_action - At least one order requires action
pending - Default state
The payment status from the payment collection (e.g., captured, authorized, pending).
The aggregated fulfillment status across all orders. Determined by:
canceled - All orders canceled
delivered - All orders delivered
fulfilled - All orders fulfilled
shipped - All orders shipped
partially_delivered - Some orders delivered
partially_shipped - Some orders shipped
partially_fulfilled - Some orders fulfilled
not_fulfilled - Default state
The total amount (sum of all order totals).
The subtotal (total minus tax_total).
The total tax amount across all orders.
The total shipping cost across all orders.
The total shipping tax across all orders.
The date the order set was created.
The date the order set was last updated.
Pagination metadata. The total number of order sets.
The number of items skipped.
The number of items returned.