Workflows
createLocationFulfillmentSetAndAssociateWithSellerWorkflow
This documentation provides a reference to the createLocationFulfillmentSetAndAssociateWithSellerWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow creates a fulfillment set for a stock location and associates it with a seller. It establishes the necessary links between the stock location, fulfillment set, and seller to enable shipping configuration.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/stock-locations/[id]/fulfillment-sets/route.ts
import {
AuthenticatedMedusaRequest ,
MedusaResponse ,
} from "@medusajs/framework/http" ;
import { fetchSellerByAuthActorId } from "../../../../../shared/infra/http/utils" ;
import { createLocationFulfillmentSetAndAssociateWithSellerWorkflow } from "../../../../../workflows/fulfillment-set" ;
import { VendorCreateStockLocationFulfillmentSetType } from "../../validators" ;
export const POST = async (
req : AuthenticatedMedusaRequest < VendorCreateStockLocationFulfillmentSetType >,
res : MedusaResponse
) => {
const seller = await fetchSellerByAuthActorId (
req . auth_context . actor_id ,
req . scope
);
await createLocationFulfillmentSetAndAssociateWithSellerWorkflow (
req . scope
). run ({
input: {
location_id: req . params . id ,
fulfillment_set_data: {
name: req . validatedBody . name ,
type: req . validatedBody . type ,
},
seller_id: seller . id ,
},
});
// ... query and return stock location
};
Steps
createFulfillmentSets : Creates the fulfillment set using Medusa’s core step.
createRemoteLinkStep : Creates two links: one between the stock location and fulfillment set, and another between the seller and fulfillment set.
The fulfillment set creation and association details. The ID of the stock location to associate with the fulfillment set.
The fulfillment set details. The name of the fulfillment set.
The type of the fulfillment set (e.g., “shipping”, “pickup”).
The ID of the seller to associate with the fulfillment set.
Output
This workflow does not return a value.
createVendorServiceZonesWorkflow
This documentation provides a reference to the createVendorServiceZonesWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow creates one or more service zones for a fulfillment set and links them to a seller. It also emits intermediate events to trigger updates in search indexes and other systems.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/fulfillment-sets/[id]/service-zones/route.ts
import {
AuthenticatedMedusaRequest ,
MedusaResponse ,
} from "@medusajs/framework" ;
import { fetchSellerByAuthActorId } from "../../../../../shared/infra/http/utils" ;
import { createVendorServiceZonesWorkflow } from "../../../../../workflows/fulfillment-set" ;
import { VendorCreateServiceZoneType } from "../../validators" ;
export const POST = async (
req : AuthenticatedMedusaRequest < VendorCreateServiceZoneType >,
res : MedusaResponse
) => {
const seller = await fetchSellerByAuthActorId (
req . auth_context . actor_id ,
req . scope
);
await createVendorServiceZonesWorkflow ( req . scope ). run ({
input: {
data: [{ fulfillment_set_id: req . params . id , ... req . validatedBody }],
seller_id: seller . id ,
},
});
// ... query and return fulfillment set
};
Steps
createServiceZonesWorkflow : Creates the service zones using Medusa’s core workflow.
createRemoteLinkStep : Links the created service zones to the seller.
emitMultipleEventsStep : Emits service_zone.changed events for search index updates.
The service zone creation details. data
CreateServiceZoneDTO[]
required
Array of service zones to create. The name of the service zone.
The ID of the fulfillment set this service zone belongs to.
Array of geographical zones that define the service area. Each geo zone can be of type:
country - Covers an entire country
province - Covers a specific province/state
city - Covers a specific city
zip - Covers specific postal codes
The ID of the seller creating the service zones.
Output
The created service zones. The ID of the service zone.
The name of the service zone.
The ID of the associated fulfillment set.
The geographical zones that define the service area.
The date the service zone was created.
The date the service zone was last updated.
deleteVendorServiceZonesWorkflow
This documentation provides a reference to the deleteVendorServiceZonesWorkflow. It belongs to the @mercurjs/b2c-core package.
This workflow deletes one or more service zones, removes their links to the seller, and emits events to update dependent systems.
Source code
Examples
packages/modules/b2c-core/src/api/vendor/fulfillment-sets/[id]/service-zones/[zone_id]/route.ts
import {
AuthenticatedMedusaRequest ,
MedusaResponse ,
} from "@medusajs/framework" ;
import { fetchSellerByAuthActorId } from "../../../../../../shared/infra/http/utils" ;
import { deleteVendorServiceZonesWorkflow } from "../../../../../../workflows/fulfillment-set" ;
export const DELETE = async (
req : AuthenticatedMedusaRequest ,
res : MedusaResponse
) => {
const { zone_id } = req . params ;
const seller = await fetchSellerByAuthActorId (
req . auth_context . actor_id ,
req . scope
);
await deleteVendorServiceZonesWorkflow . run ({
container: req . scope ,
input: {
ids: [ zone_id ],
seller_id: seller . id ,
},
});
res . json ({ id: zone_id , object: "service_zone" , deleted: true });
};
Steps
deleteServiceZonesWorkflow : Deletes the service zones using Medusa’s core workflow.
dismissRemoteLinkStep : Removes the links between the service zones and the seller.
emitMultipleEventsStep : Emits service_zone.changed events for search index updates.
The service zone deletion details. Array of service zone IDs to delete.
The ID of the seller who owns the service zones.
Output
The IDs of the deleted service zones.
Steps
emitMultipleEventsStep
Emits multiple events to the event bus. This step is commonly used to notify other systems (like search indexes) about changes to data.
Source code
Array of events to emit. The name of the event to emit (e.g., “service_zone.changed”).
data
Record<string, any>
required
The event payload data.
Output
This step does not return a value.