✨ Add product to cart from anywhere
Make a global function that adds a product to the current cart
This commit is contained in:
@@ -1,17 +1,18 @@
|
||||
import { addNotification } from '$utils/functions/notifications'
|
||||
import type { Writable } from 'svelte/store'
|
||||
import { cartData } from '$utils/stores/shop'
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Add a product to a cart
|
||||
*/
|
||||
export const addToCart = async (cart: string, cartData: Writable<any>, product: any, quantity: number = 1) => {
|
||||
if (cart && cart !== 'null') {
|
||||
export const addToCart = async (cartId: string, product: any, quantity: number = 1) => {
|
||||
if (cartId && cartId !== 'null') {
|
||||
const updatedCart = await fetch('/api/swell', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({
|
||||
action: 'addToCart',
|
||||
cartId: cart,
|
||||
cartId,
|
||||
productId: product.id,
|
||||
quantity,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user