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