import Link from 'next/link';
import Image from 'next/image';
import { getCollectionProducts } from 'lib/shopify';
const formatPrice = ({ amount, currencyCode }) => {
const USDollar = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: currencyCode,
});
return USDollar.format(amount);
};
const formatPriceRange = ({ maxVariantPrice, minVariantPrice }) => {
if (maxVariantPrice.amount == minVariantPrice.amount) {
return `${formatPrice(maxVariantPrice)}`;
} else {
return `${formatPrice(minVariantPrice)} - ${formatPrice(
maxVariantPrice
)}`;
}
};
export async function HomeProduct({ product }) {
const featuredImage = product?.images?.[0];
const collections = product?.collections?.nodes;
return (
{product?.title}
{collections && collections.length > 0 && ({`(${collections ?.map(collection => collection?.title) .join(', ')})`}
)} {product?.availableForSale ? ( (product?.priceRange?.maxVariantPrice?.amount ?? 0) > 0 && ({formatPriceRange(product.priceRange)}
) ) : (Sold Out
)} ); } export default async function HomePage() { const collection = process.env.HOMEPAGE_COLLECTION; const products = await getCollectionProducts({ collection, }); console.log({ collection, products }); // console.log({ price: products[0].priceRange, tile: products[0].title }); return ( <> {products.length === 0 ? ({`No products found`}
) : (