Skip to main content

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.

Input

input
object
required
The fulfillment set creation and association details.

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.

Input

input
object
required
The service zone creation details.

Output

ServiceZoneDTO[]
ServiceZoneDTO[]
The created service zones.

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.

Input

input
object
required
The service zone deletion details.

Output

string[]
string[]
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

Input

input
object[]
required
Array of events to emit.

Output

This step does not return a value.