From 2393d285973b4d67416058cac3ac70c7b610626f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fe=CC=81lix=20Pe=CC=81ault?= Date: Sun, 18 Sep 2022 12:52:48 +0200 Subject: [PATCH] Fix Shop fetching on server side? --- src/routes/shop/+layout.server.ts | 3 ++- src/routes/shop/+page.server.ts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/routes/shop/+layout.server.ts b/src/routes/shop/+layout.server.ts index 0759a08..ccfbd58 100644 --- a/src/routes/shop/+layout.server.ts +++ b/src/routes/shop/+layout.server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' import { fetchAPI } from '$utils/api' -import { getProducts } from '$utils/functions/shop' +import { initSwell, getProducts } from '$utils/functions/shop' export const load: PageServerLoad = async () => { try { @@ -55,6 +55,7 @@ export const load: PageServerLoad = async () => { /** * Get products data from Swell */ + initSwell() const shopProducts = await getProducts('posters') if (shopProducts) { diff --git a/src/routes/shop/+page.server.ts b/src/routes/shop/+page.server.ts index 85b337b..4e91cb5 100644 --- a/src/routes/shop/+page.server.ts +++ b/src/routes/shop/+page.server.ts @@ -1,7 +1,7 @@ import { error } from '@sveltejs/kit' import type { PageServerLoad } from './$types' import { fetchAPI } from '$utils/api' -import { getProduct } from '$utils/functions/shop' +import { initSwell, getProduct } from '$utils/functions/shop' import { getRandomItem } from '$utils/functions' export const load: PageServerLoad = async ({}) => { @@ -39,6 +39,7 @@ export const load: PageServerLoad = async ({}) => { const randomPoster: any = getRandomItem(data.data.posters) // Fetch Swell API for product + initSwell() const shopProduct = await getProduct(randomPoster.product_id) if (shopProduct) {