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:
@@ -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"
|
```ts title="src/services/product-media.ts" badgeLabel="Backend"
|
||||||
import {
|
import {
|
||||||
FindConfig,
|
FindConfig,
|
||||||
|
ProductVariant,
|
||||||
ProductVariantService,
|
ProductVariantService,
|
||||||
Selector,
|
Selector,
|
||||||
TransactionBaseService,
|
TransactionBaseService,
|
||||||
@@ -331,6 +332,8 @@ Creating an API Route also requires creating a service, which is a class that ty
|
|||||||
|
|
||||||
config.relations = relations
|
config.relations = relations
|
||||||
|
|
||||||
|
console.log(selector, config.relations)
|
||||||
|
|
||||||
const query = buildQuery(selector, config)
|
const query = buildQuery(selector, config)
|
||||||
|
|
||||||
const [
|
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(
|
async create(
|
||||||
data: Pick<
|
data: Pick<
|
||||||
ProductMedia,
|
ProductMedia,
|
||||||
@@ -717,6 +736,12 @@ To add an interface that allows the admin user to upload digital products, you c
|
|||||||
|
|
||||||
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:
|
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"
|
```tsx title="src/admin/components/product-media/CreateForm/index.tsx" badgeLabel="Backend"
|
||||||
import { useState } from "react"
|
import { useState } from "react"
|
||||||
import { MediaType } from "../../../../models/product-media"
|
import { MediaType } from "../../../../models/product-media"
|
||||||
|
|||||||
Reference in New Issue
Block a user