1
1
import medusaRequest from "../medusa-fetch"
2
2
import { StoreGetProductsParams } from "@medusajs/medusa"
3
3
4
- type GetProductListParams = {
5
- pageParam ?: number
6
- queryParams : StoreGetProductsParams
7
- }
8
-
9
4
/**
10
5
* This file contains functions for fetching products and collections from the Medusa API or the Medusa Product Module,
11
6
* depending on the feature flag. By default, the standard Medusa API is used. To use the Medusa Product Module, set the feature flag to true.
@@ -19,7 +14,7 @@ const PRODUCT_MODULE_ENABLED =
19
14
const API_BASE_URL = process . env . NEXT_PUBLIC_BASE_URL || "http://localhost:8000"
20
15
21
16
// Set DEBUG to true to console.log where the data is coming from.
22
- const DEBUG = true
17
+ const DEBUG = false
23
18
24
19
/**
25
20
* Fetches a product by handle, using the Medusa API or the Medusa Product Module, depending on the feature flag.
@@ -64,7 +59,10 @@ export async function getProductByHandle(handle: string) {
64
59
export async function getProductsList ( {
65
60
pageParam = 0 ,
66
61
queryParams,
67
- } : GetProductListParams ) {
62
+ } : {
63
+ pageParam ?: number
64
+ queryParams : StoreGetProductsParams
65
+ } ) {
68
66
const limit = queryParams . limit || 12
69
67
70
68
if ( PRODUCT_MODULE_ENABLED ) {
@@ -157,7 +155,9 @@ export async function getCollectionsList(offset: number = 0) {
157
155
/**
158
156
* Fetches a collection by handle, using the Medusa API or the Medusa Product Module, depending on the feature flag.
159
157
* @param handle (string) - The handle of the collection to retrieve
160
- * @returns (array) - An array of collections (should only be one)
158
+ * @returns collections (array) - An array of collections (should only be one)
159
+ * @returns response (object) - An object containing the products and the number of products in the collection
160
+ * @returns nextPage (number) - The offset of the next page of products
161
161
*/
162
162
export async function getCollectionByHandle ( handle : string ) {
163
163
if ( PRODUCT_MODULE_ENABLED ) {
@@ -185,6 +185,14 @@ export async function getCollectionByHandle(handle: string) {
185
185
return data
186
186
}
187
187
188
+ /**
189
+ * Fetches a list of products in a collection, using the Medusa API or the Medusa Product Module, depending on the feature flag.
190
+ * @param pageParam (number) - The offset of the products to retrieve
191
+ * @param handle (string) - The handle of the collection to retrieve
192
+ * @param cartId (string) - The ID of the cart
193
+ * @returns response (object) - An object containing the products and the number of products in the collection
194
+ * @returns nextPage (number) - The offset of the next page of products
195
+ */
188
196
export async function getProductsByCollectionHandle ( {
189
197
pageParam = 0 ,
190
198
handle,
0 commit comments