Adding wishlist api

This commit is contained in:
okbel
2021-02-18 13:11:57 -03:00
parent c620355448
commit 4cfa0418dd
4 changed files with 28 additions and 8 deletions

View File

@@ -26,6 +26,8 @@ const SORT = Object.entries({
'price-desc': 'Price: High to low',
})
import Features from '@commerce/utils/features'
import {
filterQuery,
getCategoryPath,
@@ -40,14 +42,23 @@ export async function getStaticProps({
const config = getConfig({ locale })
const { pages } = await getAllPages({ config, preview })
const { categories, brands } = await getSiteInfo({ config, preview })
const isWishlistEnabled = Features.isEnabled('wishlist')
return {
props: { pages, categories, brands },
props: {
pages,
categories,
brands,
commerceFeatures: {
wishlist: isWishlistEnabled,
},
},
}
}
export default function Search({
categories,
brands,
commerceFeatures: { wishlist },
}: InferGetStaticPropsType<typeof getStaticProps>) {
const [activeFilter, setActiveFilter] = useState('')
const [toggleFilter, setToggleFilter] = useState(false)
@@ -337,7 +348,7 @@ export default function Search({
{data ? (
<Grid layout="normal">
{data.products.map((product) => (
{data.products.map((product: Product) => (
<ProductCard
variant="simple"
key={product.path}
@@ -347,6 +358,7 @@ export default function Search({
width: 480,
height: 480,
}}
wishlist={wishlist}
/>
))}
</Grid>

View File

@@ -11,14 +11,14 @@ import { useCustomer } from '@framework/customer'
import { WishlistCard } from '@components/wishlist'
import useWishlist from '@framework/wishlist/use-wishlist'
import getAllPages from '@framework/common/get-all-pages'
import frameworkConfig from '@framework/config.json'
import Features from '@commerce/utils/features'
export async function getStaticProps({
preview,
locale,
}: GetStaticPropsContext) {
// Disabling page if Feature is not available
if (!frameworkConfig.features.wishlist) {
if (Features.isEnabled('wishlist')) {
return {
notFound: true,
}