docs: fix digital products recipe by adding shipping profile to snippets (#11452)

This commit is contained in:
Shahed Nasser
2025-02-13 17:52:20 +02:00
committed by GitHub
parent 1a3843a92a
commit 710cdaf677
2 changed files with 15 additions and 3 deletions

View File

@@ -698,6 +698,12 @@ export const POST = async (
req: AuthenticatedMedusaRequest<CreateRequestBody>,
res: MedusaResponse
) => {
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
const { data: [shippingProfile] } = await query.graph({
entity: "shipping_profile",
fields: ["id"],
})
const { result } = await createDigitalProductWorkflow(
req.scope
).run({
@@ -710,7 +716,10 @@ export const POST = async (
...media,
})) as Omit<CreateDigitalProductMediaInput, "digital_product_id">[],
},
product: req.validatedBody.product,
product: {
...req.validatedBody.product,
shipping_profile_id: shippingProfile.id,
},
},
})
@@ -720,7 +729,9 @@ export const POST = async (
}
```
This adds a `POST` API route at `/admin/digital-products`. In the route handler, you execute the `createDigitalProductWorkflow` created in the previous step, passing data from the request body as input.
This adds a `POST` API route at `/admin/digital-products`. In the route handler, you first retrieve a shipping profile to associate it with the product, which is required.
Then, you execute the `createDigitalProductWorkflow` created in the previous step, passing data from the request body as input, along with the retrieved shipping profile.
The route handler imports a validation schema from a `validation-schema` file. So, create the file `src/api/validation-schemas.ts` with the following content:
@@ -1392,6 +1403,7 @@ fetch(`/admin/digital-products`, {
// delegate setting the prices to the
// product's page.
prices: [],
shipping_profile_id: ""
}],
},
}),

View File

@@ -112,7 +112,7 @@ export const generatedEditDates = {
"app/nextjs-starter/page.mdx": "2025-01-06T12:19:31.143Z",
"app/recipes/b2b/page.mdx": "2025-01-29T11:35:23.247Z",
"app/recipes/commerce-automation/page.mdx": "2024-10-16T08:52:01.585Z",
"app/recipes/digital-products/examples/standard/page.mdx": "2025-02-04T07:36:59.024Z",
"app/recipes/digital-products/examples/standard/page.mdx": "2025-02-13T15:24:15.868Z",
"app/recipes/digital-products/page.mdx": "2025-01-06T11:19:35.623Z",
"app/recipes/ecommerce/page.mdx": "2024-10-22T11:01:01.218Z",
"app/recipes/integrate-ecommerce-stack/page.mdx": "2024-12-09T13:03:35.846Z",