From 710cdaf6771def730083903d26cf63a6ddde0cdb Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Thu, 13 Feb 2025 17:52:20 +0200 Subject: [PATCH] docs: fix digital products recipe by adding shipping profile to snippets (#11452) --- .../digital-products/examples/standard/page.mdx | 16 ++++++++++++++-- www/apps/resources/generated/edit-dates.mjs | 2 +- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx b/www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx index 3d444c58d3..c275cbae99 100644 --- a/www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx +++ b/www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx @@ -698,6 +698,12 @@ export const POST = async ( req: AuthenticatedMedusaRequest, 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[], }, - 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: "" }], }, }), diff --git a/www/apps/resources/generated/edit-dates.mjs b/www/apps/resources/generated/edit-dates.mjs index 11cfbd0c9c..6eed328af1 100644 --- a/www/apps/resources/generated/edit-dates.mjs +++ b/www/apps/resources/generated/edit-dates.mjs @@ -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",