docs: added customer storefront guides (#7685)
* added customer guides * fixes to sidebar * remove old customer registration guide * fix build error * generate files * run linter
This commit is contained in:
@@ -245,16 +245,16 @@ You can create a B2B module that adds necessary data models to represent a B2B c
|
||||
Next, create the migration in the file `src/modules/b2b/migrations/Migration20240516081502.ts` with the following content:
|
||||
|
||||
```ts title="src/modules/b2b/migrations/Migration20240516081502.ts"
|
||||
import { Migration } from '@mikro-orm/migrations';
|
||||
|
||||
import { Migration } from "@mikro-orm/migrations"
|
||||
|
||||
export class Migration20240516081502 extends Migration {
|
||||
|
||||
async up(): Promise<void> {
|
||||
this.addSql('create table if not exists "company" ("id" text not null, "name" text not null, "city" text not null, "country_code" text not null, "customer_group_id" text not null, constraint "company_pkey" primary key ("id"));');
|
||||
this.addSql("create table if not exists \"company\" (\"id\" text not null, \"name\" text not null, \"city\" text not null, \"country_code\" text not null, \"customer_group_id\" text not null, constraint \"company_pkey\" primary key (\"id\"));")
|
||||
}
|
||||
|
||||
async down(): Promise<void> {
|
||||
this.addSql('drop table if exists "company" cascade;');
|
||||
this.addSql("drop table if exists \"company\" cascade;")
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -295,9 +295,9 @@ export const mainServiceHighlights = [
|
||||
import { ModulesSdkUtils } from "@medusajs/utils"
|
||||
import { ModuleJoinerConfig, ModulesSdkTypes } from "@medusajs/types"
|
||||
import { Modules } from "@medusajs/modules-sdk"
|
||||
import { Company } from "./models/company";
|
||||
import { CompanyDTO, CreateCompanyDTO } from "../../types/b2b";
|
||||
|
||||
import { Company } from "./models/company"
|
||||
import { CompanyDTO, CreateCompanyDTO } from "../../types/b2b"
|
||||
|
||||
type InjectedDependencies = {
|
||||
companyService: ModulesSdkTypes.InternalModuleService<any>
|
||||
}
|
||||
@@ -329,9 +329,9 @@ export const mainServiceHighlights = [
|
||||
{
|
||||
name: ["company"],
|
||||
args: {
|
||||
entity: Company.name
|
||||
}
|
||||
}
|
||||
entity: Company.name,
|
||||
},
|
||||
},
|
||||
],
|
||||
relationships: [
|
||||
{
|
||||
@@ -340,14 +340,14 @@ export const mainServiceHighlights = [
|
||||
primaryKey: "id",
|
||||
foreignKey: "customer_group_id",
|
||||
args: {
|
||||
methodSuffix: "CustomerGroups"
|
||||
}
|
||||
}
|
||||
]
|
||||
methodSuffix: "CustomerGroups",
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
async create (data: CreateCompanyDTO): Promise<CompanyDTO> {
|
||||
async create(data: CreateCompanyDTO): Promise<CompanyDTO> {
|
||||
const company = this.companyService_.create(data)
|
||||
|
||||
return company
|
||||
@@ -365,8 +365,8 @@ export const mainServiceHighlights = [
|
||||
Next, create the module definition at `src/modules/b2b/index.ts` with the following content:
|
||||
|
||||
```ts title="src/modules/b2b/index.ts"
|
||||
import B2bModuleService from "./service";
|
||||
|
||||
import B2bModuleService from "./service"
|
||||
|
||||
export default {
|
||||
service: B2bModuleService,
|
||||
}
|
||||
@@ -381,10 +381,10 @@ export const mainServiceHighlights = [
|
||||
b2bModuleService: {
|
||||
resolve: "./modules/b2b",
|
||||
definition: {
|
||||
isQueryable: true
|
||||
}
|
||||
isQueryable: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
},
|
||||
})
|
||||
```
|
||||
|
||||
@@ -411,15 +411,15 @@ export const workflowHighlights = [
|
||||
import {
|
||||
StepResponse,
|
||||
createStep,
|
||||
createWorkflow
|
||||
} from "@medusajs/workflows-sdk";
|
||||
createWorkflow,
|
||||
} from "@medusajs/workflows-sdk"
|
||||
import {
|
||||
createCustomerGroupsWorkflow
|
||||
createCustomerGroupsWorkflow,
|
||||
} from "@medusajs/core-flows"
|
||||
import { CreateCustomerGroupDTO } from "@medusajs/types";
|
||||
import { CompanyDTO, CreateCompanyDTO } from "../types/b2b";
|
||||
import B2bModuleService from "../modules/b2b/service";
|
||||
|
||||
import { CreateCustomerGroupDTO } from "@medusajs/types"
|
||||
import { CompanyDTO, CreateCompanyDTO } from "../types/b2b"
|
||||
import B2bModuleService from "../modules/b2b/service"
|
||||
|
||||
export type CreateCompanyWorkflowInput = CreateCompanyDTO & {
|
||||
customer_group?: CreateCustomerGroupDTO
|
||||
}
|
||||
@@ -447,8 +447,8 @@ export const workflowHighlights = [
|
||||
container
|
||||
).run({
|
||||
input: {
|
||||
customersData: [customer_group]
|
||||
}
|
||||
customersData: [customer_group],
|
||||
},
|
||||
})
|
||||
|
||||
company.customer_group_id = result[0].id
|
||||
@@ -486,7 +486,7 @@ export const workflowHighlights = [
|
||||
"create-company",
|
||||
function (input) {
|
||||
const {
|
||||
company: companyData
|
||||
company: companyData,
|
||||
} = tryToCreateCustomerGroupStep(input)
|
||||
|
||||
const company = createCompanyStep({ companyData })
|
||||
@@ -506,11 +506,11 @@ export const workflowHighlights = [
|
||||
```ts title="src/api/admin/b2b/company/route.ts" collapsibleLines="1-9" expandButtonLabel="Show Imports"
|
||||
import type {
|
||||
MedusaRequest,
|
||||
MedusaResponse
|
||||
} from "@medusajs/medusa";
|
||||
MedusaResponse,
|
||||
} from "@medusajs/medusa"
|
||||
import {
|
||||
CreateCompanyWorkflowInput,
|
||||
createCompanyWorkflow
|
||||
createCompanyWorkflow,
|
||||
} from "../../../../workflows/create-company"
|
||||
|
||||
type CreateCompanyReq = CreateCompanyWorkflowInput
|
||||
@@ -521,11 +521,11 @@ export const workflowHighlights = [
|
||||
) {
|
||||
const { result } = await createCompanyWorkflow(req.scope)
|
||||
.run({
|
||||
input: req.body
|
||||
input: req.body,
|
||||
})
|
||||
|
||||
res.json({
|
||||
company: result.company
|
||||
company: result.company,
|
||||
})
|
||||
}
|
||||
```
|
||||
@@ -698,11 +698,11 @@ export const checkCustomerHighlights = [
|
||||
]
|
||||
|
||||
```ts title="src/api/store/b2b/check-customer/route.ts" highlights={checkCustomerHighlights} collapsibleLines="1-5" expandButtonLabel="Show Imports"
|
||||
import type { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/medusa";
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk";
|
||||
import { ICustomerModuleService } from "@medusajs/types";
|
||||
import B2bModuleService from "../../../../modules/b2b/service";
|
||||
|
||||
import type { AuthenticatedMedusaRequest, MedusaResponse } from "@medusajs/medusa"
|
||||
import { ModuleRegistrationName } from "@medusajs/modules-sdk"
|
||||
import { ICustomerModuleService } from "@medusajs/types"
|
||||
import B2bModuleService from "../../../../modules/b2b/service"
|
||||
|
||||
export async function GET(
|
||||
req: AuthenticatedMedusaRequest,
|
||||
res: MedusaResponse
|
||||
@@ -714,15 +714,15 @@ export const checkCustomerHighlights = [
|
||||
)
|
||||
|
||||
const customer = await customerModuleService.retrieve(req.auth.actor_id, {
|
||||
relations: ["groups"]
|
||||
relations: ["groups"],
|
||||
})
|
||||
|
||||
const companies = await b2bModuleService.list({
|
||||
customer_group_id: customer.groups.map((group) => group.id)
|
||||
customer_group_id: customer.groups.map((group) => group.id),
|
||||
})
|
||||
|
||||
res.json({
|
||||
is_b2b: companies.length > 0
|
||||
is_b2b: companies.length > 0,
|
||||
})
|
||||
}
|
||||
```
|
||||
@@ -743,7 +743,7 @@ export const checkCustomerHighlights = [
|
||||
{
|
||||
matcher: "/store/b2b*",
|
||||
middlewares: [
|
||||
authenticate("store", ["bearer", "session"])
|
||||
authenticate("store", ["bearer", "session"]),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user