mirror of
https://github.com/vercel/commerce.git
synced 2025-05-16 06:26:58 +00:00
Add sale price into product page
This commit is contained in:
parent
bc39d46fa2
commit
bf1a8b6f87
@ -55,6 +55,7 @@ export type ProductMetafield = {
|
||||
}
|
||||
|
||||
export interface ProductVariant {
|
||||
listPrice: number | undefined
|
||||
/**
|
||||
* The unique identifier for the variant.
|
||||
*/
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { Stack, Text } from '@chakra-ui/react'
|
||||
import cn from 'clsx'
|
||||
import s from './ProductTag.module.css'
|
||||
|
||||
@ -5,12 +6,14 @@ interface ProductTagProps {
|
||||
className?: string
|
||||
name: string
|
||||
price: string
|
||||
listPrice: string
|
||||
fontSize?: number
|
||||
}
|
||||
|
||||
const ProductTag: React.FC<ProductTagProps> = ({
|
||||
name,
|
||||
price,
|
||||
listPrice,
|
||||
className = '',
|
||||
fontSize = 32,
|
||||
}) => {
|
||||
@ -27,7 +30,16 @@ const ProductTag: React.FC<ProductTagProps> = ({
|
||||
{name}
|
||||
</span>
|
||||
</h3>
|
||||
<div className={s.price}>{price}</div>
|
||||
<div className={s.price}>
|
||||
<Stack direction={'row'} align={'center'}>
|
||||
<Text fontWeight={800} fontSize={'xl'}>
|
||||
{price}
|
||||
</Text>
|
||||
<Text textDecoration={'line-through'} color={'gray.600'}>
|
||||
{listPrice}
|
||||
</Text>
|
||||
</Stack>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
@ -28,6 +28,11 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
|
||||
currencyCode: product.price.currencyCode!,
|
||||
})
|
||||
|
||||
const listPrice = usePrice({
|
||||
amount: (product.variants[0].listPrice) ? product.variants[0].listPrice : -1,
|
||||
currencyCode: product.price.currencyCode!,
|
||||
}).price
|
||||
|
||||
const model3dPath = product.media
|
||||
.map((media) => {
|
||||
return media.sources
|
||||
@ -52,7 +57,8 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
|
||||
<div className={cn(s.main, 'fit')}>
|
||||
<ProductTag
|
||||
name={product.name}
|
||||
price={`${price} ${product.price?.currencyCode}`}
|
||||
price={`${price}`}
|
||||
listPrice={listPrice.includes("-") ? "" : listPrice}
|
||||
fontSize={28}
|
||||
/>
|
||||
<div className={s.sliderContainer}>
|
||||
|
Loading…
x
Reference in New Issue
Block a user