Skip to content

Commit

Permalink
Make sure the ConfigurableProductPagePrice only works for a Configura…
Browse files Browse the repository at this point in the history
…bleProduct.
  • Loading branch information
paales committed Apr 17, 2024
1 parent fa3bad7 commit 59c8253
Showing 1 changed file with 9 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
AddToCartItemSelector,
ProductPagePriceFragment,
type ProductPagePrice,
} from '@graphcommerce/magento-product'
import { AddToCartItemSelector, type ProductPagePrice } from '@graphcommerce/magento-product'
import type { ReactPlugin } from '@graphcommerce/next-config'
import { useConfigurableSelectedVariant } from '../../hooks'

Expand All @@ -16,12 +12,15 @@ const ConfigurableProductPagePrice: PluginType = (props) => {
const { Prev, product, index, ...rest } = props
const variant = useConfigurableSelectedVariant({ url_key: product.url_key, index })

if (product.__typename === 'GroupedProduct') return <Prev {...props} />
const finalProduct: ProductPagePriceFragment = variant
? { ...variant, options: product.options }
: product
if (product.__typename !== 'ConfigurableProduct') return <Prev {...props} />

return <Prev product={finalProduct} index={index} {...rest} />
return (
<Prev
product={variant ? { ...variant, options: product.options } : product}
index={index}
{...rest}
/>
)
}

export const Plugin = ConfigurableProductPagePrice

0 comments on commit 59c8253

Please sign in to comment.