Add sale price into product page

This commit is contained in:
Daniele Pancottini 2023-03-03 14:14:20 +01:00
parent bc39d46fa2
commit bf1a8b6f87
3 changed files with 21 additions and 2 deletions

View File

@ -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.
*/ */

View File

@ -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>
) )
} }

View File

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