From 9feeb87b8bbcc327c6a6c3520a3c0204db0aef8b Mon Sep 17 00:00:00 2001 From: cond0r Date: Tue, 10 Aug 2021 15:49:04 +0300 Subject: [PATCH] Allow guests to add to wishlist --- components/product/ProductCard/ProductCard.tsx | 2 ++ components/wishlist/WishlistButton/WishlistButton.tsx | 3 +-- components/wishlist/WishlistCard/WishlistCard.tsx | 1 - framework/shopify/cart/use-cart.tsx | 10 ++-------- framework/shopify/commerce.config.json | 1 + framework/shopify/utils/handle-fetch-response.ts | 3 --- framework/shopify/utils/index.ts | 1 + framework/shopify/utils/normalize.ts | 1 + 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/components/product/ProductCard/ProductCard.tsx b/components/product/ProductCard/ProductCard.tsx index 95f2f3f07..11bd8d01e 100644 --- a/components/product/ProductCard/ProductCard.tsx +++ b/components/product/ProductCard/ProductCard.tsx @@ -37,6 +37,8 @@ const ProductCard: FC = ({ className ) + console.log(process.env.COMMERCE_PROVIDER) + return ( diff --git a/components/wishlist/WishlistButton/WishlistButton.tsx b/components/wishlist/WishlistButton/WishlistButton.tsx index 4278eb2c3..6805a0fd5 100644 --- a/components/wishlist/WishlistButton/WishlistButton.tsx +++ b/components/wishlist/WishlistButton/WishlistButton.tsx @@ -41,7 +41,7 @@ const WishlistButton: FC = ({ 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 = ({ variantId: variant?.id!, }) } - setLoading(false) } catch (err) { setLoading(false) diff --git a/components/wishlist/WishlistCard/WishlistCard.tsx b/components/wishlist/WishlistCard/WishlistCard.tsx index 7e8719fdf..f54e3e71e 100644 --- a/components/wishlist/WishlistCard/WishlistCard.tsx +++ b/components/wishlist/WishlistCard/WishlistCard.tsx @@ -36,7 +36,6 @@ const WishlistCard: FC = ({ 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 diff --git a/framework/shopify/cart/use-cart.tsx b/framework/shopify/cart/use-cart.tsx index 56c4da811..7b4d5c314 100644 --- a/framework/shopify/cart/use-cart.tsx +++ b/framework/shopify/cart/use-cart.tsx @@ -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 diff --git a/framework/shopify/commerce.config.json b/framework/shopify/commerce.config.json index f84484e09..a54820104 100644 --- a/framework/shopify/commerce.config.json +++ b/framework/shopify/commerce.config.json @@ -2,6 +2,7 @@ "provider": "shopify", "features": { "wishlist": true, + "wishlistForGuests": true, "customerAuth": true, "search": true } diff --git a/framework/shopify/utils/handle-fetch-response.ts b/framework/shopify/utils/handle-fetch-response.ts index 2aece3e1f..91d362d7d 100644 --- a/framework/shopify/utils/handle-fetch-response.ts +++ b/framework/shopify/utils/handle-fetch-response.ts @@ -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) } diff --git a/framework/shopify/utils/index.ts b/framework/shopify/utils/index.ts index bad865470..c23bdbed7 100644 --- a/framework/shopify/utils/index.ts +++ b/framework/shopify/utils/index.ts @@ -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' diff --git a/framework/shopify/utils/normalize.ts b/framework/shopify/utils/normalize.ts index 75638d86f..2e333ba01 100644 --- a/framework/shopify/utils/normalize.ts +++ b/framework/shopify/utils/normalize.ts @@ -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,