docs: added missing service method in digital products recipe (#5899)

* docs: added missing service method in digital products recipe

* fix lint
This commit is contained in:
Shahed Nasser
2023-12-15 15:40:05 +02:00
committed by GitHub
parent 1d7888afca
commit 525ae6d728

View File

@@ -277,6 +277,7 @@ Creating an API Route also requires creating a service, which is a class that ty
```ts title="src/services/product-media.ts" badgeLabel="Backend"
import {
FindConfig,
ProductVariant,
ProductVariantService,
Selector,
TransactionBaseService,
@@ -331,6 +332,8 @@ Creating an API Route also requires creating a service, which is a class that ty
config.relations = relations
console.log(selector, config.relations)
const query = buildQuery(selector, config)
const [
@@ -404,6 +407,22 @@ Creating an API Route also requires creating a service, which is a class that ty
)
}
async retrieveMediasByVariant(
productVariant: ProductVariant
): Promise<ProductMedia[]> {
const productMediaRepo = this.activeManager_.getRepository(
ProductMedia
)
const query = buildQuery({
variant_id: productVariant.id,
})
const productMedias = await productMediaRepo.find(query)
return productMedias
}
async create(
data: Pick<
ProductMedia,
@@ -716,6 +735,12 @@ To add an interface that allows the admin user to upload digital products, you c
In the page, youll show the list of digital products in a table, if there are any. Youll also show a button that opens a drawer to the side of the page.
In the drawer, you show the Create Digital Product form. To create this form, create the file `src/admin/components/product-media/CreateForm/index.tsx` with the following content:
:::note
If you're using `@tanstack/react-query` v4, please change all occurrences of `isPending` to `isLoading`.
:::
```tsx title="src/admin/components/product-media/CreateForm/index.tsx" badgeLabel="Backend"
import { useState } from "react"