From 9bbd7feed083d5bd7a055dd665a78f4c905f9000 Mon Sep 17 00:00:00 2001 From: Belen Curcio Date: Mon, 11 Jan 2021 15:03:04 -0300 Subject: [PATCH] Restored Add to cart --- components/product/ProductView/ProductView.tsx | 12 +++--------- components/product/Swatch/Swatch.tsx | 2 +- framework/bigcommerce/lib/normalize.ts | 4 +++- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/components/product/ProductView/ProductView.tsx b/components/product/ProductView/ProductView.tsx index 290af8b68..2c8a456d9 100644 --- a/components/product/ProductView/ProductView.tsx +++ b/components/product/ProductView/ProductView.tsx @@ -11,11 +11,7 @@ import { Button, Container, Text } from '@components/ui' import usePrice from '@framework/product/use-price' import { useAddItem } from '@framework/cart' -import { - getCurrentVariant, - getProductOptions, - SelectedOptions, -} from '../helpers' +import { getCurrentVariant, SelectedOptions } from '../helpers' import WishlistButton from '@components/wishlist/WishlistButton' interface Props { @@ -41,13 +37,13 @@ const ProductView: FC = ({ product }) => { }) // const variant = getCurrentVariant(product, choices) || product.variants[0] - + console.log('PRODUCT VIEW', product) const addToCart = async () => { setLoading(true) try { await addItem({ productId: Number(product.id), - variantId: Number(product.variants[0].id), + variantId: Number(product.variants[0].id), // TODO(bc) send the correct variant }) openSidebar() setLoading(false) @@ -113,7 +109,6 @@ const ProductView: FC = ({ product }) => {
{opt.values.map((v, i: number) => { const active = (choices as any)[opt.displayName] - return ( = ({ product }) => { className={s.button} onClick={addToCart} loading={loading} - // disabled={!variant} > Add to Cart diff --git a/components/product/Swatch/Swatch.tsx b/components/product/Swatch/Swatch.tsx index 30c9be7c3..34244321f 100644 --- a/components/product/Swatch/Swatch.tsx +++ b/components/product/Swatch/Swatch.tsx @@ -13,7 +13,7 @@ interface Props { color?: string } -const Swatch: FC = ({ +const Swatch: FC & Props> = ({ className, color = '', label, diff --git a/framework/bigcommerce/lib/normalize.ts b/framework/bigcommerce/lib/normalize.ts index a2be86478..ad6302c2e 100644 --- a/framework/bigcommerce/lib/normalize.ts +++ b/framework/bigcommerce/lib/normalize.ts @@ -8,11 +8,13 @@ export function normalizeProduct(productNode: BCProduct): Product { productOptions, prices, path, - options: _, + id: _, + options: _0, ...rest } = productNode return { + id, path, slug: path?.replace(/^\/+|\/+$/g, ''), images: images.edges