Added compareAtPrice feature

This commit is contained in:
Ron Dopaz 2023-12-02 00:58:37 +02:00
parent e3dee2c904
commit 5c3a508826
3 changed files with 26 additions and 4 deletions

View File

@ -5,16 +5,24 @@ import { Product } from 'lib/shopify/types';
import { VariantSelector } from './variant-selector'; import { VariantSelector } from './variant-selector';
export function ProductDescription({ product }: { product: Product }) { export function ProductDescription({ product }: { product: Product }) {
const compareAtPrice = product.compareAtPriceRange.maxVariantPrice.amount;
const price = product.priceRange.maxVariantPrice.amount;
return ( return (
<> <>
<div className="mb-6 flex flex-col border-b pb-6 dark:border-neutral-700"> <div className="mb-6 flex flex-col border-b pb-6 dark:border-neutral-700">
<h1 className="mb-2 text-5xl font-medium">{product.title}</h1> <h1 className="mb-2 text-5xl font-medium">{product.title}</h1>
<div className="mr-auto w-auto rounded-full bg-blue-600 p-2 text-sm text-white"> {parseFloat(compareAtPrice) > parseFloat(price) && (
<div className="mr-auto w-auto p-2 text-sm text-white line-through decoration-red-500">
<Price <Price
amount={product.priceRange.maxVariantPrice.amount} amount={compareAtPrice}
currencyCode={product.priceRange.maxVariantPrice.currencyCode} currencyCode={product.priceRange.maxVariantPrice.currencyCode}
/> />
</div> </div>
)}
<div className="mr-auto w-auto rounded-full bg-blue-600 p-2 text-sm text-white">
<Price amount={price} currencyCode={product.priceRange.maxVariantPrice.currencyCode} />
</div>
</div> </div>
<VariantSelector options={product.options} variants={product.variants} /> <VariantSelector options={product.options} variants={product.variants} />

View File

@ -24,6 +24,16 @@ const productFragment = /* GraphQL */ `
currencyCode currencyCode
} }
} }
compareAtPriceRange {
maxVariantPrice {
amount
currencyCode
}
minVariantPrice {
amount
currencyCode
}
}
variants(first: 250) { variants(first: 250) {
edges { edges {
node { node {

View File

@ -120,6 +120,10 @@ export type ShopifyProduct = {
maxVariantPrice: Money; maxVariantPrice: Money;
minVariantPrice: Money; minVariantPrice: Money;
}; };
compareAtPriceRange: {
maxVariantPrice: Money;
minVariantPrice: Money;
};
variants: Connection<ProductVariant>; variants: Connection<ProductVariant>;
featuredImage: Image; featuredImage: Image;
images: Connection<Image>; images: Connection<Image>;