feat: /store api product types (#2552)
## What Allow users to fetch ProductTypes from the storefront API. ## Why This endpoint will allow developers to implement better faceted product search in Medusa without the need for search plugin. Developers will be able to use this to render refinement lists based on types, like this:  ## How Endpoint `GET /store/products/types` and `GET /store/product-types` (use [product types listing in admin](https://github.com/medusajs/medusa/blob/master/packages/medusa/src/api/routes/admin/products/list-types.ts) as reference) Support added in @medusajs/medusa-js Support added in medusa-react ## Testing Similar automated tests as `GET /admin/products/types` and `GET /admin/product-types` --- Resolves CORE-699
This commit is contained in:
@@ -10,6 +10,7 @@ import OrdersResource from "./resources/orders"
|
||||
import OrderEditsResource from "./resources/order-edits"
|
||||
import PaymentMethodsResource from "./resources/payment-methods"
|
||||
import ProductsResource from "./resources/products"
|
||||
import ProductTypesResource from "./resources/product-types"
|
||||
import RegionsResource from "./resources/regions"
|
||||
import ReturnReasonsResource from "./resources/return-reasons"
|
||||
import ReturnsResource from "./resources/returns"
|
||||
@@ -27,6 +28,7 @@ class Medusa {
|
||||
public orders: OrdersResource
|
||||
public orderEdits: OrderEditsResource
|
||||
public products: ProductsResource
|
||||
public productTypes: ProductTypesResource
|
||||
public regions: RegionsResource
|
||||
public returnReasons: ReturnReasonsResource
|
||||
public returns: ReturnsResource
|
||||
@@ -48,6 +50,7 @@ class Medusa {
|
||||
this.orders = new OrdersResource(this.client)
|
||||
this.orderEdits = new OrderEditsResource(this.client)
|
||||
this.products = new ProductsResource(this.client)
|
||||
this.productTypes = new ProductTypesResource(this.client)
|
||||
this.regions = new RegionsResource(this.client)
|
||||
this.returnReasons = new ReturnReasonsResource(this.client)
|
||||
this.returns = new ReturnsResource(this.client)
|
||||
|
||||
@@ -8,16 +8,17 @@ import BaseResource from "../base"
|
||||
|
||||
class AdminProductTypesResource extends BaseResource {
|
||||
list(
|
||||
query?: AdminGetProductTypesParams
|
||||
query?: AdminGetProductTypesParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductTypesListRes> {
|
||||
let path = `/admin/product-types`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path = `/admin/product-types?${queryString}`
|
||||
path += `?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path)
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,9 @@ class AdminProductsResource extends BaseResource {
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link AdminProductTypesResource.list} instead.
|
||||
*/
|
||||
listTypes(
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<AdminProductsListTypesRes> {
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import {
|
||||
StoreGetProductTypesParams,
|
||||
StoreProductTypesListRes,
|
||||
} from "@medusajs/medusa"
|
||||
import qs from "qs"
|
||||
import { ResponsePromise } from "../typings"
|
||||
import BaseResource from "./base"
|
||||
|
||||
class ProductTypesResource extends BaseResource {
|
||||
/**
|
||||
* @description Retrieves a list of product types
|
||||
* @param {StoreGetProductTypesParams} query is optional. Can contain a limit and offset for the returned list
|
||||
* @param customHeaders
|
||||
* @return {ResponsePromise<StoreProductTypesListRes>}
|
||||
*/
|
||||
list(
|
||||
query?: StoreGetProductTypesParams,
|
||||
customHeaders: Record<string, any> = {}
|
||||
): ResponsePromise<StoreProductTypesListRes> {
|
||||
let path = `/store/product-types`
|
||||
|
||||
if (query) {
|
||||
const queryString = qs.stringify(query)
|
||||
path += `?${queryString}`
|
||||
}
|
||||
|
||||
return this.client.request("GET", path, undefined, {}, customHeaders)
|
||||
}
|
||||
}
|
||||
|
||||
export default ProductTypesResource
|
||||
Reference in New Issue
Block a user