mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Allow a product variant to have a different price
This commit is contained in:
parent
d838f34c73
commit
4ac140ffbd
@ -19,15 +19,18 @@ interface Props {
|
||||
|
||||
const ProductView: FC<Props> = ({ product }) => {
|
||||
const addItem = useAddItem()
|
||||
const { price } = usePrice({
|
||||
amount: product.price.value,
|
||||
baseAmount: product.price.retailPrice,
|
||||
currencyCode: product.price.currencyCode!,
|
||||
})
|
||||
const { openSidebar } = useUI()
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [choices, setChoices] = useState<SelectedOptions>({})
|
||||
|
||||
const variant = getVariant(product, choices)
|
||||
|
||||
const { price } = usePrice({
|
||||
amount: variant?.price!.value || product.price.value,
|
||||
baseAmount: variant?.price!.retailPrice || product.price.retailPrice,
|
||||
currencyCode: variant?.price!.currencyCode! || product.price.currencyCode!,
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
// Selects the default option
|
||||
product.variants[0].options?.forEach((v) => {
|
||||
@ -38,8 +41,6 @@ const ProductView: FC<Props> = ({ product }) => {
|
||||
})
|
||||
}, [])
|
||||
|
||||
const variant = getVariant(product, choices)
|
||||
|
||||
const addToCart = async () => {
|
||||
setLoading(true)
|
||||
try {
|
||||
|
@ -190,6 +190,7 @@ interface ProductImage {
|
||||
interface ProductVariant2 {
|
||||
id: string | number
|
||||
options: ProductOption[]
|
||||
price?: ProductPrice
|
||||
}
|
||||
|
||||
interface ProductPrice {
|
||||
|
Loading…
x
Reference in New Issue
Block a user