♻️ enhan: not get fresh and featured product when don't have facet id

:%s
This commit is contained in:
lytrankieio123
2021-10-05 10:35:53 +07:00
parent 1546d5df4b
commit 2ccccc51de

View File

@@ -62,19 +62,23 @@ export async function getStaticProps({
const freshFacetId = getFreshFacetId(facets)
if (freshFacetId) {
freshProductvariables.facetValueIds = [freshFacetId]
}
const freshProductsPromise = commerce.getAllProducts({
variables: freshProductvariables,
config,
preview,
})
promisesWithKey.push({ key: 'freshProducts', promise: freshProductsPromise, keyResult: 'products' })
} else {
props.freshProducts = []
}
// featured products
const allFeaturedFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_FEATURED)
const allDiscountFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_DISCOUNT)
const facetValueIdsForFeaturedProducts = [...allFeaturedFacetIds, ...allDiscountFacetIds]
if (facetValueIdsForFeaturedProducts.length > 0) {
const featuredProductsPromise = commerce.getAllProducts({
variables: {
facetValueIds: facetValueIdsForFeaturedProducts
@@ -83,6 +87,9 @@ export async function getStaticProps({
preview,
})
promisesWithKey.push({ key: 'featuredProducts', promise: featuredProductsPromise, keyResult: 'products' })
} else {
props.featuredProducts = []
}
// collection
const collectionsPromise = commerce.getAllCollections({