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 className
) )
console.log(process.env.COMMERCE_PROVIDER)
return ( return (
<Link href={`/product/${product.slug}`}> <Link href={`/product/${product.slug}`}>
<a className={rootClassName}> <a className={rootClassName}>

View File

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

View File

@ -36,7 +36,6 @@ const WishlistCard: FC<Props> = ({ product }) => {
const handleRemove = async () => { const handleRemove = async () => {
setRemoving(true) setRemoving(true)
try { try {
// If this action succeeds then there's no need to do `setRemoving(true)` // If this action succeeds then there's no need to do `setRemoving(true)`
// because the component will be removed from the view // 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 useCommerceCart, { UseCart } from '@commerce/cart/use-cart'
import { SWRHook } from '@commerce/utils/types' import { SWRHook } from '@commerce/utils/types'
import getCartQuery from '../utils/queries/get-cart-query'
import { GetCartHook } from '../types/cart' import { GetCartHook } from '../types/cart'
import { import { GetCartQueryVariables, QueryRoot } from '../schema'
GetCartQuery, import { normalizeCart, getCartQuery, setCheckoutUrlCookie } from '../utils'
GetCartQueryVariables,
QueryRoot,
} from '@framework/schema'
import { normalizeCart } from '@framework/utils'
import setCheckoutUrlCookie from '@framework/utils/set-checkout-url-cookie'
export default useCommerceCart as UseCart<typeof handler> export default useCommerceCart as UseCart<typeof handler>

View File

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

View File

@ -7,9 +7,6 @@ export function getError(errors: any[] | null, status: number) {
export async function getAsyncError(res: Response) { export async function getAsyncError(res: Response) {
const data = await res.json() const data = await res.json()
console.log(data)
return getError(data.errors, res.status) 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 handleAccountActivation } from './handle-account-activation'
export { default as throwUserErrors } from './throw-user-errors' export { default as throwUserErrors } from './throw-user-errors'
export { default as getWishlistId } from './get-wisthlist-id' export { default as getWishlistId } from './get-wisthlist-id'
export { default as setCheckoutUrlCookie } from './set-checkout-url-cookie'
export * from './queries' export * from './queries'
export * from './mutations' export * from './mutations'

View File

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