mirror of
https://github.com/vercel/commerce.git
synced 2025-05-20 16:36:59 +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 {
|
export interface ProductVariant {
|
||||||
|
listPrice: number | undefined
|
||||||
/**
|
/**
|
||||||
* The unique identifier for the variant.
|
* The unique identifier for the variant.
|
||||||
*/
|
*/
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Stack, Text } from '@chakra-ui/react'
|
||||||
import cn from 'clsx'
|
import cn from 'clsx'
|
||||||
import s from './ProductTag.module.css'
|
import s from './ProductTag.module.css'
|
||||||
|
|
||||||
@ -5,12 +6,14 @@ interface ProductTagProps {
|
|||||||
className?: string
|
className?: string
|
||||||
name: string
|
name: string
|
||||||
price: string
|
price: string
|
||||||
|
listPrice: string
|
||||||
fontSize?: number
|
fontSize?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
const ProductTag: React.FC<ProductTagProps> = ({
|
const ProductTag: React.FC<ProductTagProps> = ({
|
||||||
name,
|
name,
|
||||||
price,
|
price,
|
||||||
|
listPrice,
|
||||||
className = '',
|
className = '',
|
||||||
fontSize = 32,
|
fontSize = 32,
|
||||||
}) => {
|
}) => {
|
||||||
@ -27,7 +30,16 @@ const ProductTag: React.FC<ProductTagProps> = ({
|
|||||||
{name}
|
{name}
|
||||||
</span>
|
</span>
|
||||||
</h3>
|
</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>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -28,6 +28,11 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
|
|||||||
currencyCode: product.price.currencyCode!,
|
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
|
const model3dPath = product.media
|
||||||
.map((media) => {
|
.map((media) => {
|
||||||
return media.sources
|
return media.sources
|
||||||
@ -52,7 +57,8 @@ const ProductView: FC<ProductViewProps> = ({ product, relatedProducts }) => {
|
|||||||
<div className={cn(s.main, 'fit')}>
|
<div className={cn(s.main, 'fit')}>
|
||||||
<ProductTag
|
<ProductTag
|
||||||
name={product.name}
|
name={product.name}
|
||||||
price={`${price} ${product.price?.currencyCode}`}
|
price={`${price}`}
|
||||||
|
listPrice={listPrice.includes("-") ? "" : listPrice}
|
||||||
fontSize={28}
|
fontSize={28}
|
||||||
/>
|
/>
|
||||||
<div className={s.sliderContainer}>
|
<div className={s.sliderContainer}>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user