mirror of
https://github.com/vercel/commerce.git
synced 2025-05-13 13:17:51 +00:00
Added compareAtPrice feature
This commit is contained in:
parent
e3dee2c904
commit
5c3a508826
@ -5,15 +5,23 @@ 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>
|
||||||
|
{parseFloat(compareAtPrice) > parseFloat(price) && (
|
||||||
|
<div className="mr-auto w-auto p-2 text-sm text-white line-through decoration-red-500">
|
||||||
|
<Price
|
||||||
|
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">
|
<div className="mr-auto w-auto rounded-full bg-blue-600 p-2 text-sm text-white">
|
||||||
<Price
|
<Price amount={price} currencyCode={product.priceRange.maxVariantPrice.currencyCode} />
|
||||||
amount={product.priceRange.maxVariantPrice.amount}
|
|
||||||
currencyCode={product.priceRange.maxVariantPrice.currencyCode}
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<VariantSelector options={product.options} variants={product.variants} />
|
<VariantSelector options={product.options} variants={product.variants} />
|
||||||
|
@ -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 {
|
||||||
|
@ -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>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user