diff --git a/.env.local b/.env.local index 7db2a49..1e4df06 100644 --- a/.env.local +++ b/.env.local @@ -16,6 +16,10 @@ VITE_API_URL_PROD="https://api.housesof.world" VITE_API_GRAPHQL_PATH="/graphql" VITE_API_TOKEN="efa40490-152c-49d7-a75b-30a6427439b1" +# Shop +VITE_SWELL_STORE_ID="houses-of" +VITE_SWELL_API_TOKEN="v3BiXcZP5jpmhL80i4eUy6iXxcpN9cIq" + # Analytics VITE_ANALYTICS_KEY="c01e378821e6ba7bf9a9f947b107500bfcbd4ae8" VITE_ANALYTICS_URL="https://stats.flayks.com" \ No newline at end of file diff --git a/package.json b/package.json index f2596b0..6ed4f1a 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,7 @@ "svelte": "^3.44.1", "svelte-check": "^2.2.8", "svelte-preprocess": "^4.9.8", + "swell-node": "^4.0.6", "tslib": "^2.3.1", "typescript": "^4.4.4" }, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a4b613d..409ad00 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -16,6 +16,7 @@ specifiers: svelte: ^3.44.1 svelte-check: ^2.2.8 svelte-preprocess: ^4.9.8 + swell-node: ^4.0.6 tslib: ^2.3.1 typescript: ^4.4.4 @@ -37,6 +38,7 @@ devDependencies: svelte: 3.44.1 svelte-check: 2.2.8_sass@1.43.4+svelte@3.44.1 svelte-preprocess: 4.9.8_6627cbae993b0086cf4555994e082905 + swell-node: 4.0.6 tslib: 2.3.1 typescript: 4.4.4 @@ -1437,6 +1439,11 @@ packages: engines: {node: '>= 8'} dev: true + /swell-node/4.0.6: + resolution: {integrity: sha512-9eAjxse63TL2J3R7RdyD3VoykSffkY/z4jpIpwqjGUhbJYhpqXwbAive2U+6dvdqxGdjovBM8siTeld2Ud9LVw==} + engines: {node: '>= v12.21.0'} + dev: true + /text-table/0.2.0: resolution: {integrity: sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=} dev: true diff --git a/src/components/layouts/PosterLayout.svelte b/src/components/layouts/PosterLayout.svelte index cc59881..8bca5b6 100644 --- a/src/components/layouts/PosterLayout.svelte +++ b/src/components/layouts/PosterLayout.svelte @@ -4,8 +4,10 @@ import Button from '$components/atoms/Button.svelte' import Image from '$components/atoms/Image.svelte' import Carousel from '$components/organisms/Carousel.svelte' +import { cartData, cartId } from '$utils/store'; export let product: any + export let productShop: any /** @@ -51,6 +53,33 @@ ratio: 0.68, }, ] + + + /** + * Handling add to cart + */ + const addToCart = async () => { + // const addedReturn = await swell.cart.addItem({ + // product_id: product.product_id, + // quantity: 1, + // }) + + const addedReturn = await fetch('/api/swell', { + method: 'POST', + body: JSON.stringify({ + action: 'addToCart', + cartId: $cartId, + productId: product.product_id, + quantity: 1, + }) + }) + + if (addedReturn.ok) { + const newCart = await addedReturn.json() + $cartData = newCart + console.log('Show mini product added to cart') + } + }
@@ -62,11 +91,12 @@
{capitalizeFirstLetter(product.type)}
-
{product.name} – 30€
+
{productShop.name} – {productShop.price}€
diff --git a/src/components/molecules/CartItem.svelte b/src/components/molecules/CartItem.svelte new file mode 100644 index 0000000..a87dd98 --- /dev/null +++ b/src/components/molecules/CartItem.svelte @@ -0,0 +1,49 @@ + + + \ No newline at end of file diff --git a/src/components/molecules/PosterCart.svelte b/src/components/molecules/PosterCart.svelte deleted file mode 100644 index 8140c6d..0000000 --- a/src/components/molecules/PosterCart.svelte +++ /dev/null @@ -1,31 +0,0 @@ - - -