From 8766b16e3b482c6b7409aafd74a8299eb07f818c Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Tue, 18 Apr 2023 13:20:15 +0300 Subject: [PATCH] docs: added manage products documentation (#3867) * docs: added manage products documentation * lint fixes * generated oas types --- .../backend/prepare-environment.mdx | 19 - .../products/admin/manage-products.mdx | 1169 +++++++++++++++++ docs/content/modules/products/overview.mdx | 14 +- ...inPostProductsProductVariantsVariantReq.ts | 2 +- .../api/routes/admin/products/add-option.ts | 2 +- .../routes/admin/products/delete-option.ts | 2 +- .../routes/admin/products/update-variant.ts | 2 - www/docs/sidebars.js | 56 +- 8 files changed, 1189 insertions(+), 77 deletions(-) create mode 100644 docs/content/modules/products/admin/manage-products.mdx diff --git a/docs/content/development/backend/prepare-environment.mdx b/docs/content/development/backend/prepare-environment.mdx index be696beb34..9c78534b34 100644 --- a/docs/content/development/backend/prepare-environment.mdx +++ b/docs/content/development/backend/prepare-environment.mdx @@ -191,25 +191,6 @@ For other distributions, you can check out [PostgreSQL’s website for more guid You can download PostgreSQL on your macOS using [the installer on their website](https://www.postgresql.org/download/macosx/). - - - -Make sure the Docker Desktop app is running, then run the following command to quickly spin up a PostgreSQL instance: - -```bash -docker run --name postgres -e POSTGRES_USER=postgres \ - -e POSTGRES_PASSWORD=postgres -e \ - POSTGRES_DB=medusa-docker -p 5432:5432 -d postgres -``` - -Where: - -- `--name` creates a new container named `postgres`. -- `-e` creates environment variables `POSTGRES_USER`, `POSTGRES_PASSWORD` and `POSTGRES_DB`. These will be used to set up a database named `medusa-docker` with the username and password being `postgres`. -- `-p` maps the container port `5432` to the external host `5432`. This allows you to connect to the database backend from outside of the container. -- `-d` enables Docker to run the container in the background. -- The last section of the command, `postgres` grabs the latest postgres image from the Docker hub. - diff --git a/docs/content/modules/products/admin/manage-products.mdx b/docs/content/modules/products/admin/manage-products.mdx new file mode 100644 index 0000000000..c399c3b740 --- /dev/null +++ b/docs/content/modules/products/admin/manage-products.mdx @@ -0,0 +1,1169 @@ +--- +description: 'Learn how to manage products using the admin APIs. Learn how to create, update, and delete products, and how to manage their options and variants.' +addHowToData: true +--- + +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +# How to Manage Products + +In this document, you’ll learn how to manage products using the admin APIs. + +## Overview + +Using the admin APIs, you can manage products, their options, and their variants. + +### Scenario + +You want to add or use the following admin functionalities: + +- Manage products. This includes listing, adding, updating, and deleting products. +- Manage product options. This includes adding, updating, or deleting options. +- Manage product variants. This includes listing, adding, updating, or deleting variants. + +--- + +## Prerequisites + +### Medusa Components + +It is assumed that you already have a Medusa backend installed and set up. If not, you can follow the [quickstart guide](../../../development/backend/install.mdx) to get started. + +### JS Client + +This guide includes code snippets to send requests to your Medusa backend using Medusa’s JS Client, among other methods. + +If you follow the JS Client code blocks, it’s assumed you already have [Medusa’s JS Client](../../../js-client/overview.md) installed and have [created an instance of the client](../../../js-client/overview.md#configuration). + +### Medusa React + +This guide also includes code snippets to send requests to your Medusa backend using Medusa React, among other methods. + +If you follow the Medusa React code blocks, it's assumed you already have [Medusa React installed](../../../medusa-react/overview.md) and have [used MedusaProvider higher in your component tree](../../../medusa-react/overview.md#usage). + +### Authenticated Admin User + +You must be an authenticated admin user before following along with the steps in the tutorial. + +You can learn more about [authenticating as an admin user in the API reference](/api/admin/#section/Authentication). + +--- + +## List Products + +You can list products as an admin using the [List Products endpoint](/api/admin#tag/Products/operation/GetProducts): + + + + +```ts +medusa.admin.products.list() +.then(({ products, limit, offset, count }) => { + console.log(products.length) +}) +``` + + + + +```tsx +import { useAdminProducts } from "medusa-react" + +const Products = () => { + const { products, isLoading } = useAdminProducts() + + return ( +
+ {isLoading && Loading...} + {products && !products.length && No Products} + {products && products.length > 0 && ( +
    + {products.map((product) => ( +
  • {product.title}
  • + ))} +
+ )} +
+ ) +} + +export default Products +``` + +
+ + +```ts +fetch(`/admin/products`, { + credentials: "include", +}) +.then((response) => response.json()) +.then(({ products, limit, offset, count }) => { + console.log(products.length) +}) +``` + + + + +```bash +curl -L -X GET '/admin/products' \ +-H 'Authorization: Bearer ' +``` + + +
+ +This endpoint does not require any parameters. You can pass parameters to search and filter through the retrieved products. For example, you can pass the `q` parameter which searches through product titles, descriptions, and more. You can learn more about available parameters in the [API reference](/api/admin#tag/Products/operation/GetProducts). + +You can also specify which fields to returns or which relations to expand using the `fields` and `expand` query parameters. You can learn more about them in the [API reference](/api/admin#section/Expanding-Fields). + +The request returns an array of products along with [pagination parameters](/api/admin#section/Pagination). + +--- + +## Create a Product + +You can create a product by sending a request to the [Create a Product endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProducts): + + + + +```ts +medusa.admin.products.create({ + title: "Shirt", + is_giftcard: false, + discountable: true, + options: [ + { + title: "Color", + }, + { + title: "Size", + }, + ], + variants: [ + { + title: "White Small Shirt", + prices: [ + { + amount: 1000, + currency_code, + }, + ], + options: [ + { + value: "White", + }, + { + value: "Small", + }, + ], + }, + ], + collection_id, + categories: [ + { + id: categoryId, + }, + ], + type: { + value: typeValue, + }, + tags: [ + { + value: tagValue, + }, + ], +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminCreateProduct } from "medusa-react" + +const CreateProduct = () => { + const createProduct = useAdminCreateProduct() + // ... + + const handleCreate = () => { + createProduct.mutate({ + title: "Shirt", + is_giftcard: false, + discountable: true, + options: [ + { + title: "Color", + }, + { + title: "Size", + }, + ], + variants: [ + { + title: "White Small Shirt", + prices: [ + { + amount: 1000, + currency_code, + }, + ], + options: [ + { + value: "White", + }, + { + value: "Small", + }, + ], + }, + ], + collection_id, + categories: [ + { + id: categoryId, + }, + ], + type: { + value: typeValue, + }, + tags: [ + { + value: tagValue, + }, + ], + }) + } + + // ... +} + +export default CreateProduct +``` + + + + +```ts +fetch(`/admin/products`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "Shirt", + options: [ + { + title: "Color", + }, + { + title: "Size", + }, + ], + variants: [ + { + title: "White Small Shirt", + prices: [ + { + amount: 1000, + currency_code, + }, + ], + options: [ + { + value: "White", + }, + { + value: "Small", + }, + ], + }, + ], + collection_id, + categories: [ + { + id: categoryId, + }, + ], + type: { + value: typeValue, + }, + tags: [ + { + value: tagValue, + }, + ], + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products' \ +-H 'Authorization: Bearer ' \ +-H 'Content-Type: application/json' \ +--data-raw '{ + "title": "Shirt 2", + "options": [ + { + "title": "Color" + }, + { + "title": "Size" + } + ], + "variants": [ + { + "title": "White Shirt", + "prices": [ + { + "amount": 1000, + "currency_code": "USD" + } + ], + "options": [ + { + "value": "White" + }, + { + "value": "Small" + } + ] + } + ], + + "collection_id": "", + "categories": [ + { + "id": "" + } + ], + "type": { + "value": "" + }, + "tags": [ + { + "value": "" + } + ] +}' +``` + + + + +This endpoint only requires the `title` body parameter, which is the name of the product. Other parameters passed in the example are optional. They are: + +- `is_giftcard`: a boolean value that determines whether a product is a gift card. By default, it’s `false`. +- `is_discountable`: a boolean value that determines whether discounts can be applied on the product. By default, it’s `true`. +- `options`: an array of objects, each object has the required property `title`. This only defines the option names and not their values, as their values are defined within the product variant. The array length must be the same as that of the values passed for each variant. +- `variants`: an array of objects, each object has the required properties `title` and `prices`: + - `title` is a string indicating the name of the variant. + - `prices` is an array of objects, each indicating the different prices of the product variant. You can specify prices for different contexts, such as a price for different currencies or regions. You can learn more about possible properties to pass in a price object in the API reference. + - `options` is an array of objects, each object requires the `value` property. `value` is a string indicating the value of the option. Each object within this array is matched with the object of the product’s `options` array at the same index. So, in the example above, the “White” value is matched with the “Color” option, and the “Small” value is matched with the “Size” option. +- `collection_id`: an optional ID of the collection to associate the product with. +- `categories`: an optional array of product category IDs to associate the product with. +- `type`: an optional object that holds a value of the type to associate the product with. If you don’t pass an ID in the object, a new product type will be created. Otherwise, the product will be associated with an existing product type. +- `tags`: an optional array of objects, each object requires the `value` property. If you don’t pass an ID in an object, a new product tag will be created. Otherwise, the product will be associated with an existing product tag. + +You can learn about other available parameters in the [API reference](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProducts). + +The request returns the created product as an object. + +### Product Handle + +If you don’t pass the `handle` body parameter, the handle of the product will be automatically set to the slug version of the `title` parameter. + +### Product Variant Prices + +It’s recommended to set the prices of product variants as the actual amount multiplied by a hundred. This behavior is implemented within the Medusa admin, and the Next.js storefront divides all prices by a hundred before displaying the price. + +So, in the example above, if the `amount` is set to `1000`, it means the price is actually `10`. + +--- + +## Retrieve a Product + +You can retrieve a single product as an admin by sending a request to the [Get a Product endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/GetProductsProduct): + + + + +```ts +medusa.admin.products.retrieve(productId) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminProduct } from "medusa-react" + +const Product = () => { + const { + product, + isLoading, + } = useAdminProduct(productId) + + return ( +
+ {isLoading && Loading...} + {product && {product.title}} + +
+ ) +} + +export default Product +``` + +
+ + +```ts +fetch(`/admin/products/${productId}`, { + credentials: "include", +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X GET '/admin/products/' \ +-H 'Authorization: Bearer ' +``` + + +
+ +This endpoint requires the product ID to be passed as a path parameter. + +The request returns the product as an object. + +--- + +## Update a Product + +You can update a product by sending a request to the [Update Product endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProduct): + + + + +```ts +medusa.admin.products.update(productId, { + title: "Shirt", +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminUpdateProduct } from "medusa-react" + +const UpdateProduct = () => { + const updateProduct = useAdminUpdateProduct( + productId + ) + // ... + + const handleUpdate = () => { + updateProduct.mutate({ + title: "Shirt", + }) + } + + // ... +} + +export default UpdateProduct +``` + + + + +```ts +fetch(`/admin/products/${productId}`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "Shirt", + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products/' \ +-H 'Authorization: Bearer ' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "title": "Shirt" +}' +``` + + + + +This endpoint requires the product ID as a path parameter. In the request’s body, you can pass any of the product’s fields to update. In the example above, you update the `title` of the product. + +You can learn about other body parameters that you can pass in the [API reference](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProduct). + +The request returns the updated product as an object. + +--- + +## Manage Product Options + +In this section, you’ll learn how to manage the options of the product. Although you can already do that through the [Create a Product](#create-a-product) and [Update a Product](#update-a-product) endpoints explained above, you can also use endpoints specific to product options. + +### Retrieve Product Options + +You can retrieve a product’s options by retrieving the product either using the [List Products](#list-products) or the [Retrieve a Product](#retrieve-a-product) endpoints. The options are available under the `options` property. + +### Add a Product Option + +You can add a product option to a product by sending a request to the [Add Product Option endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductOptions): + + + + +```ts +medusa.admin.products.addOption(productId, { + title: "Size", +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminCreateProductOption } from "medusa-react" + +const CreateProductOption = () => { + const createOption = useAdminCreateProductOption( + productId + ) + // ... + + const handleCreate = () => { + createOption.mutate({ + title: "Size", + }) + } + + // ... +} + +export default CreateProductOption +``` + + + + +```ts +fetch(`/admin/products/${productId}/options`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "Size", + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products//options' \ +-H 'Authorization: Bearer ' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "title": "Size" +}' +``` + + + + +This endpoint requires the product’s ID as a path parameter. In the request body parameter, it requires passing the `title` of the option. + +The request returns the updated product as an option. You can view available options under the `options` property of the product. + +### Update a Product Option + +You can update a product option by sending a request to the [Update Product Option endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductOptionsOption): + + + + +```ts +medusa.admin.products.updateOption(productId, optionId, { + title: "Size", +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminUpdateProductOption } from "medusa-react" + +const UpdateProductOption = () => { + const updateOption = useAdminUpdateProductOption( + productId + ) + // ... + + const handleUpdate = () => { + updateOption.mutate({ + option_id, + title: "Size", + }) + } + + // ... +} + +export default UpdateProductOption +``` + + + + + + +```ts +fetch(`/admin/products/${productId}/options/${optionId}`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "Size", + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products//options/' \ +-H 'Authorization: Bearer ' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "title": "Size" +}' +``` + + + + +This endpoint requires the product’s ID and the product option’s ID to be passed as a path parameter. + +In the body parameters, you can update the `title` field of the product option. + +The request returns the updated product as an option. You can view available options under the `options` property of the product. + +### Delete a Product Option + +You can delete a product option by sending a request to the [Delete Product Option endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/DeleteProductsProductOptionsOption): + + + + +```ts +medusa.admin.products.deleteOption(productId, optionId) +.then(({ option_id, object, deleted, product }) => { + console.log(product.options) +}) +``` + + + + +```tsx +import { useAdminDeleteProductOption } from "medusa-react" + +const DeleteProductOption = () => { + const deleteOption = useAdminDeleteProductOption( + productId + ) + // ... + + const handleDelete = () => { + deleteOption.mutate(option_id) + } + + // ... +} + +export default DeleteProductOption +``` + + + + + + +```ts +fetch(`/admin/products/${productId}/options/${optionId}`, { + credentials: "include", + method: "DELETE", +}) +.then((response) => response.json()) +.then(({ option_id, object, deleted, product }) => { + console.log(product.options) +}) +``` + + + + +```bash +curl -L -X DELETE '/admin/products//options/' \ +-H 'Authorization: Bearer ' +``` + + + + +This endpoint requires the product’s ID and the product option’s ID to be passed as a path parameter. + +The request returns the following fields: + +- `option_id`: The ID of the deleted product option. +- `product`: The updated product object. You can access remaining product options under `product.options`. +- `object`: The type of object that was deleted. In this case, the value will be `option`. +- `deleted`: A boolean value indicating whether the option was deleted. + +--- + +## Manage Product Variants + +In this section, you’ll learn how to manage the variants of the product. Although you can already do that through the [Create a Product](#create-a-product) and [Update a Product](#update-a-product) endpoints explained above, you can also use endpoints specific to product variants. + +### Retrieve Product Variants + +You can retrieve a product’s variants by retrieving the product either using the [List Products](#list-products) or the [Retrieve a Product](#retrieve-a-product) endpoints. The product variants are available under the `variants` property. + +### Create Product Variants + +You can create a product variant by sending a request to the [Create Product Variant endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductVariants): + + + + +```ts +medusa.admin.products.createVariant(product_id, { + title: "White Shirt", + prices: [ + { + amount: 1000, + currency_code: "USD", + }, + ], + options: [ + { + option_id, + value: "White", + }, + ], +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminCreateVariant } from "medusa-react" + +const CreateProductVariant = () => { + const createVariant = useAdminCreateVariant( + productId + ) + // ... + + const handleCreate = () => { + createVariant.mutate({ + title: "White Shirt", + prices: [ + { + amount: 1000, + currency_code: "USD", + }, + ], + options: [ + { + option_id, + value: "White", + }, + ], + }) + } + + // ... +} + +export default CreateProductVariant +``` + + + + +```ts +fetch(`/admin/products/${productId}/variants`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "White Shirt", + prices: [ + { + amount: 1000, + currency_code: "USD", + }, + ], + options: [ + { + option_id, + value: "White", + }, + ], + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products//variants' \ +-H 'Authorization: Bearer ' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "title": "White Shirt", + "prices": [ + { + "amount": 1000, + "currency_code": "USD" + } + ], + "options": [ + { + "option_id": "", + "value": "White" + } + ] +}' +``` + + + + +This endpoint requires the ID of the product as a path parameter. In the request body parameters, the following parameters are required: + +- `title`: A string indicating the title of the product variant. +- `prices`: an array of objects, each object indicating the pricing of the variant in different contexts. For example, you can specify different prices for different currencies or regions. You can learn about other accepted properties within price objects in the API reference. You can also learn about formatting the `amount` property in this section. +- `options`: an array of objects, each object indicating a product option. Each object must have the following properties: + - `option_id`: The ID of the product option. + - `value`: A string indicating the value of the product option. + +You can pass other optional parameters as well as indicated in the [API reference](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductVariants). + +The request returns the updated product. You can access the product’s variants under the `variants` property of the product. + +### Update a Product Variant + +You can update a product variant by sending a request to the [Update a Product Variant endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductVariantsVariant): + + + + +```ts +medusa.admin.products.updateVariant(productId, variantId, { + title: "White Shirt", +}) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminUpdateVariant } from "medusa-react" + +const UpdateProductVariant = () => { + const updateVariant = useAdminUpdateVariant( + productId + ) + // ... + + const handleUpdate = () => { + updateVariant.mutate({ + variant_id, + title: "White Shirt", + }) + } + + // ... +} + +export default UpdateProductVariant +``` + + + + + + +```ts +fetch(`/admin/products/${productId}/variants/${variantId}`, { + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, + body: JSON.stringify({ + title: "White Shirt", + }), +}) +.then((response) => response.json()) +.then(({ product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X POST '/admin/products//variants/' \ +-H 'Authorization: Bearer ' \ +--header 'Content-Type: application/json' \ +--data-raw '{ + "title": "White Shirt" +}' +``` + + + + +This endpoint requires the product ID and variant ID to be passed as a path parameter. + +In the request body parameters, you can pass any of the variant’s attributes that you want to update. In the example above, you edit the `title` of the variant. You can refer to the [API reference](https://docs.medusajs.com/api/admin#tag/Products/operation/PostProductsProductVariantsVariant) for other possible parameters. + +The request returns the updated product. You can access the product’s variants under the `variants` property of the product. + +### Delete Product Variant + +You can delete a product variant by sending a request to the [Delete a Product Variant endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/DeleteProductsProductVariantsVariant): + + + + +```ts +medusa.admin.products.deleteVariant(productId, variantId) +.then(({ variant_id, object, deleted, product }) => { + console.log(product.id) +}) +``` + + + + +```tsx +import { useAdminDeleteVariant } from "medusa-react" + +const DeleteProductVariant = () => { + const deleteVariant = useAdminDeleteVariant( + productId + ) + // ... + + const handleDelete = () => { + deleteVariant.mutate(variant_id) + } + + // ... +} + +export default DeleteProductVariant +``` + + + + + + +```ts +fetch(`/admin/products/${productId}/variants/${variantId}`, { + credentials: "include", + method: "DELETE", +}) +.then((response) => response.json()) +.then(({ variant_id, object, deleted, product }) => { + console.log(product.id) +}) +``` + + + + +```bash +curl -L -X DELETE '/admin/products//variants/' \ +-H 'Authorization: Bearer ' +``` + + + + +This endpoint requires the product ID and variant ID to be passed as a path parameter. + +The request returns the following fields: + +- `variant_id`: The ID of the deleted product variant. +- `product`: The updated product object. You can access remaining product variants under `product.variants`. +- `object`: The type of object that was deleted. In this case, the value will be `product-variant`. +- `deleted`: A boolean value indicating whether the variant was deleted. + +--- + +## Delete a Product + +You can delete a product by sending a request to the [Delete a Product endpoint](https://docs.medusajs.com/api/admin#tag/Products/operation/DeleteProductsProduct): + + + + +```ts +medusa.admin.products.delete(productId) +.then(({ id, object, deleted }) => { + console.log(id) +}) +``` + + + + +```tsx +import { useAdminDeleteProduct } from "medusa-react" + +const DeleteProduct = () => { + const deleteProduct = useAdminDeleteProduct( + productId + ) + // ... + + const handleDelete = () => { + deleteProduct.mutate() + } + + // ... +} + +export default DeleteProduct +``` + + + + +```ts +fetch(`/admin/products/${productId}`, { + credentials: "include", + method: "DELETE", +}) +.then((response) => response.json()) +.then(({ id, object, deleted }) => { + console.log(id) +}) +``` + + + + +```bash +curl -L -X DELETE '/admin/products/' \ +-H 'Authorization: Bearer ' +``` + + + + +This endpoint requires passing the product ID as a path parameter. + +The request returns the following fields: + +- `id`: The ID of the deleted product. +- `object`: The type of object that was deleted. In this case, the value will be `product`. +- `deleted`: A boolean value indicating whether the product was deleted. + +--- + +## See Also + +- [How to manage categories](./manage-categories.mdx) +- [How to display products in the storefront](../storefront/show-products.mdx) diff --git a/docs/content/modules/products/overview.mdx b/docs/content/modules/products/overview.mdx index 87f3205c0a..2b98e0c701 100644 --- a/docs/content/modules/products/overview.mdx +++ b/docs/content/modules/products/overview.mdx @@ -24,7 +24,7 @@ Admins can manage unlimited amount of products and their variants. They can mana --- diff --git a/packages/generated/client-types/src/lib/models/AdminPostProductsProductVariantsVariantReq.ts b/packages/generated/client-types/src/lib/models/AdminPostProductsProductVariantsVariantReq.ts index 80bc3be359..37dba2387c 100644 --- a/packages/generated/client-types/src/lib/models/AdminPostProductsProductVariantsVariantReq.ts +++ b/packages/generated/client-types/src/lib/models/AdminPostProductsProductVariantsVariantReq.ts @@ -72,7 +72,7 @@ export interface AdminPostProductsProductVariantsVariantReq { * An optional set of key-value pairs with additional information. */ metadata?: Record - prices: Array<{ + prices?: Array<{ /** * The ID of the price. */ diff --git a/packages/medusa/src/api/routes/admin/products/add-option.ts b/packages/medusa/src/api/routes/admin/products/add-option.ts index 7c0eac66e9..1fe1ed2b30 100644 --- a/packages/medusa/src/api/routes/admin/products/add-option.ts +++ b/packages/medusa/src/api/routes/admin/products/add-option.ts @@ -8,7 +8,7 @@ import { EntityManager } from "typeorm" /** * @oas [post] /admin/products/{id}/options * operationId: "PostProductsProductOptions" - * summary: "Add an Option" + * summary: "Add a Product Option" * x-authenticated: true * description: "Adds a Product Option to a Product" * parameters: diff --git a/packages/medusa/src/api/routes/admin/products/delete-option.ts b/packages/medusa/src/api/routes/admin/products/delete-option.ts index 383ba6ed74..89e452cee8 100644 --- a/packages/medusa/src/api/routes/admin/products/delete-option.ts +++ b/packages/medusa/src/api/routes/admin/products/delete-option.ts @@ -22,7 +22,7 @@ import { ProductService } from "../../../../services" * const medusa = new Medusa({ baseUrl: MEDUSA_BACKEND_URL, maxRetries: 3 }) * // must be previously logged in or use api token * medusa.admin.products.deleteOption(product_id, option_id) - * .then(({ option_id, object, delete, product }) => { + * .then(({ option_id, object, deleted, product }) => { * console.log(product.id); * }); * - lang: Shell diff --git a/packages/medusa/src/api/routes/admin/products/update-variant.ts b/packages/medusa/src/api/routes/admin/products/update-variant.ts index b2135bbce8..c4df7e171e 100644 --- a/packages/medusa/src/api/routes/admin/products/update-variant.ts +++ b/packages/medusa/src/api/routes/admin/products/update-variant.ts @@ -150,8 +150,6 @@ class ProductVariantOptionReq { /** * @schema AdminPostProductsProductVariantsVariantReq * type: object - * required: - * - prices * properties: * title: * description: The title to identify the Product Variant by. diff --git a/www/docs/sidebars.js b/www/docs/sidebars.js index 51925b56a8..6617ce6d4f 100644 --- a/www/docs/sidebars.js +++ b/www/docs/sidebars.js @@ -210,17 +210,18 @@ module.exports = { }, }, }, -{ - type: 'doc', - id: 'deployments/server/deploying-on-microtica', - label: 'Deploy on Microtica', - customProps: { - themedImage: { - light: 'https://res.cloudinary.com/dza7lstvk/image/upload/v1681296578/Medusa%20Docs/Other/aF4ZuDS_t11rcu.png', - dark: 'https://res.cloudinary.com/dza7lstvk/image/upload/v1681296612/Medusa%20Docs/Other/Lg7NHQk_qo6oax.png' - } - } - }, + { + type: "doc", + id: "deployments/server/deploying-on-microtica", + label: "Deploy on Microtica", + customProps: { + themedImage: { + light: + "https://res.cloudinary.com/dza7lstvk/image/upload/v1681296578/Medusa%20Docs/Other/aF4ZuDS_t11rcu.png", + dark: "https://res.cloudinary.com/dza7lstvk/image/upload/v1681296612/Medusa%20Docs/Other/Lg7NHQk_qo6oax.png", + }, + }, + }, { type: "doc", id: "deployments/server/deploying-on-qovery", @@ -597,14 +598,6 @@ module.exports = { id: "modules/products/categories", label: "Categories", }, - { - type: "link", - href: "#", - label: "Collections", - customProps: { - sidebar_is_soon: true, - }, - }, { type: "html", value: "How-to", @@ -613,26 +606,15 @@ module.exports = { }, }, { - type: "link", - href: "#", + type: "doc", + id: "modules/products/admin/manage-products", label: "Admin: Manage Products", - customProps: { - sidebar_is_soon: true, - }, }, { type: "doc", id: "modules/products/admin/manage-categories", label: "Admin: Manage Categories", }, - { - type: "link", - href: "#", - label: "Admin: Manage Collections", - customProps: { - sidebar_is_soon: true, - }, - }, { type: "doc", id: "modules/products/admin/import-products", @@ -648,14 +630,6 @@ module.exports = { id: "modules/products/storefront/use-categories", label: "Storefront: Use Categories", }, - { - type: "link", - href: "#", - label: "Storefront: Show Collections", - customProps: { - sidebar_is_soon: true, - }, - }, ], }, { @@ -2583,4 +2557,4 @@ module.exports = { dirName: "references/entities/classes", }, ], -} \ No newline at end of file +}