mirror of
https://github.com/vercel/commerce.git
synced 2025-07-27 04:01:23 +00:00
feat: get blog list
This commit is contained in:
@@ -6,7 +6,9 @@ import { GetStaticPropsContext } from 'next';
|
||||
import { Layout } from 'src/components/common';
|
||||
import { FeaturedProductsCarousel, FreshProducts, HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
|
||||
import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
|
||||
import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED } from 'src/utils/constanst.utils';
|
||||
import { FACET } from 'src/utils/constanst.utils';
|
||||
import { FilterOneVatiant, getFacetIdByName } from 'src/utils/funtion.utils';
|
||||
import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED,COLLECTION_SLUG_SPICE } from 'src/utils/constanst.utils';
|
||||
import { getAllFacetValueIdsByParentCode, getAllFacetValuesForFeatuedProducts, getAllPromies, getFreshFacetId } from 'src/utils/funtion.utils';
|
||||
import { PromiseWithKey } from 'src/utils/types.utils';
|
||||
|
||||
@@ -16,19 +18,23 @@ interface Props {
|
||||
freshProducts: ProductCard[],
|
||||
featuredProducts: ProductCard[],
|
||||
collections: Collection[]
|
||||
spiceProducts:ProductCard[]
|
||||
veggie: ProductCard[],
|
||||
|
||||
}
|
||||
export default function Home({ featuredAndDiscountFacetsValue,
|
||||
export default function Home({ featuredAndDiscountFacetsValue, veggie,
|
||||
freshProducts, featuredProducts,
|
||||
collections }: Props) {
|
||||
collections,spiceProducts }: Props) {
|
||||
|
||||
return (
|
||||
<>
|
||||
<HomeBanner />
|
||||
<HomeFeature />
|
||||
<HomeCategories />
|
||||
<HomeCollection data = {veggie}/>
|
||||
<FreshProducts data={freshProducts} collections={collections} />
|
||||
<HomeCollection />
|
||||
<HomeVideo />
|
||||
<HomeSpice />
|
||||
{spiceProducts.length>0 && <HomeSpice data={spiceProducts}/>}
|
||||
<FeaturedProductsCarousel data={featuredProducts} featuredFacetsValue={featuredAndDiscountFacetsValue} />
|
||||
<HomeCTA />
|
||||
<HomeRecipe />
|
||||
@@ -55,6 +61,8 @@ export async function getStaticProps({
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
|
||||
|
||||
props.featuredAndDiscountFacetsValue = getAllFacetValuesForFeatuedProducts(facets)
|
||||
|
||||
// fresh products
|
||||
@@ -72,7 +80,20 @@ export async function getStaticProps({
|
||||
props.freshProducts = []
|
||||
}
|
||||
|
||||
|
||||
//veggie
|
||||
const veggieProductvariables: ProductVariables = {
|
||||
groupByProduct:false
|
||||
}
|
||||
const veggieId = getFacetIdByName(facets,FACET.CATEGORY.PARENT_NAME,FACET.CATEGORY.VEGGIE)
|
||||
if (veggieId) {
|
||||
veggieProductvariables.facetValueIds = [veggieId]
|
||||
}
|
||||
const veggieProductsPromise = commerce.getAllProducts({
|
||||
variables: veggieProductvariables,
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
promisesWithKey.push({ key: 'veggie', promise: veggieProductsPromise, keyResult: 'products' })
|
||||
// featured products
|
||||
const allFeaturedFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_FEATURED)
|
||||
const allDiscountFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_DISCOUNT)
|
||||
@@ -99,15 +120,24 @@ export async function getStaticProps({
|
||||
})
|
||||
promisesWithKey.push({ key: 'collections', promise: collectionsPromise, keyResult: 'collections' })
|
||||
|
||||
// spiceProducts
|
||||
const spiceProducts = commerce.getAllProducts({
|
||||
variables: {
|
||||
collectionSlug: COLLECTION_SLUG_SPICE,
|
||||
},
|
||||
config,
|
||||
preview,
|
||||
})
|
||||
promisesWithKey.push({ key: 'spiceProducts', promise: spiceProducts, keyResult: 'products' })
|
||||
|
||||
try {
|
||||
const promises = getAllPromies(promisesWithKey)
|
||||
const rs = await Promise.all(promises)
|
||||
|
||||
|
||||
promisesWithKey.map((item, index) => {
|
||||
props[item.key] = item.keyResult ? rs[index][item.keyResult] : rs[index]
|
||||
props[item.key] = item.keyResult ? FilterOneVatiant(rs[index][item.keyResult]) : rs[index]
|
||||
return null
|
||||
})
|
||||
|
||||
return {
|
||||
props,
|
||||
revalidate: 60,
|
||||
|
Reference in New Issue
Block a user