Skip to main content

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.

Input

input
object
required
The batch price list operation details.

Output

PriceListDTO
PriceListDTO
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.

Input

input
object
required
The price creation details.

Output

PriceListDTO
PriceListDTO
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.

Input

input
object
required
The price list creation details.

Output

PriceListDTO[]
PriceListDTO[]
Array containing the created price list.

Steps

validateVendorPriceListPricesStep

Validates price list price operations for a vendor. It performs two types of validation:
  1. For create operations: Verifies that the seller owns all product variants being priced.
  2. For update operations: Verifies that all price IDs being updated belong to the specified price list.
Source code

Input

input
object
required
The validation parameters.

Output

void
void
Throws an INVALID_DATA error if validation fails.