Add product to cart from anywhere

Make a global function that adds a product to the current cart
This commit is contained in:
2021-11-08 13:00:31 +01:00
parent 571f5d0a6d
commit 378a64f2b0
3 changed files with 13 additions and 34 deletions

View File

@@ -1,7 +1,11 @@
<script lang="ts">
import { cartId } from '$utils/stores/shop'
import { addToCart } from '$utils/functions/shop'
// Components
import Button from '$components/atoms/Button.svelte'
import Image from '$components/atoms/Image.svelte'
export let product: any
export let location: { name: string, slug: string }
export let image: any
</script>
@@ -33,6 +37,7 @@
text="Add to cart"
color="pinklight"
size="xsmall"
on:click={() => addToCart($cartId, product)}
/>
</div>
</div>