- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
- Get Started
- Product
- Resources
- Tools & SDKs
- Framework
- Reference
Sales Channel Module
In this section of the documentation, you will find resources to learn more about the Sales Channel Module and how to use it in your application.
Medusa has sales channel related features available out-of-the-box through the Sales Channel Module. A module is a standalone package that provides features for a single domain. Each of Medusa's commerce features are placed in commerce modules, such as this Sales Channel Module.
What's a Sales Channel?#
A sales channel indicates an online or offline channel that you sell products on.
Some use case examples for using a sales channel:
- Implement a B2B Ecommerce Store.
- Specify different products for each channel you sell in.
- Support omnichannel in your ecommerce store.
Sales Channel Features#
- Sales Channel Management: Manage sales channels in your store. Each sales channel has different meta information such as name or description, allowing you to easily differentiate between sales channels.
- Product Availability: Medusa uses the Product and Sales Channel modules to allow merchants to specify a product's availability per sales channel.
- Cart and Order Scoping: Carts, available through the Cart Module, are scoped to a sales channel. Paired with the product availability feature, you benefit from more features like allowing only products available in sales channel in a cart.
- Inventory Availability Per Sales Channel: Medusa links sales channels to stock locations, allowing you to retrieve available inventory of products based on the specified sales channel.
How to Use Sales Channel Module's Service#
In your Medusa application, you build flows around commerce modules. A flow is built as a Workflow, which is a special function composed of a series of steps that guarantees data consistency and reliable roll-back mechanism.
You can build custom workflows and steps. You can also re-use Medusa's workflows and steps, which are provided by the @medusajs/medusa/core-flows
package.
For example:
1import { 2 createWorkflow, 3 WorkflowResponse,4 createStep,5 StepResponse,6} from "@medusajs/framework/workflows-sdk"7import { Modules } from "@medusajs/framework/utils"8 9const createSalesChannelStep = createStep(10 "create-sales-channel",11 async ({}, { container }) => {12 const salesChannelModuleService = container.resolve(Modules.SALES_CHANNEL)13 14 const salesChannels = await salesChannelModuleService.createSalesChannels([15 {16 name: "B2B",17 },18 {19 name: "Mobile App",20 },21 ])22 23 return new StepResponse({ salesChannels }, salesChannels.map((sc) => sc.id))24 },25 async (salesChannelIds, { container }) => {26 if (!salesChannelIds) {27 return28 }29 const salesChannelModuleService = container.resolve(Modules.SALES_CHANNEL)30 31 await salesChannelModuleService.deleteSalesChannels(32 salesChannelIds33 )34 }35)36 37export const createSalesChannelWorkflow = createWorkflow(38 "create-sales-channel",39 () => {40 const { salesChannels } = createSalesChannelStep()41 42 return new WorkflowResponse({43 salesChannels,44 })45 }46)
You can then execute the workflow in your custom API routes, scheduled jobs, or subscribers:
Learn more about workflows in this documentation.