43 lines
965 B
TypeScript
43 lines
965 B
TypeScript
import { writable, derived } from 'svelte/store'
|
|
|
|
|
|
/**
|
|
* Shop
|
|
*/
|
|
export const shopLocations = writable([])
|
|
|
|
|
|
|
|
/**
|
|
* Cart
|
|
*/
|
|
/** Cart open state */
|
|
export const cartOpen = writable(false)
|
|
|
|
/** Cart open state */
|
|
export const cartId = writable(null)
|
|
|
|
// Write to localStorage when changing cartId
|
|
if (typeof localStorage !== 'undefined') {
|
|
if (localStorage.getItem('cartId')) {
|
|
// console.log('existant', localStorage.getItem('cartId'))
|
|
cartId.set(localStorage.getItem('cartId'))
|
|
}
|
|
cartId.subscribe(value => localStorage.setItem('cartId', value))
|
|
}
|
|
|
|
/** Raw Cart data */
|
|
export const cartData = writable(null)
|
|
|
|
/** Cart data is being updated */
|
|
export const cartIsUpdating = writable(false)
|
|
|
|
/** Amount of products present in cart */
|
|
export const cartAmount = derived(cartData, ($cart) => {
|
|
return $cart && $cart.item_quantity > 0 ? $cart.item_quantity : 0
|
|
})
|
|
|
|
/**
|
|
* Notifications
|
|
*/
|
|
export const cartNotifications = writable([]) |