Skip to content

Commit

Permalink
default variant + correct shopify variant
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkevingreen committed Sep 12, 2023
1 parent 235125c commit 4e1a3e9
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions app/components/sharable/productGrid.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@ import {

const ProductCard = ({
product,
defaultVariant,
shopify
}) => {
const [activeVariant, setActiveVariant] = useState(shopify?.variants?.nodes[0])
console.log('first variant', product.store.variants[0], activeVariant)
const shopifyDefaultVariant = shopify.variants.nodes.find(item => {
return item.id === defaultVariant.store.gid
})
const [activeVariant, setActiveVariant] = useState(shopifyDefaultVariant ? shopifyDefaultVariant : shopify?.variants?.nodes[0])
console.log('active variant', activeVariant)
return (
<div className='col-span-1'>
<div className='aspect-square bg-primary-green/60' />
Expand All @@ -30,7 +34,12 @@ const ProductCard = ({
backgroundSize: 'cover',
backgroundColor: variant.pattern?.colorType?.color,
}}
onClick={() => setActiveVariant(shopify.variants.nodes[i])}
onClick={() => {
const shopifyVariant = shopify.variants.nodes.find(item => {
return item.id === variant.store.gid
})
setActiveVariant(shopifyVariant)
}}
aria-label={`${variant.pattern.colorName}`}
className={cx('block w-10 h-10 mr-2 rounded-full border-black', {
'opacity-100': activeVariant.id === variant.store.gid,
Expand Down Expand Up @@ -70,6 +79,7 @@ export const ProductGrid = ({
<ProductCard
product={item.product}
shopify={item.shopify}
defaultVariant={item.productVariant}
key={item._key} />
)
})}
Expand Down

0 comments on commit 4e1a3e9

Please sign in to comment.