Workflows
batchVendorPriceListPricesWorkflow
This documentation provides a reference to the batchVendorPriceListPricesWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow performs batch operations on price list prices, including creating, updating, and deleting prices. It validates that the seller owns all products being priced and that price IDs being updated belong to the specified price list.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/price-lists/[id]/products/route.ts
import { AuthenticatedMedusaRequest , MedusaResponse } from '@medusajs/framework'
import { ContainerRegistrationKeys } from '@medusajs/framework/utils'
import { fetchPriceListPriceIdsForProduct } from '@medusajs/medusa/api/admin/price-lists/helpers'
import { batchVendorPriceListPricesWorkflow } from '../../../../../workflows/price-list/workflows'
import { VendorUpdateProductsOnPriceListType } from '../../validators'
export const POST = async (
req : AuthenticatedMedusaRequest < VendorUpdateProductsOnPriceListType >,
res : MedusaResponse
) => {
const query = req . scope . resolve ( ContainerRegistrationKeys . QUERY )
const { id } = req . params
const { remove = [], create = [], update = [] } = req . validatedBody
const productPriceIds = await fetchPriceListPriceIdsForProduct (
id ,
remove ,
req . scope
)
await batchVendorPriceListPricesWorkflow . run ({
container: req . scope ,
input: {
id ,
create ,
update ,
delete: productPriceIds
}
})
const {
data : [ price_list ]
} = await query . graph ({
entity: 'price_list' ,
fields: req . queryConfig . fields ,
filters: {
id: req . params . id
}
})
res . json ({ price_list })
}
Steps
validateVendorPriceListPricesStep : Validates that the seller owns the products and that price IDs are valid.
batchPriceListPricesWorkflow : Creates, updates, and deletes prices using Medusa’s core workflow.
The batch price list operation details. The ID of the price list to update.
The ID of the seller who owns the price list.
Array of price IDs to delete from the price list.
create
CreatePriceListPriceWorkflowDTO[]
required
Array of prices to create. The ID of the product variant.
The currency code (e.g., “usd”).
The minimum quantity required for this price.
The maximum quantity allowed for this price.
Additional pricing rules.
update
UpdatePriceListPriceWorkflowDTO[]
required
Array of prices to update. The ID of the price to update.
The ID of the product variant.
Additional pricing rules.
Output
The result from the batch operation.
createVendorPriceListPricesWorkflow
This documentation provides a reference to the createVendorPriceListPricesWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow creates prices for a price list. It validates that the seller owns all product variants being priced before creating the prices.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/price-lists/[id]/prices/route.ts
import {
AuthenticatedMedusaRequest ,
MedusaResponse ,
} from "@medusajs/framework" ;
import { ContainerRegistrationKeys } from "@medusajs/framework/utils" ;
import { fetchSellerByAuthActorId } from "../../../../../shared/infra/http/utils" ;
import { createVendorPriceListPricesWorkflow } from "../../../../../workflows/price-list/workflows" ;
import { VendorCreatePriceListPriceType } from "../../validators" ;
export const POST = async (
req : AuthenticatedMedusaRequest < VendorCreatePriceListPriceType >,
res : MedusaResponse
) => {
const query = req . scope . resolve ( ContainerRegistrationKeys . QUERY );
const id = req . params . id ;
const seller = await fetchSellerByAuthActorId (
req . auth_context . actor_id ,
req . scope
);
await createVendorPriceListPricesWorkflow . run ({
container: req . scope ,
input: {
price_list_id: id ,
prices: [ req . validatedBody ],
seller_id: seller . id ,
},
});
const { data : price_list } = await query . graph ({
entity: "price_list" ,
fields: req . queryConfig . fields ,
filters: {
id: req . params . id ,
},
});
res . status ( 201 ). json ({ price_list });
};
Steps
validateVendorPriceListPricesStep : Validates that the seller owns the product variants.
createPriceListPricesWorkflow : Creates the prices using Medusa’s core workflow.
The price creation details. The ID of the price list to add prices to.
The ID of the seller creating the prices.
prices
CreatePriceListPriceWorkflowDTO[]
required
Array of prices to create. The ID of the product variant.
The currency code (e.g., “usd”).
The minimum quantity required for this price.
The maximum quantity allowed for this price.
Additional pricing rules.
Output
The result from the price creation operation.
createVendorPriceListWorkflow
This documentation provides a reference to the createVendorPriceListWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow creates a price list for a seller and links it to the seller. It validates that the seller owns all product variants included in the initial prices and establishes the necessary connection between the price list and seller.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/price-lists/route.ts
import { AuthenticatedMedusaRequest , MedusaResponse } from '@medusajs/framework'
import { fetchSellerByAuthActorId } from '../../../shared/infra/http/utils'
import { createVendorPriceListWorkflow } from '../../../workflows/price-list/workflows'
import { VendorCreatePriceListType } from './validators'
export const POST = async (
req : AuthenticatedMedusaRequest < VendorCreatePriceListType >,
res : MedusaResponse
) => {
const seller = await fetchSellerByAuthActorId (
req . auth_context . actor_id ,
req . scope
)
const {
result : [ price_list ]
} = await createVendorPriceListWorkflow . run ({
container: req . scope ,
input: { price_lists_data: req . validatedBody , seller_id: seller . id }
})
res . status ( 201 ). json ({ price_list })
}
Steps
validateVendorPriceListPricesStep : Validates that the seller owns all product variants in the initial prices.
createPriceListsWorkflow : Creates the price list using Medusa’s core workflow.
createRemoteLinkStep : Links the created price list to the seller.
The price list creation details. price_lists_data
CreatePriceListWorkflowInputDTO
required
The price list details. The title of the price list.
The description of the price list.
The status of the price list. Available statuses:
draft - Price list is in draft mode
active - Price list is active and applied
The type of the price list. Available types:
sale - Represents a sale price
override - Overrides existing prices
The date the price list becomes active (ISO 8601 format).
The date the price list expires (ISO 8601 format).
Rules that determine when the price list applies (e.g., customer group rules).
prices
CreatePriceListPriceWorkflowDTO[]
Array of initial prices to create with the price list.
The ID of the seller creating the price list.
Output
Array containing the created price list. The ID of the price list.
The title of the price list.
The description of the price list.
The status of the price list.
The type of the price list.
The date the price list starts.
The date the price list ends.
The date the price list was created.
The date the price list was last updated.
Steps
validateVendorPriceListPricesStep
Validates price list price operations for a vendor. It performs two types of validation:
For create operations: Verifies that the seller owns all product variants being priced.
For update operations: Verifies that all price IDs being updated belong to the specified price list.
Source code
The validation parameters. The ID of the seller performing the operation.
create
CreatePriceListPriceWorkflowDTO[]
Array of prices to create (validates product ownership).
update
UpdatePriceListPriceWorkflowDTO[]
Array of prices to update (validates price IDs belong to price list).
The ID of the price list (required when updating prices).
Output
Throws an INVALID_DATA error if validation fails.