fix: Wishlist flow

This commit is contained in:
Alessandro Casazza 2021-12-20 12:09:30 +01:00
parent 5ce768866d
commit 6c060582ec
No known key found for this signature in database
GPG Key ID: 3AF41B06C6495D3D
3 changed files with 6 additions and 5 deletions

View File

@ -6,11 +6,11 @@ export function emptyHook() {
const localWishlist = localStorage.getItem('wishlist')
if (localWishlist) {
wishlist = JSON.parse(localWishlist)
if (!wishlist.includes(options.variantId)) {
wishlist.push(options.variantId)
if (!wishlist.includes(options.productId)) {
wishlist.push(options.productId)
}
} else {
wishlist.push(options.variantId)
wishlist.push(options.productId)
}
localStorage.setItem('wishlist', JSON.stringify(wishlist))
return wishlist

View File

@ -11,7 +11,7 @@ export function emptyHook(options?: Options) {
wishlist = wishlist.filter((p: string) => p !== id)
}
localStorage.setItem('wishlist', JSON.stringify(wishlist))
return Promise.resolve()
return wishlist
}
return useEmptyHook

View File

@ -41,8 +41,9 @@ export function extendHook(
const wishlist = JSON.parse(getWishlist)
const items = wishlist.map((wishlist: string) => {
const [product] = data.products.filter((p) => p.id === wishlist) as any
const [variant] = product.variants
return {
variant_id: wishlist,
variant_id: variant.id,
product_id: wishlist,
id: wishlist,
product,