This commit is contained in:
Joel Varty
2021-06-17 17:37:32 -04:00
parent d48aec2c2d
commit d9fe7d8e6b
23 changed files with 263 additions and 11789 deletions

View File

@@ -1,55 +1,27 @@
import { getConfig } from '@framework/api'
import getAllProducts from '@framework/api/operations/get-all-products'
import commerce from '@lib/api/commerce'
import rangeMap from '@lib/range-map'
const nonNullable = (v: any) => v
const getCustomInitialProps = async function ({ }):Promise<{bestSelling:any}> {
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 Best Selling Products
const { products: bestSellingProducts } = await getAllProducts({
variables: { field: 'bestSellingProducts', first: 6 },
const config = { locale, locales: [locale] }
const productsPromise = commerce.getAllProducts({
variables: { first: 6 },
config,
preview,
})
// Saleor provider only
...({ featured: true } as any),
})
// Get Best Newest Products
const { products: newestProducts } = await getAllProducts({
variables: { field: 'newestProducts', first: 12 },
config,
preview,
})
// These are the products that are going to be displayed in the landing.
// We prefer to do the computation at buildtime/servertime
const { bestSelling } = (() => {
// Create a copy of products that we can mutate
const products = [...newestProducts]
// If the lists of featured and best selling products don't have enough
// products, then fill them with products from the products list, this
// is useful for new commerce sites that don't have a lot of products
return {
bestSelling: rangeMap(
6,
(i) => bestSellingProducts[i] ?? products.shift()
).filter(nonNullable),
}
})()
const { products } = await productsPromise
return {
bestSelling
products
}
}
export default {getCustomInitialProps}
export default { getCustomInitialProps }

View File

@@ -0,0 +1,17 @@
import commerce from '@lib/api/commerce'
const getCustomInitialProps = async function ({ }):Promise<{pages:any, categories: any}> {
const languageCode = "en-us"
const preview = false
const config = { locale: languageCode, locales: [languageCode] }
const pagesPromise = commerce.getAllPages({ config, preview })
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
const { pages } = await pagesPromise
const { categories } = await siteInfoPromise
return {
pages, categories
}
}
export default {getCustomInitialProps}

View File

@@ -1,11 +1,4 @@
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
import commerce from '@lib/api/commerce'
const getCustomInitialProps = async function ({ item, agility, languageCode, channelName, pageInSitemap, dynamicPageItem }: any) {
//TODO: pass the locale and preview mode as props...
@@ -14,21 +7,21 @@ const getCustomInitialProps = async function ({ item, agility, languageCode, cha
const locale = "en-US"
const preview = false
const config = getConfig({ locale })
// Get Featured Products
const { products: featuredProducts } = await getAllProducts({
variables: { field: 'featuredProducts', first: 6 },
const config = { locale, locales: [locale] }
const productsPromise = commerce.getAllProducts({
variables: { first: 6 },
config,
preview,
// Saleor provider only
...({ featured: true } as any),
})
const { products } = await productsPromise
return {
featured: featuredProducts
products
}
}
export default { getCustomInitialProps }

View File

@@ -1,38 +1,27 @@
import { getConfig } from '@framework/api'
import getSiteInfo from '@framework/api/operations/get-site-info'
import getAllProducts from '@framework/api/operations/get-all-products'
import rangeMap from '@lib/range-map'
const nonNullable = (v: any) => v
import commerce from '@lib/api/commerce'
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 })
const { categories, brands } = await getSiteInfo({ config, preview })
// Get Best Newest Products
const { products: newestProducts } = await getAllProducts({
variables: { field: 'newestProducts', first: 12 },
const config = { locale, locales: [locale] }
const productsPromise = commerce.getAllProducts({
variables: { first: 6 },
config,
preview,
})
// Saleor provider only
...({ featured: true } as any),
})
const { products } = await productsPromise
return {
newestProducts: newestProducts,
categories,
brands
products
}
}
export default { getCustomInitialProps }

View File

@@ -0,0 +1,26 @@
import commerce from '@lib/api/commerce'
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 = { locale, locales: [locale] }
const productsPromise = commerce.getAllProducts({
variables: { first: 4 },
config,
preview,
})
const { products } = await productsPromise
return {
products
}
}
export default { getCustomInitialProps }

View File

@@ -1,5 +1,4 @@
import { getConfig } from '@framework/api'
import getSiteInfo from '@framework/api/operations/get-site-info'
import commerce from '@lib/api/commerce'
const getCustomInitialProps = async ({ agility, channelName, languageCode }:any) => {
@@ -7,14 +6,16 @@ const getCustomInitialProps = async ({ agility, channelName, languageCode }:any)
const locale = "en-US"
const preview = false
const config = { locale, locales: [locale] }
const pagesPromise = commerce.getAllPages({ config, preview })
const siteInfoPromise = commerce.getSiteInfo({ config, preview })
const config = getConfig({ locale })
const { categories, brands } = await getSiteInfo({ config, preview })
const { categories, brands } = await siteInfoPromise
return {
categories,
brands,
}
return {
categories,
brands
}
}

View File

@@ -1,13 +1,17 @@
import BestsellingProductsData from "./BestsellingProductsData"
import CartData from "./CartData"
import FeaturedProductsData from "./FeaturedProductsData"
import HomeAllProductsGridData from "./HomeAllProductsGridData"
import ProductSearchData from "./ProductSearchData"
import ProductDetailsData from "./ProductDetailsData"
const allModules:any =[
{ name: "BestsellingProducts", init: BestsellingProductsData },
{ name: "FeaturedProducts", init: FeaturedProductsData},
{ name: "HomeAllProductsGrid", init: HomeAllProductsGridData},
{ name: "ProductSearch", init: ProductSearchData}
{ name: "ProductSearch", init: ProductSearchData},
{ name: "Cart", init: CartData},
{ name: "ProductDetails", init: ProductDetailsData}
]
/**