4
0
forked from crowetic/commerce

Restored Add to cart

This commit is contained in:
Belen Curcio 2021-01-11 15:03:04 -03:00
parent 4fdaae2197
commit 9bbd7feed0
3 changed files with 7 additions and 11 deletions

View File

@ -11,11 +11,7 @@ import { Button, Container, Text } from '@components/ui'
import usePrice from '@framework/product/use-price' import usePrice from '@framework/product/use-price'
import { useAddItem } from '@framework/cart' import { useAddItem } from '@framework/cart'
import { import { getCurrentVariant, SelectedOptions } from '../helpers'
getCurrentVariant,
getProductOptions,
SelectedOptions,
} from '../helpers'
import WishlistButton from '@components/wishlist/WishlistButton' import WishlistButton from '@components/wishlist/WishlistButton'
interface Props { interface Props {
@ -41,13 +37,13 @@ const ProductView: FC<Props> = ({ product }) => {
}) })
// const variant = getCurrentVariant(product, choices) || product.variants[0] // const variant = getCurrentVariant(product, choices) || product.variants[0]
console.log('PRODUCT VIEW', product)
const addToCart = async () => { const addToCart = async () => {
setLoading(true) setLoading(true)
try { try {
await addItem({ await addItem({
productId: Number(product.id), productId: Number(product.id),
variantId: Number(product.variants[0].id), variantId: Number(product.variants[0].id), // TODO(bc) send the correct variant
}) })
openSidebar() openSidebar()
setLoading(false) setLoading(false)
@ -113,7 +109,6 @@ const ProductView: FC<Props> = ({ product }) => {
<div className="flex flex-row py-4"> <div className="flex flex-row py-4">
{opt.values.map((v, i: number) => { {opt.values.map((v, i: number) => {
const active = (choices as any)[opt.displayName] const active = (choices as any)[opt.displayName]
return ( return (
<Swatch <Swatch
key={`${opt.id}-${i}`} key={`${opt.id}-${i}`}
@ -147,7 +142,6 @@ const ProductView: FC<Props> = ({ product }) => {
className={s.button} className={s.button}
onClick={addToCart} onClick={addToCart}
loading={loading} loading={loading}
// disabled={!variant}
> >
Add to Cart Add to Cart
</Button> </Button>

View File

@ -13,7 +13,7 @@ interface Props {
color?: string color?: string
} }
const Swatch: FC<Props & ButtonProps> = ({ const Swatch: FC<Omit<ButtonProps, 'variant'> & Props> = ({
className, className,
color = '', color = '',
label, label,

View File

@ -8,11 +8,13 @@ export function normalizeProduct(productNode: BCProduct): Product {
productOptions, productOptions,
prices, prices,
path, path,
options: _, id: _,
options: _0,
...rest ...rest
} = productNode } = productNode
return { return {
id,
path, path,
slug: path?.replace(/^\/+|\/+$/g, ''), slug: path?.replace(/^\/+|\/+$/g, ''),
images: images.edges images: images.edges