Skip to content

Commit 710cdaf

Browse files
authored
docs: fix digital products recipe by adding shipping profile to snippets (medusajs#11452)
1 parent 1a3843a commit 710cdaf

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

www/apps/resources/app/recipes/digital-products/examples/standard/page.mdx

+14-2
Original file line numberDiff line numberDiff line change
@@ -698,6 +698,12 @@ export const POST = async (
698698
req: AuthenticatedMedusaRequest<CreateRequestBody>,
699699
res: MedusaResponse
700700
) => {
701+
const query = req.scope.resolve(ContainerRegistrationKeys.QUERY)
702+
const { data: [shippingProfile] } = await query.graph({
703+
entity: "shipping_profile",
704+
fields: ["id"],
705+
})
706+
701707
const { result } = await createDigitalProductWorkflow(
702708
req.scope
703709
).run({
@@ -710,7 +716,10 @@ export const POST = async (
710716
...media,
711717
})) as Omit<CreateDigitalProductMediaInput, "digital_product_id">[],
712718
},
713-
product: req.validatedBody.product,
719+
product: {
720+
...req.validatedBody.product,
721+
shipping_profile_id: shippingProfile.id,
722+
},
714723
},
715724
})
716725

@@ -720,7 +729,9 @@ export const POST = async (
720729
}
721730
```
722731

723-
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.
732+
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.
733+
734+
Then, you execute the `createDigitalProductWorkflow` created in the previous step, passing data from the request body as input, along with the retrieved shipping profile.
724735

725736
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:
726737

@@ -1392,6 +1403,7 @@ fetch(`/admin/digital-products`, {
13921403
// delegate setting the prices to the
13931404
// product's page.
13941405
prices: [],
1406+
shipping_profile_id: ""
13951407
}],
13961408
},
13971409
}),

www/apps/resources/generated/edit-dates.mjs

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

0 commit comments

Comments
 (0)