docs: fixes to product category how-to and overview (#3702)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2023-04-04 12:33:27 +02:00
1 parent 748833383f
commit 4bb1f833b1
2 files changed
+36 -5

No files matched your search

+2 -3
View File
@@ -34,7 +34,7 @@ Admins can manage unlimited amount of products and their variants. They can mana
{ {
type: 'link', type: 'link',
href: '/user-guide/products/manage', href: '/user-guide/products/manage',
label: 'User Guide: Manage Products', label: 'User Guide: Products',
customProps: { customProps: {
icon: Icons['users-solid'], icon: Icons['users-solid'],
description: 'Manage products in Medusa Admin.' description: 'Manage products in Medusa Admin.'
@@ -66,13 +66,12 @@ Customers can use this organization to filter products while browsing them.
customProps: { customProps: {
icon: Icons['academic-cap-solid'], icon: Icons['academic-cap-solid'],
description: 'Learn how to manage categories using Admin APIs.', description: 'Learn how to manage categories using Admin APIs.',
isSoon: true,
} }
}, },
{ {
type: 'link', type: 'link',
href: '/user-guide/products/categories', href: '/user-guide/products/categories',
label: 'User Guide: Manage Categories', label: 'User Guide: Categories',
customProps: { customProps: {
icon: Icons['users-solid'], icon: Icons['users-solid'],
description: 'Learn how to manage categories in the Medusa Admin.' description: 'Learn how to manage categories in the Medusa Admin.'
@@ -49,6 +49,9 @@ If you follow the Medusa React code blocks, it's assumed you already have [Medus
You can list product categories by sending a request to the [List Product Categories endpoint](/api/store#tag/Product-Category/operation/GetProductCategories): You can list product categories by sending a request to the [List Product Categories endpoint](/api/store#tag/Product-Category/operation/GetProductCategories):
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```ts ```ts
medusa.productCategories.list() medusa.productCategories.list()
.then(({ product_categories, limit, offset, count }) => { .then(({ product_categories, limit, offset, count }) => {
@@ -56,6 +59,9 @@ medusa.productCategories.list()
}) })
``` ```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx ```tsx
import { useProductCategories } from "medusa-react" import { useProductCategories } from "medusa-react"
import { ProductCategory } from "@medusajs/medusa" import { ProductCategory } from "@medusajs/medusa"
@@ -88,8 +94,11 @@ function Categories() {
export default Categories export default Categories
``` ```
</TabItem>
<TabItem value="fetch" label="Fetch API">
```ts ```ts
fetch(`<BACKEND_URL>/product-categories`, { fetch(`<BACKEND_URL>/store/product-categories`, {
credentials: "include", credentials: "include",
}) })
.then((response) => response.json()) .then((response) => response.json())
@@ -98,11 +107,17 @@ fetch(`<BACKEND_URL>/product-categories`, {
}) })
``` ```
</TabItem>
<TabItem value="curl" label="cURL">
```bash ```bash
curl -L -X GET '<BACKEND_URL>/store/product-categories' \ curl -L -X GET '<BACKEND_URL>/store/product-categories' \
-H 'Authorization: Bearer <API_TOKEN>' -H 'Authorization: Bearer <API_TOKEN>'
``` ```
</TabItem>
</Tabs>
This request does not require any query parameters. You can, however, pass query parameters to filter the list of categories, such as the passing the `q` query parameter to search categories by title or handle. You can learn about available query parameters in the [API reference](/api/store#tag/Product-Category/operation/GetProductCategories). This request does not require any query parameters. You can, however, pass query parameters to filter the list of categories, such as the passing the `q` query parameter to search categories by title or handle. You can learn about available query parameters in the [API reference](/api/store#tag/Product-Category/operation/GetProductCategories).
The request returns an array of product categories along with [pagination fields](/api/store#section/Pagination). The request returns an array of product categories along with [pagination fields](/api/store#section/Pagination).
@@ -117,6 +132,9 @@ By default, the categories are not retrieved along with their nested children. T
You can retrieve a single product category by using the [Get a Product Category endpoint](/api/store#tag/Product-Category/operation/GetProductCategoriesCategory): You can retrieve a single product category by using the [Get a Product Category endpoint](/api/store#tag/Product-Category/operation/GetProductCategoriesCategory):
<Tabs groupId="request-type" wrapperClassName="code-tabs">
<TabItem value="client" label="Medusa JS Client" default>
```ts ```ts
medusa.productCategories.retrieve(productCategoryId) medusa.productCategories.retrieve(productCategoryId)
.then(({ product_category }) => { .then(({ product_category }) => {
@@ -124,6 +142,9 @@ medusa.productCategories.retrieve(productCategoryId)
}) })
``` ```
</TabItem>
<TabItem value="medusa-react" label="Medusa React">
```tsx ```tsx
import { useProductCategory } from "medusa-react" import { useProductCategory } from "medusa-react"
@@ -141,8 +162,13 @@ function Category() {
export default Category export default Category
``` ```
</TabItem>
<TabItem value="fetch" label="Fetch API">
<!-- eslint-disable max-len -->
```ts ```ts
fetch(`<BACKEND_URL>/product-categories/${productCategoryId}`, { fetch(`<BACKEND_URL>/store/product-categories/${productCategoryId}`, {
credentials: "include", credentials: "include",
}) })
.then((response) => response.json()) .then((response) => response.json())
@@ -151,11 +177,17 @@ fetch(`<BACKEND_URL>/product-categories/${productCategoryId}`, {
}) })
``` ```
</TabItem>
<TabItem value="curl" label="cURL">
```bash ```bash
curl -L -X GET '<BACKEND_URL>/store/product-categories/<CAT_ID>' \ curl -L -X GET '<BACKEND_URL>/store/product-categories/<CAT_ID>' \
-H 'Authorization: Bearer <API_TOKEN>' -H 'Authorization: Bearer <API_TOKEN>'
``` ```
</TabItem>
</Tabs>
This request requires the product category ID as a path parameter. You can also pass query parameters such as `expand` and `fields` as explained in the [API reference](/api/store#tag/Product-Category/operation/GetProductCategoriesCategory). This request requires the product category ID as a path parameter. You can also pass query parameters such as `expand` and `fields` as explained in the [API reference](/api/store#tag/Product-Category/operation/GetProductCategoriesCategory).
The request returns the category as an object. The request returns the category as an object.