Allow guests to add to wishlist

This commit is contained in:
cond0r 2021-08-10 15:49:04 +03:00
parent bc15597be9
commit 9feeb87b8b
8 changed files with 8 additions and 14 deletions

View File

@ -37,6 +37,8 @@ const ProductCard: FC<Props> = ({
className
)
console.log(process.env.COMMERCE_PROVIDER)
return (
<Link href={`/product/${product.slug}`}>
<a className={rootClassName}>

View File

@ -41,7 +41,7 @@ const WishlistButton: FC<Props> = ({
if (loading) return
// A login is required before adding an item to the wishlist
if (!customer && process.env.COMMERCE_PROVIDER !== 'shopify') {
if (!customer && !process.env.COMMERCE_WISHLISTFORGUESTS_ENABLED) {
setModalView('LOGIN_VIEW')
return openModal()
}
@ -57,7 +57,6 @@ const WishlistButton: FC<Props> = ({
variantId: variant?.id!,
})
}
setLoading(false)
} catch (err) {
setLoading(false)

View File

@ -36,7 +36,6 @@ const WishlistCard: FC<Props> = ({ product }) => {
const handleRemove = async () => {
setRemoving(true)
try {
// If this action succeeds then there's no need to do `setRemoving(true)`
// because the component will be removed from the view

View File

@ -2,15 +2,9 @@ import { useMemo } from 'react'
import useCommerceCart, { UseCart } from '@commerce/cart/use-cart'
import { SWRHook } from '@commerce/utils/types'
import getCartQuery from '../utils/queries/get-cart-query'
import { GetCartHook } from '../types/cart'
import {
GetCartQuery,
GetCartQueryVariables,
QueryRoot,
} from '@framework/schema'
import { normalizeCart } from '@framework/utils'
import setCheckoutUrlCookie from '@framework/utils/set-checkout-url-cookie'
import { GetCartQueryVariables, QueryRoot } from '../schema'
import { normalizeCart, getCartQuery, setCheckoutUrlCookie } from '../utils'
export default useCommerceCart as UseCart<typeof handler>

View File

@ -2,6 +2,7 @@
"provider": "shopify",
"features": {
"wishlist": true,
"wishlistForGuests": true,
"customerAuth": true,
"search": true
}

View File

@ -7,9 +7,6 @@ export function getError(errors: any[] | null, status: number) {
export async function getAsyncError(res: Response) {
const data = await res.json()
console.log(data)
return getError(data.errors, res.status)
}

View File

@ -10,6 +10,7 @@ export { default as handleLogin, handleAutomaticLogin } from './handle-login'
export { default as handleAccountActivation } from './handle-account-activation'
export { default as throwUserErrors } from './throw-user-errors'
export { default as getWishlistId } from './get-wisthlist-id'
export { default as setCheckoutUrlCookie } from './set-checkout-url-cookie'
export * from './queries'
export * from './mutations'

View File

@ -204,6 +204,7 @@ export function normalizeWishlist(
variant?.image?.originalSrc || '/product-img-placeholder.svg',
},
],
id,
variants: variant?.id ? [{ id: variant?.id }] : [],
amount: +variant?.priceV2?.amount,
baseAmount: +variant?.compareAtPriceV2?.amount,