diff --git a/components/common/HomeAllProductsGrid/HomeAllProductsGrid.tsx b/components/common/HomeAllProductsGrid/HomeAllProductsGrid.tsx index d292d0d6b..d55f51f7a 100644 --- a/components/common/HomeAllProductsGrid/HomeAllProductsGrid.tsx +++ b/components/common/HomeAllProductsGrid/HomeAllProductsGrid.tsx @@ -8,10 +8,10 @@ import { getCategoryPath, getDesignerPath } from '@lib/search' interface Props { categories?: any brands?: any - newestProducts?: any + products?: Product[] } -const Head: FC = ({ categories, brands, newestProducts }) => { +const Head: FC = ({ categories, brands, products = [] }) => { return (
@@ -48,10 +48,10 @@ const Head: FC = ({ categories, brands, newestProducts }) => {
- {newestProducts.map(({ node }: any) => ( + {products.map((product) => ( = ({ className, product, variant, imgProps }) => { {product.name} - {product.prices[0].value} + {product.price.value}   - {product.prices[0].currencyCode} + {product.price.currencyCode}
= ({ product }) => { const addItem = useAddItem() const { price } = usePrice({ - amount: product.prices?.price?.value, - baseAmount: product.prices?.retailPrice?.value, - currencyCode: product.prices?.price?.currencyCode!, + amount: product.price.value, + baseAmount: product.price.retailValue, + currencyCode: product.price.currencyCode!, }) const { openSidebar } = useUI() const options = getProductOptions(product) @@ -38,15 +38,15 @@ const ProductView: FC = ({ product }) => { size: null, color: null, }) - const variant = - getCurrentVariant(product, choices) || product.variants.edges?.[0] + + const variant = getCurrentVariant(product, choices) || product.variants[0] const addToCart = async () => { setLoading(true) try { await addItem({ - productId: product.entityId, - variantId: product.variants.edges?.[0]?.node.entityId!, + productId: Number(product.id), + variantId: Number(product.variants[0].id), }) openSidebar() setLoading(false) @@ -66,7 +66,7 @@ const ProductView: FC = ({ product }) => { description: product.description, images: [ { - url: product.images.edges?.[0]?.node.urlOriginal!, + url: product.images[0]?.url!, width: 800, height: 600, alt: product.name, @@ -81,18 +81,18 @@ const ProductView: FC = ({ product }) => {
{price} {` `} - {product.prices?.price.currencyCode} + {product.price?.currencyCode}
- - {product.images.edges?.map((image, i) => ( -
+ + {product.images.map((image, i) => ( +
{image?.node.altText = ({ product }) => {
-
diff --git a/framework/bigcommerce/api/operations/get-all-products.ts b/framework/bigcommerce/api/operations/get-all-products.ts index 036602639..7c91c4f1d 100644 --- a/framework/bigcommerce/api/operations/get-all-products.ts +++ b/framework/bigcommerce/api/operations/get-all-products.ts @@ -34,12 +34,10 @@ function productsNormalizer(arr: any[]): Product[] { ), variants: variants.edges.map(({ node }: any) => node), productOptions: productOptions.edges.map(({ node }: any) => node), - prices: [ - { - value: prices.price.value, - currencyCode: prices.price.currencyCode, - }, - ], + price: { + value: prices.price.value, + currencyCode: prices.price.currencyCode, + }, ...rest, }) ) diff --git a/framework/types.d.ts b/framework/types.d.ts index 8958a9a04..87347da7b 100644 --- a/framework/types.d.ts +++ b/framework/types.d.ts @@ -6,7 +6,7 @@ interface Product { path?: string images: ProductImage[] variants: ProductVariant[] - prices: ProductPrice[] + price: ProductPrice } interface ProductImage { url: string @@ -18,9 +18,10 @@ interface ProductVariant { } interface ProductPrice { - value: number | string + value: number currencyCode: 'USD' | 'ARS' - type?: 'price' | 'retail' | 'sale' | string + retailValue?: number + saleValue?: number } interface Cart { diff --git a/pages/index.tsx b/pages/index.tsx index e194366c4..4b76134c7 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -41,7 +41,7 @@ export default function Home({ categories, }: InferGetStaticPropsType) { return ( -
+ <> {products.slice(0, 3).map((product, i) => ( ))} - {/* */} -
+ /> + ) }