Allow a product variant to have a different price

This commit is contained in:
royderks 2021-05-18 15:43:02 +02:00
parent d838f34c73
commit 4ac140ffbd
2 changed files with 9 additions and 7 deletions

View File

@ -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 {

View File

@ -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 {