diff --git a/src/routes/shop/+layout.server.ts b/src/routes/shop/+layout.server.ts index 82794f6..dcf5958 100644 --- a/src/routes/shop/+layout.server.ts +++ b/src/routes/shop/+layout.server.ts @@ -55,7 +55,9 @@ export const load: PageServerLoad = async () => { /** * Get products data from Swell */ - const shopProducts: any = await fetchSwell('/products') + const shopProducts: any = await fetchSwell('/products', { + category: 'posters', + }) if (shopProducts) { return { diff --git a/src/utils/functions/shopServer.ts b/src/utils/functions/shopServer.ts index 235b00d..e826a22 100644 --- a/src/utils/functions/shopServer.ts +++ b/src/utils/functions/shopServer.ts @@ -7,9 +7,19 @@ import { SWELL_API_TOKEN, SWELL_API_ENDPOINT } from '$env/static/private' * Query data from Swell REST API */ export const fetchSwell = async (path: string, options?: any) => { - const basicAuth: string = base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`) + // Define options + const defaultOptions = { + 'where[active]': true, + limit: 25, + page: 1, + } + options = { ...defaultOptions, ...options } + const parameters = new URLSearchParams(options).toString() - const req = await fetch(`${SWELL_API_ENDPOINT}/${path}`, { + // Make request + const url = `${SWELL_API_ENDPOINT}${path}?${parameters}` + const basicAuth: string = base64.encode(`${PUBLIC_SWELL_STORE_ID}:${SWELL_API_TOKEN}`) + const req = await fetch(url, { headers: { Authorization: `Basic ${basicAuth}` },