♻️ 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,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({