diff --git a/commerce.config.json b/commerce.config.json
index ad72b58de..6fb526aaf 100644
--- a/commerce.config.json
+++ b/commerce.config.json
@@ -2,8 +2,8 @@
"features": {
"cart": true,
"search": true,
- "wishlist": false,
- "customerAuth": false,
- "customCheckout": false
+ "wishlist": true,
+ "customerAuth": true,
+ "customCheckout": true
}
}
diff --git a/framework/commerce/api/operations.ts b/framework/commerce/api/operations.ts
index 2910a2d82..ca9b325c2 100644
--- a/framework/commerce/api/operations.ts
+++ b/framework/commerce/api/operations.ts
@@ -1,3 +1,4 @@
+import { GetAllFacetsOperation } from './../types/facet';
import type { ServerResponse } from 'http'
import type { LoginOperation } from '../types/login'
import type { GetAllPagesOperation, GetPageOperation } from '../types/page'
@@ -9,6 +10,7 @@ import type {
GetProductOperation,
} from '../types/product'
import type { APIProvider, CommerceAPI } from '.'
+import { GetAllCollectionsOperation } from '@commerce/types/collection';
const noop = () => {
throw new Error('Not implemented')
@@ -23,6 +25,9 @@ export const OPERATIONS = [
'getAllProductPaths',
'getAllProducts',
'getProduct',
+ 'getAllFacets',
+ 'getAllCollections',
+
] as const
export const defaultOperations = OPERATIONS.reduce((ops, k) => {
@@ -154,8 +159,43 @@ export type Operations
= {
} & OperationOptions
): Promise
}
+
+ getAllFacets: {
+ (opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ }): Promise
+
+ (
+ opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+ }
+
+ getAllCollections: {
+ (opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ }): Promise
+
+ (
+ opts: {
+ variables?: T['variables']
+ config?: P['config']
+ preview?: boolean
+ } & OperationOptions
+ ): Promise
+ }
+
+
}
+
export type APIOperations = {
[K in keyof Operations
]?: (ctx: OperationContext
) => Operations
[K]
}
diff --git a/framework/commerce/new-provider.md b/framework/commerce/new-provider.md
index 8c2feeab2..3c7f05b7a 100644
--- a/framework/commerce/new-provider.md
+++ b/framework/commerce/new-provider.md
@@ -15,6 +15,8 @@ Adding a commerce provider means adding a new folder in `framework` with a folde
- useSearch
- getProduct
- getAllProducts
+ - getAllFacets
+ - getAllCollections
- `wishlist`
- useWishlist
- useAddItem
diff --git a/framework/commerce/types/collection.ts b/framework/commerce/types/collection.ts
new file mode 100644
index 000000000..3ccb72ea3
--- /dev/null
+++ b/framework/commerce/types/collection.ts
@@ -0,0 +1,54 @@
+import { Asset } from '../../vendure/schema.d';
+
+export type Collection = {
+ id: string
+ name: string
+ slug: string
+ description: string
+ featuredAsse: Asset
+ asset: Asset[]
+}
+
+export type SearchCollectionsBody = {
+ search?: string
+ sort?: string
+ locale?: string
+}
+
+export type CollectionTypes = {
+ collection: Collection
+ searchBody: SearchCollectionsBody
+}
+
+export type SearchCollectionsHook = {
+ data: {
+ collections: T['collection'][]
+ found: boolean
+ }
+ body: T['searchBody']
+ input: T['searchBody']
+ fetcherInput: T['searchBody']
+}
+
+export type CollectionsSchema = {
+ endpoint: {
+ options: {}
+ handlers: {
+ getCollections: SearchCollectionsHook
+ }
+ }
+}
+
+
+export type GetAllCollectionsOperation = {
+ data: { collections: T['collection'][] }
+ variables: {
+ ids?: string[]
+ first?: number
+ }
+}
+
+export type GetCollectionOperation = {
+ data: { collection?: T['collection'] }
+ variables: { code: string; } | { code?: never; }
+}
diff --git a/framework/commerce/types/facet.ts b/framework/commerce/types/facet.ts
new file mode 100644
index 000000000..adfe1e061
--- /dev/null
+++ b/framework/commerce/types/facet.ts
@@ -0,0 +1,52 @@
+import { FacetValue } from './../../vendure/schema.d';
+
+export type Facet = {
+ id: string
+ name: string
+ code: string
+ values: FacetValue[]
+}
+
+export type SearchFacetsBody = {
+ search?: string
+ sort?: string
+ locale?: string
+}
+
+export type FacetTypes = {
+ facet: Facet
+ searchBody: SearchFacetsBody
+}
+
+export type SearchFacetsHook = {
+ data: {
+ facets: T['facet'][]
+ found: boolean
+ }
+ body: T['searchBody']
+ input: T['searchBody']
+ fetcherInput: T['searchBody']
+}
+
+export type FacetsSchema = {
+ endpoint: {
+ options: {}
+ handlers: {
+ getFacets: SearchFacetsHook
+ }
+ }
+}
+
+
+export type GetAllFacetsOperation = {
+ data: { facets: T['facet'][] }
+ variables: {
+ ids?: string[]
+ first?: number
+ }
+}
+
+export type GetFacetOperation = {
+ data: { facet?: T['facet'] }
+ variables: { code: string; } | { code?: never; }
+}
diff --git a/framework/commerce/types/product.ts b/framework/commerce/types/product.ts
index 6a68d8ad1..e1a8da200 100644
--- a/framework/commerce/types/product.ts
+++ b/framework/commerce/types/product.ts
@@ -1,3 +1,6 @@
+import { CurrencyCode } from './../../vendure/schema.d';
+import { FacetValueFilterInput, LogicalOperator, SearchResultSortParameter } from "@framework/schema"
+
export type ProductImage = {
url: string
alt?: string
@@ -40,11 +43,26 @@ export type Product = {
slug?: string
path?: string
images: ProductImage[]
- variants: ProductVariant[]
price: ProductPrice
options: ProductOption[]
}
+export type ProductCard = {
+ id: string
+ name: string
+ slug?: string
+ imageSrc: string
+ price: number
+ currencyCode: CurrencyCode
+ oldPrice?: number
+ discount?: number
+ weight?: number
+ facetValueIds?: string[],
+ collectionIds?: string[],
+ collection?: string,
+ isNotSell?: boolean
+}
+
export type SearchProductsBody = {
search?: string
categoryId?: string | number
@@ -79,17 +97,24 @@ export type ProductsSchema = {
export type GetAllProductPathsOperation<
T extends ProductTypes = ProductTypes
-> = {
- data: { products: Pick[] }
- variables: { first?: number }
-}
+ > = {
+ data: { products: Pick[] }
+ variables: { first?: number }
+ }
export type GetAllProductsOperation = {
data: { products: T['product'][] }
variables: {
- relevance?: 'featured' | 'best_selling' | 'newest'
- ids?: string[]
- first?: number
+ term?: String
+ facetValueIds?: string[]
+ facetValueOperator?: LogicalOperator
+ facetValueFilters?: FacetValueFilterInput[]
+ collectionId?: string
+ collectionSlug?: string
+ groupByProduct?: Boolean
+ take?: number
+ skip?: number
+ sort?: SearchResultSortParameter
}
}
diff --git a/framework/vendure/api/index.ts b/framework/vendure/api/index.ts
index 6762ee6aa..95ec47d66 100644
--- a/framework/vendure/api/index.ts
+++ b/framework/vendure/api/index.ts
@@ -1,15 +1,17 @@
-import type { APIProvider, CommerceAPIConfig } from '@commerce/api'
+import type { CommerceAPIConfig } from '@commerce/api'
import { CommerceAPI, getCommerceApi as commerceApi } from '@commerce/api'
-import fetchGraphqlApi from './utils/fetch-graphql-api'
-
-import login from './operations/login'
+import getAllFacets from './operations/get-all-facets'
+import getAllCollections from './operations/get-all-collection'
import getAllPages from './operations/get-all-pages'
-import getPage from './operations/get-page'
-import getSiteInfo from './operations/get-site-info'
-import getCustomerWishlist from './operations/get-customer-wishlist'
import getAllProductPaths from './operations/get-all-product-paths'
import getAllProducts from './operations/get-all-products'
+import getCustomerWishlist from './operations/get-customer-wishlist'
+import getPage from './operations/get-page'
import getProduct from './operations/get-product'
+import getSiteInfo from './operations/get-site-info'
+import login from './operations/login'
+import fetchGraphqlApi from './utils/fetch-graphql-api'
+
export interface VendureConfig extends CommerceAPIConfig {}
@@ -40,6 +42,8 @@ const operations = {
getAllProductPaths,
getAllProducts,
getProduct,
+ getAllFacets,
+ getAllCollections,
}
export const provider = { config, operations }
diff --git a/framework/vendure/api/operations/get-all-collection.ts b/framework/vendure/api/operations/get-all-collection.ts
new file mode 100644
index 000000000..b7cc3a725
--- /dev/null
+++ b/framework/vendure/api/operations/get-all-collection.ts
@@ -0,0 +1,45 @@
+import { OperationContext } from '@commerce/api/operations'
+import { Collection } from '@commerce/types/collection'
+import { Provider, VendureConfig } from '..'
+import { GetAllCollectionsQuery } from '../../schema'
+import { getAllCollectionsQuery } from '../../utils/queries/get-all-collections-query'
+
+export type CollectionVariables = { first?: number }
+
+export default function getAllCollectionsOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllCollections(opts?: {
+ variables?: CollectionVariables
+ config?: Partial
+ preview?: boolean
+ }): Promise<{ collections: Collection[] }>
+
+ async function getAllCollections({
+ query = getAllCollectionsQuery,
+ variables: { ...vars } = {},
+ config: cfg,
+ }: {
+ query?: string
+ variables?: CollectionVariables
+ config?: Partial
+ preview?: boolean
+ } = {}): Promise<{ collections: Collection[] | any[] }> {
+ const config = commerce.getConfig(cfg)
+ const variables = {
+ input: {
+ take: vars.first,
+ groupByCollection: true,
+ },
+ }
+ const { data } = await config.fetch(query, {
+ variables,
+ })
+
+ return {
+ collections: data.collections.items,
+ }
+ }
+
+ return getAllCollections
+}
diff --git a/framework/vendure/api/operations/get-all-facets.ts b/framework/vendure/api/operations/get-all-facets.ts
new file mode 100644
index 000000000..c4b002744
--- /dev/null
+++ b/framework/vendure/api/operations/get-all-facets.ts
@@ -0,0 +1,45 @@
+import { OperationContext } from '@commerce/api/operations'
+import { Facet } from '@commerce/types/facet'
+import { Provider, VendureConfig } from '../'
+import { GetAllFacetsQuery } from '../../schema'
+import { getAllFacetsQuery } from '../../utils/queries/get-all-facets-query'
+
+export type FacetVariables = { first?: number }
+
+export default function getAllFacetsOperation({
+ commerce,
+}: OperationContext) {
+ async function getAllFacets(opts?: {
+ variables?: FacetVariables
+ config?: Partial
+ preview?: boolean
+ }): Promise<{ facets: Facet[] }>
+
+ async function getAllFacets({
+ query = getAllFacetsQuery,
+ variables: { ...vars } = {},
+ config: cfg,
+ }: {
+ query?: string
+ variables?: FacetVariables
+ config?: Partial
+ preview?: boolean
+ } = {}): Promise<{ facets: Facet[] | any[] }> {
+ const config = commerce.getConfig(cfg)
+ const variables = {
+ input: {
+ take: vars.first,
+ groupByFacet: true,
+ },
+ }
+ const { data } = await config.fetch(query, {
+ variables,
+ })
+
+ return {
+ facets: data.facets.items,
+ }
+ }
+
+ return getAllFacets
+}
diff --git a/framework/vendure/api/operations/get-all-products.ts b/framework/vendure/api/operations/get-all-products.ts
index 68d4ce9b7..1f558a7cb 100644
--- a/framework/vendure/api/operations/get-all-products.ts
+++ b/framework/vendure/api/operations/get-all-products.ts
@@ -5,7 +5,7 @@ import { normalizeSearchResult } from '../../utils/normalize'
import { getAllProductsQuery } from '../../utils/queries/get-all-products-query'
import { OperationContext } from '@commerce/api/operations'
-export type ProductVariables = { first?: number }
+export type ProductVariables = { first?: number, facetValueIds?: string[] }
export default function getAllProductsOperation({
commerce,
@@ -30,6 +30,7 @@ export default function getAllProductsOperation({
const variables = {
input: {
take: vars.first,
+ facetValueIds: vars.facetValueIds,
groupByProduct: true,
},
}
diff --git a/framework/vendure/schema.d.ts b/framework/vendure/schema.d.ts
index 840eaadda..7d9684a1f 100644
--- a/framework/vendure/schema.d.ts
+++ b/framework/vendure/schema.d.ts
@@ -1,3 +1,4 @@
+import { FacetValue } from './schema.d';
export type Maybe = T | null
export type Exact = {
[K in keyof T]: T[K]
@@ -93,6 +94,10 @@ export type QueryProductsArgs = {
options?: Maybe
}
+export type QueryFacetsArgs = {
+ options?: Maybe
+}
+
export type QuerySearchArgs = {
input: SearchInput
}
@@ -2727,6 +2732,13 @@ export type ProductListOptions = {
filter?: Maybe
}
+export type FacetListOptions = {
+ skip?: Maybe
+ take?: Maybe
+ sort?: Maybe
+ filter?: Maybe
+}
+
export type UpdateOrderItemsResult =
| Order
| OrderModificationError
@@ -2884,6 +2896,23 @@ export type ProductVariantSortParameter = {
discountPrice?: Maybe
}
+
+export type FacetFilterParameter = {
+ createdAt?: Maybe
+ updatedAt?: Maybe
+ languageCode?: Maybe
+ name?: Maybe
+ code?: Maybe
+}
+
+export type FacetSortParameter = {
+ id?: Maybe
+ createdAt?: Maybe
+ updatedAt?: Maybe
+ name?: Maybe
+ code?: Maybe
+}
+
export type CustomerFilterParameter = {
createdAt?: Maybe
updatedAt?: Maybe
@@ -3008,7 +3037,9 @@ export type CartFragment = { __typename?: 'Order' } & Pick<
export type SearchResultFragment = { __typename?: 'SearchResult' } & Pick<
SearchResult,
- 'productId' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
+ 'productId' | 'sku' | 'productName' | 'description' | 'slug' | 'sku' | 'currencyCode'
+ | 'productAsset' | 'price' | 'priceWithTax' | 'currencyCode'
+ | 'collectionIds' | 'facetValueIds' | 'collectionIds'
> & {
productAsset?: Maybe<
{ __typename?: 'SearchResultAsset' } & Pick<
@@ -3192,6 +3223,40 @@ export type GetAllProductsQuery = { __typename?: 'Query' } & {
}
}
+export type GetAllFacetsQuery = { __typename?: 'Query' } & {
+ facets: { __typename?: 'FacetList' } & {
+ items: Array<
+ { __typename?: 'Facet' } & Pick<
+ Facet,
+ 'id' | 'name' | 'code'
+ > & {
+ parent?: Maybe<{ __typename?: 'Facet' } & Pick>
+ children?: Maybe<
+ Array<{ __typename?: 'Facet' } & Pick>
+ >
+ }
+ >,
+ 'totalItems'
+ }
+}
+
+export type GetAllCollectionsQuery = { __typename?: 'Query' } & {
+ collections: { __typename?: 'CollectionList' } & {
+ items: Array<
+ { __typename?: 'Collection' } & Pick<
+ Collection,
+ 'id' | 'name' | 'slug'
+ > & {
+ parent?: Maybe<{ __typename?: 'Collection' } & Pick>
+ children?: Maybe<
+ Array<{ __typename?: 'Collection' } & Pick>
+ >
+ }
+ >,
+ 'totalItems'
+ }
+}
+
export type ActiveOrderQueryVariables = Exact<{ [key: string]: never }>
export type ActiveOrderQuery = { __typename?: 'Query' } & {
diff --git a/framework/vendure/utils/fragments/search-result-fragment.ts b/framework/vendure/utils/fragments/search-result-fragment.ts
index 6155b5b47..d2d82f42e 100644
--- a/framework/vendure/utils/fragments/search-result-fragment.ts
+++ b/framework/vendure/utils/fragments/search-result-fragment.ts
@@ -19,6 +19,8 @@ export const searchResultFragment = /* GraphQL */ `
min
max
}
- }
+ },
+ facetValueIds,
+ collectionIds,
}
`
diff --git a/framework/vendure/utils/normalize.ts b/framework/vendure/utils/normalize.ts
index 09c1c6e42..cc76e5f97 100644
--- a/framework/vendure/utils/normalize.ts
+++ b/framework/vendure/utils/normalize.ts
@@ -1,22 +1,23 @@
-import { Product } from '@commerce/types/product'
import { Cart } from '@commerce/types/cart'
+import { ProductCard } from '@commerce/types/product'
import { CartFragment, SearchResultFragment } from '../schema'
-export function normalizeSearchResult(item: SearchResultFragment): Product {
+export function normalizeSearchResult(item: SearchResultFragment): ProductCard {
return {
id: item.productId,
name: item.productName,
- description: item.description,
slug: item.slug,
- path: item.slug,
- images: [{ url: item.productAsset?.preview + '?w=800&mode=crop' || '' }],
- variants: [],
- price: {
- value: (item.priceWithTax as any).min / 100,
- currencyCode: item.currencyCode,
- },
- options: [],
- sku: item.sku,
+ imageSrc: item.productAsset?.preview ? item.productAsset?.preview + '?w=800&mode=crop' : '',
+ price: (item.priceWithTax as any).min / 100,
+ currencyCode: item.currencyCode,
+ facetValueIds: item.facetValueIds,
+ collectionIds: item.collectionIds,
+
+ // TODO:
+ // oldPrice: item.price
+ // discount
+ // isNotSell
+ // weight
}
}
diff --git a/framework/vendure/utils/queries/get-all-collections-query.ts b/framework/vendure/utils/queries/get-all-collections-query.ts
new file mode 100644
index 000000000..359c81ea9
--- /dev/null
+++ b/framework/vendure/utils/queries/get-all-collections-query.ts
@@ -0,0 +1,12 @@
+export const getAllCollectionsQuery = /* GraphQL */ `
+query collections ($options: CollectionListOptions) {
+ collections (options: $options){
+ totalItems,
+ items {
+ id
+ name
+ slug
+ }
+ }
+}
+`
diff --git a/framework/vendure/utils/queries/get-all-facets-query.ts b/framework/vendure/utils/queries/get-all-facets-query.ts
new file mode 100644
index 000000000..906507c69
--- /dev/null
+++ b/framework/vendure/utils/queries/get-all-facets-query.ts
@@ -0,0 +1,17 @@
+export const getAllFacetsQuery = /* GraphQL */ `
+query facets ($options: FacetListOptions) {
+ facets (options: $options){
+ totalItems,
+ items {
+ id
+ name
+ code
+ values {
+ id
+ name
+ code
+ }
+ }
+ }
+}
+`
diff --git a/framework/vendure/utils/queries/get-collections-query.ts b/framework/vendure/utils/queries/get-collections-query.ts
index ed0919652..79e00a292 100644
--- a/framework/vendure/utils/queries/get-collections-query.ts
+++ b/framework/vendure/utils/queries/get-collections-query.ts
@@ -19,3 +19,13 @@ export const getCollectionsQuery = /* GraphQL */ `
}
}
`
+export const getCollectionsNameQuery = /* GraphQL */ `
+ query getCollections {
+ collections{
+ items{
+ name
+ link:slug
+ }
+ }
+ }
+`
\ No newline at end of file
diff --git a/pages/index.tsx b/pages/index.tsx
index 3fa86079d..cac464a43 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -1,19 +1,37 @@
+import { ProductCard } from '@commerce/types/product';
+import { ProductVariables } from '@framework/api/operations/get-all-products';
+import { Collection, FacetValue } from '@framework/schema';
+import commerce from '@lib/api/commerce';
+import { GetStaticPropsContext } from 'next';
import { Layout } from 'src/components/common';
-import { FeaturedProductsCarousel, HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
+import { FeaturedProductsCarousel, FreshProducts, HomeBanner, HomeCategories, HomeCollection, HomeCTA, HomeFeature, HomeRecipe, HomeSubscribe, HomeVideo } from 'src/components/modules/home';
import HomeSpice from 'src/components/modules/home/HomeSpice/HomeSpice';
+import { CODE_FACET_DISCOUNT, CODE_FACET_FEATURED } from 'src/utils/constanst.utils';
+import { getAllFacetValueIdsByParentCode, getAllFacetValuesForFeatuedProducts, getAllPromies, getFreshFacetId } from 'src/utils/funtion.utils';
+import { PromiseWithKey } from 'src/utils/types.utils';
-export default function Home() {
+interface Props {
+ featuredAndDiscountFacetsValue: FacetValue[],
+ freshProducts: ProductCard[],
+ featuredProducts: ProductCard[],
+ collections: Collection[]
+
+}
+export default function Home({ featuredAndDiscountFacetsValue,
+ freshProducts, featuredProducts,
+ collections }: Props) {
return (
<>
+
-
-
+
+
-
+
{/* // todo: uncomment
@@ -22,4 +40,76 @@ export default function Home() {
)
}
+
+export async function getStaticProps({
+ preview,
+ locale,
+ locales,
+}: GetStaticPropsContext) {
+ const config = { locale, locales }
+ let promisesWithKey = [] as PromiseWithKey[]
+ let props = {} as any
+
+ const { facets } = await commerce.getAllFacets({
+ variables: {},
+ config,
+ preview,
+ })
+ props.featuredAndDiscountFacetsValue = getAllFacetValuesForFeatuedProducts(facets)
+
+ // fresh products
+ const freshProductvariables: ProductVariables = {}
+ 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' })
+
+
+ // featured products
+ const allFeaturedFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_FEATURED)
+ const allDiscountFacetIds = getAllFacetValueIdsByParentCode(facets, CODE_FACET_DISCOUNT)
+ const facetValueIdsForFeaturedProducts = [...allFeaturedFacetIds, ...allDiscountFacetIds]
+ const featuredProductsPromise = commerce.getAllProducts({
+ variables: {
+ facetValueIds: facetValueIdsForFeaturedProducts
+ },
+ config,
+ preview,
+ })
+ promisesWithKey.push({ key: 'featuredProducts', promise: featuredProductsPromise, keyResult: 'products' })
+
+ // collection
+ const collectionsPromise = commerce.getAllCollections({
+ variables: {},
+ config,
+ preview,
+ })
+ promisesWithKey.push({ key: 'collections', promise: collectionsPromise, keyResult: 'collections' })
+
+
+ try {
+ const promises = getAllPromies(promisesWithKey)
+ const rs = await Promise.all(promises)
+
+ promisesWithKey.map((item, index) => {
+ props[item.key] = item.keyResult ? rs[index][item.keyResult] : rs[index]
+ return null
+ })
+
+ return {
+ props,
+ revalidate: 60,
+ }
+ } catch (err) {
+
+ }
+}
+
+
Home.Layout = Layout
diff --git a/pages/product/[slug].tsx b/pages/product/[slug].tsx
index ab9a1c17c..a8e925df9 100644
--- a/pages/product/[slug].tsx
+++ b/pages/product/[slug].tsx
@@ -4,6 +4,7 @@ import { ProductInfoDetail, ReleventProducts, ViewedProducts } from 'src/compone
import { BLOGS_DATA_TEST, INGREDIENT_DATA_TEST, RECIPE_DATA_TEST } from 'src/utils/demo-data'
export default function Slug() {
+
return <>
diff --git a/pages/test.tsx b/pages/test.tsx
index b60fe63c7..6244c3dd6 100644
--- a/pages/test.tsx
+++ b/pages/test.tsx
@@ -1,18 +1,51 @@
-import { Layout } from 'src/components/common'
-import { useMessage } from 'src/components/contexts'
-
-export default function Test() {
- const { showMessageError } = useMessage()
-
- const handleClick = () => {
- showMessageError("Create account successfully")
- }
+import commerce from '@lib/api/commerce';
+import { GetStaticPropsContext } from 'next';
+import { Layout } from 'src/components/common';
+interface Props {
+ products: any
+}
+export default function Home({ products }: Props) {
return (
<>
-
+
+ TOTAL: {products?.length}
+
+ {JSON.stringify(products[0])}
>
)
}
-Test.Layout = Layout
+
+export async function getServerSideProps({
+ preview,
+ locale,
+ locales,
+}: GetStaticPropsContext) {
+ const config = { locale, locales }
+ const productsPromise = commerce.getAllProducts({
+ // const productsPromise = commerce.getAllFacets({
+ variables: {
+ first: 70,
+ // filter: {
+ // name: {
+ // contains: 'ca'
+ // }
+ // }
+ },
+ config,
+ preview,
+ // Saleor provider only
+ ...({ featured: true } as any),
+ })
+
+ const { products } = await productsPromise
+
+
+ return {
+ props: { products },
+ }
+}
+
+
+Home.Layout = Layout
diff --git a/public/assets/images/default_img.jpg b/public/assets/images/default_img.jpg
new file mode 100644
index 000000000..f72d03596
Binary files /dev/null and b/public/assets/images/default_img.jpg differ
diff --git a/src/components/common/FeaturedProductCard/FeaturedProductCard.module.scss b/src/components/common/FeaturedProductCard/FeaturedProductCard.module.scss
index 036e84629..3f95f92da 100644
--- a/src/components/common/FeaturedProductCard/FeaturedProductCard.module.scss
+++ b/src/components/common/FeaturedProductCard/FeaturedProductCard.module.scss
@@ -21,6 +21,9 @@
width: 24rem;
height: 24rem;
}
+ img {
+ object-fit: contain;
+ }
}
.right{
margin-left: 1.2rem;
diff --git a/src/components/common/FeaturedProductCard/FeaturedProductCard.tsx b/src/components/common/FeaturedProductCard/FeaturedProductCard.tsx
index a82b6857b..23b9ac987 100644
--- a/src/components/common/FeaturedProductCard/FeaturedProductCard.tsx
+++ b/src/components/common/FeaturedProductCard/FeaturedProductCard.tsx
@@ -1,39 +1,55 @@
+import { ProductCard } from '@commerce/types/product'
+import { Facet, FacetValue } from '@framework/schema'
+import Link from 'next/link'
import React from 'react'
-import { FeaturedProductProps } from 'src/utils/types.utils'
-import s from './FeaturedProductCard.module.scss'
-import { LANGUAGE } from '../../../utils/language.utils'
-import ButtonIconBuy from '../ButtonIconBuy/ButtonIconBuy'
-import ButtonCommon from '../ButtonCommon/ButtonCommon'
+import { ROUTE } from 'src/utils/constanst.utils'
import { ImgWithLink } from '..'
-export interface FeaturedProductCardProps extends FeaturedProductProps {
- buttonText?: string
+import { LANGUAGE } from '../../../utils/language.utils'
+import ButtonCommon from '../ButtonCommon/ButtonCommon'
+import ButtonIconBuy from '../ButtonIconBuy/ButtonIconBuy'
+import s from './FeaturedProductCard.module.scss'
+export interface FeaturedProductCardProps extends ProductCard {
+ buttonText?: string,
+ subText?: string,
}
const FeaturedProductCard = ({
imageSrc,
- title,
- subTitle,
+ name,
+ slug,
price,
- originPrice,
+ subText,
+ currencyCode,
buttonText = LANGUAGE.BUTTON_LABEL.BUY_NOW,
}: FeaturedProductCardProps) => {
+
+
return (
-
{title}
-
{subTitle}
+
+
+ {name}
+
+
+
{subText}
-
{price}
-
{originPrice}
+
{price} {currencyCode}
+ {/* TODO: */}
+ {/*
{originPrice}
*/}
-
+
{buttonText}
diff --git a/src/components/common/Header/components/HeaderSubMenu/HeaderSubMenu.tsx b/src/components/common/Header/components/HeaderSubMenu/HeaderSubMenu.tsx
index eb7d0a18a..2cd72e5f2 100644
--- a/src/components/common/Header/components/HeaderSubMenu/HeaderSubMenu.tsx
+++ b/src/components/common/Header/components/HeaderSubMenu/HeaderSubMenu.tsx
@@ -3,6 +3,7 @@ import Link from 'next/link'
import { useRouter } from 'next/router'
import { memo } from 'react'
import MenuDropdown from 'src/components/common/MenuDropdown/MenuDropdown'
+import { useGetAllCollection } from 'src/components/hooks/collection'
import { ProductFeature, QUERY_KEY, ROUTE } from 'src/utils/constanst.utils'
import HeaderNoti from './HeaderNoti/HeaderNoti'
import s from './HeaderSubMenu.module.scss'
@@ -30,39 +31,18 @@ const MENU = [
},
]
-// note: hard code, remove later
-const CATEGORY = [
- {
- name: 'Veggie',
- link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=veggie`,
- },
- {
- name: 'Seafood',
- link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=seafood`,
- },
- {
- name: 'Frozen',
- link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=frozen`,
- },
- {
- name: 'Coffee Bean',
- link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=coffee-bean`,
- },
- {
- name: 'Sauce',
- link: `${ROUTE.PRODUCTS}/?${QUERY_KEY.BRAND}=sauce`,
- },
-]
+
const HeaderSubMenu = memo(() => {
const router = useRouter()
+ const {collections} = useGetAllCollection();
return (
{/* todo: handle active item */}
-
- Categories
+ Categories
{
MENU.map(item => - {
return (
-
{
+ children?: React.ReactNode
size?: 'default' | 'large'
shape?: 'half' | 'round' | 'default'
type?: 'default' | 'discount' | 'waiting' | 'delivering' | 'delivered'
diff --git a/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx b/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx
index c08b9120f..e3d0a8417 100644
--- a/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx
+++ b/src/components/common/ModalAuthenticate/components/FormRegister/FormRegister.tsx
@@ -48,7 +48,7 @@ const FormRegister = ({ onSwitch, isHide }: Props) => {
const onSignupCallBack = (isSuccess: boolean, message?: string) => {
if (isSuccess) {
- showMessageSuccess("Create account successfully. Please verify your email to login.")
+ showMessageSuccess("Create account successfully. Please verify your email to login.", 15000)
} else {
showMessageError(message || LANGUAGE.MESSAGE.ERROR)
}
@@ -71,7 +71,7 @@ const FormRegister = ({ onSwitch, isHide }: Props) => {
validationSchema={DisplayingErrorMessagesSchema}
onSubmit={onSignup}
>
- {({ errors, touched }) => (
+ {({ errors, touched, isValid, submitForm }) => (