chore: move ModuleRegistrationName to utils (#7911)
This commit is contained in:
@@ -51,65 +51,57 @@ To search through product variants by their barcode, create a custom API Route a
|
||||
|
||||

|
||||
|
||||
<CardList itemsPerRow={2} items={[
|
||||
{
|
||||
href: "/commerce-modules/product",
|
||||
title: "Product Module",
|
||||
text: "Learn about the Product Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "!docs!/basics/api-routes",
|
||||
title: "Create API Route",
|
||||
text: "Learn how to create an API Route.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
]} />
|
||||
<CardList
|
||||
itemsPerRow={2}
|
||||
items={[
|
||||
{
|
||||
href: "/commerce-modules/product",
|
||||
title: "Product Module",
|
||||
text: "Learn about the Product Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "!docs!/basics/api-routes",
|
||||
title: "Create API Route",
|
||||
text: "Learn how to create an API Route.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
<Details summaryContent="Example: Search Products By Barcode API Route">
|
||||
|
||||
Here’s an example of creating a custom API Route at `/store/pos/search-barcode` that searches product variants by a barcode:
|
||||
Here’s an example of creating a custom API Route at `/store/pos/search-barcode` that searches product variants by a barcode:
|
||||
|
||||
```ts title="src/api/store/pos/search-barcode/route.ts" collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
```ts title="src/api/store/pos/search-barcode/route.ts" collapsibleLines="1-8" expandButtonLabel="Show Imports"
|
||||
import type { MedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import { MedusaError } from "@medusajs/utils"
|
||||
import { ModuleRegistrationName } from "@medusajs/utils"
|
||||
import { IProductModuleService } from "@medusajs/types"
|
||||
|
||||
export const GET = async (
|
||||
req: MedusaRequest,
|
||||
res: MedusaResponse
|
||||
) => {
|
||||
const barcode = (req.query.barcode as string) || ""
|
||||
if (!barcode) {
|
||||
throw new MedusaError(
|
||||
MedusaError.Types.INVALID_DATA,
|
||||
"Barcode is required"
|
||||
)
|
||||
}
|
||||
// get product service
|
||||
const productModuleService: IProductModuleService =
|
||||
req.scope.resolve(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
)
|
||||
|
||||
// retrieve product variants by barcode
|
||||
const productVariants = await productModuleService
|
||||
.listProductVariants({
|
||||
// @ts-ignore
|
||||
barcode,
|
||||
})
|
||||
|
||||
res.json({
|
||||
product_variants: productVariants,
|
||||
})
|
||||
export const GET = async (req: MedusaRequest, res: MedusaResponse) => {
|
||||
const barcode = (req.query.barcode as string) || ""
|
||||
if (!barcode) {
|
||||
throw new MedusaError(MedusaError.Types.INVALID_DATA, "Barcode is required")
|
||||
}
|
||||
```
|
||||
// get product service
|
||||
const productModuleService: IProductModuleService = req.scope.resolve(
|
||||
ModuleRegistrationName.PRODUCT
|
||||
)
|
||||
|
||||
// retrieve product variants by barcode
|
||||
const productVariants = await productModuleService.listProductVariants({
|
||||
// @ts-ignore
|
||||
barcode,
|
||||
})
|
||||
|
||||
res.json({
|
||||
product_variants: productVariants,
|
||||
})
|
||||
}
|
||||
```
|
||||
|
||||
</Details>
|
||||
|
||||
@@ -127,29 +119,31 @@ Merchants can create a sales channel for their online store and a sales channel
|
||||
|
||||
This also opens the door for other business opportunities, such as an endless aisle experience. Suppose a product isn't available in-store but is available in different warehouses. You can allow customers to purchase that item in-store and deliver it to their address.
|
||||
|
||||
<CardList items={[
|
||||
{
|
||||
href: "/commerce-modules/inventory",
|
||||
title: "Inventory Module",
|
||||
text: "Learn about the Inventory Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/stock-location",
|
||||
title: "Stock Location Module",
|
||||
text: "Learn about the Stock Location Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/sales-channel",
|
||||
title: "Sales Channel Module",
|
||||
text: "Learn about the Sales Channel Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
]} />
|
||||
<CardList
|
||||
items={[
|
||||
{
|
||||
href: "/commerce-modules/inventory",
|
||||
title: "Inventory Module",
|
||||
text: "Learn about the Inventory Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/stock-location",
|
||||
title: "Stock Location Module",
|
||||
text: "Learn about the Stock Location Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/sales-channel",
|
||||
title: "Sales Channel Module",
|
||||
text: "Learn about the Sales Channel Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
---
|
||||
|
||||
@@ -161,29 +155,31 @@ In addition, using Medusa's Promotion Module, store operators can create promoti
|
||||
|
||||
You can also create custom modules to provide features for a better customer experience, such as a rewards system or loyalty points.
|
||||
|
||||
<CardList items={[
|
||||
{
|
||||
href: "/commerce-modules/customer",
|
||||
title: "Customer Module",
|
||||
text: "Learn about the Customer Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/promotion",
|
||||
title: "Promotion Module",
|
||||
text: "Learn about the Promotion Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "!docs!/basics/modules-and-services",
|
||||
title: "Create a Module",
|
||||
text: "Learn how to create a module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
]} />
|
||||
<CardList
|
||||
items={[
|
||||
{
|
||||
href: "/commerce-modules/customer",
|
||||
title: "Customer Module",
|
||||
text: "Learn about the Customer Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "/commerce-modules/promotion",
|
||||
title: "Promotion Module",
|
||||
text: "Learn about the Promotion Module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "!docs!/basics/modules-and-services",
|
||||
title: "Create a Module",
|
||||
text: "Learn how to create a module.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
---
|
||||
|
||||
@@ -195,19 +191,21 @@ Once you accept the payment, place an order in the POS system using the [Draft O
|
||||
|
||||
Then, merchants can view all orders coming from different sales channels using the Medusa Admin. This keeps logistics and order handling consistent between online and in-store customers.
|
||||
|
||||
<CardList items={[
|
||||
{
|
||||
href: "/references/payment/provider",
|
||||
title: "Create a Payment Module Provider",
|
||||
text: "Learn how to create a payment module provider.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
{
|
||||
href: "!api!/admin",
|
||||
title: "Admin REST APIs",
|
||||
text: "Check out available Admin REST APIs.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false
|
||||
},
|
||||
]} />
|
||||
<CardList
|
||||
items={[
|
||||
{
|
||||
href: "/references/payment/provider",
|
||||
title: "Create a Payment Module Provider",
|
||||
text: "Learn how to create a payment module provider.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
{
|
||||
href: "!api!/admin",
|
||||
title: "Admin REST APIs",
|
||||
text: "Check out available Admin REST APIs.",
|
||||
startIcon: <AcademicCapSolid />,
|
||||
showLinkIcon: false,
|
||||
},
|
||||
]}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user