mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
♻️ enhan: not get fresh and featured product when don't have facet id
:%s
This commit is contained in:
@@ -62,27 +62,34 @@ export async function getStaticProps({
|
|||||||
const freshFacetId = getFreshFacetId(facets)
|
const freshFacetId = getFreshFacetId(facets)
|
||||||
if (freshFacetId) {
|
if (freshFacetId) {
|
||||||
freshProductvariables.facetValueIds = [freshFacetId]
|
freshProductvariables.facetValueIds = [freshFacetId]
|
||||||
|
const freshProductsPromise = commerce.getAllProducts({
|
||||||
|
variables: freshProductvariables,
|
||||||
|
config,
|
||||||
|
preview,
|
||||||
|
})
|
||||||
|
promisesWithKey.push({ key: 'freshProducts', promise: freshProductsPromise, keyResult: 'products' })
|
||||||
|
} else {
|
||||||
|
props.freshProducts = []
|
||||||
}
|
}
|
||||||
const freshProductsPromise = commerce.getAllProducts({
|
|
||||||
variables: freshProductvariables,
|
|
||||||
config,
|
|
||||||
preview,
|
|
||||||
})
|
|
||||||
promisesWithKey.push({ key: 'freshProducts', promise: freshProductsPromise, keyResult: 'products' })
|
|
||||||
|
|
||||||
|
|
||||||
// featured products
|
// featured products
|
||||||
const allFeaturedFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_FEATURED)
|
const allFeaturedFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_FEATURED)
|
||||||
const allDiscountFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_DISCOUNT)
|
const allDiscountFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_DISCOUNT)
|
||||||
const facetValueIdsForFeaturedProducts = [...allFeaturedFacetIds, ...allDiscountFacetIds]
|
const facetValueIdsForFeaturedProducts = [...allFeaturedFacetIds, ...allDiscountFacetIds]
|
||||||
const featuredProductsPromise = commerce.getAllProducts({
|
|
||||||
variables: {
|
if (facetValueIdsForFeaturedProducts.length > 0) {
|
||||||
facetValueIds: facetValueIdsForFeaturedProducts
|
const featuredProductsPromise = commerce.getAllProducts({
|
||||||
},
|
variables: {
|
||||||
config,
|
facetValueIds: facetValueIdsForFeaturedProducts
|
||||||
preview,
|
},
|
||||||
})
|
config,
|
||||||
promisesWithKey.push({ key: 'featuredProducts', promise: featuredProductsPromise, keyResult: 'products' })
|
preview,
|
||||||
|
})
|
||||||
|
promisesWithKey.push({ key: 'featuredProducts', promise: featuredProductsPromise, keyResult: 'products' })
|
||||||
|
} else {
|
||||||
|
props.featuredProducts = []
|
||||||
|
}
|
||||||
|
|
||||||
// collection
|
// collection
|
||||||
const collectionsPromise = commerce.getAllCollections({
|
const collectionsPromise = commerce.getAllCollections({
|
||||||
|
Reference in New Issue
Block a user