commerce/framework/module-data/FeaturedProductsData.ts
2021-06-09 23:17:19 -04:00

34 lines
723 B
TypeScript

import { getConfig } from '@framework/api'
import getAllProducts from '@framework/api/operations/get-all-products'
import rangeMap from '@lib/range-map'
const nonNullable = (v: any) => v
const getCustomInitialProps = async function ({ item, agility, languageCode, channelName, pageInSitemap, dynamicPageItem }: any) {
//TODO: pass the locale and preview mode as props...
const locale = "en-US"
const preview = false
const config = getConfig({ locale })
// Get Featured Products
const { products: featuredProducts } = await getAllProducts({
variables: { field: 'featuredProducts', first: 6 },
config,
preview,
})
return {
featured: featuredProducts
}
}
export default { getCustomInitialProps }