mirror of
https://github.com/vercel/commerce.git
synced 2025-05-13 21:27:50 +00:00
Added compareAtPrice feature
This commit is contained in:
parent
e3dee2c904
commit
5c3a508826
@ -5,16 +5,24 @@ import { Product } from 'lib/shopify/types';
|
||||
import { VariantSelector } from './variant-selector';
|
||||
|
||||
export function ProductDescription({ product }: { product: Product }) {
|
||||
const compareAtPrice = product.compareAtPriceRange.maxVariantPrice.amount;
|
||||
const price = product.priceRange.maxVariantPrice.amount;
|
||||
|
||||
return (
|
||||
<>
|
||||
<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>
|
||||
<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
|
||||
amount={product.priceRange.maxVariantPrice.amount}
|
||||
amount={compareAtPrice}
|
||||
currencyCode={product.priceRange.maxVariantPrice.currencyCode}
|
||||
/>
|
||||
</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>
|
||||
<VariantSelector options={product.options} variants={product.variants} />
|
||||
|
||||
|
@ -24,6 +24,16 @@ const productFragment = /* GraphQL */ `
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
compareAtPriceRange {
|
||||
maxVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
minVariantPrice {
|
||||
amount
|
||||
currencyCode
|
||||
}
|
||||
}
|
||||
variants(first: 250) {
|
||||
edges {
|
||||
node {
|
||||
|
@ -120,6 +120,10 @@ export type ShopifyProduct = {
|
||||
maxVariantPrice: Money;
|
||||
minVariantPrice: Money;
|
||||
};
|
||||
compareAtPriceRange: {
|
||||
maxVariantPrice: Money;
|
||||
minVariantPrice: Money;
|
||||
};
|
||||
variants: Connection<ProductVariant>;
|
||||
featuredImage: Image;
|
||||
images: Connection<Image>;
|
||||
|
Loading…
x
Reference in New Issue
Block a user