mirror of
https://github.com/vercel/commerce.git
synced 2025-05-12 12:47:50 +00:00
filters
This commit is contained in:
parent
ae486fcfbc
commit
b8b4e77645
@ -1,7 +1,5 @@
|
|||||||
import Footer from 'components/layout/footer';
|
import Footer from 'components/layout/footer';
|
||||||
import Collections from 'components/layout/search/collections';
|
import Collections from 'components/layout/search/collections';
|
||||||
import FilterList from 'components/layout/search/filter';
|
|
||||||
import { sorting } from 'lib/constants';
|
|
||||||
|
|
||||||
export default function SearchLayout({ children }: { children: React.ReactNode }) {
|
export default function SearchLayout({ children }: { children: React.ReactNode }) {
|
||||||
return (
|
return (
|
||||||
@ -12,7 +10,7 @@ export default function SearchLayout({ children }: { children: React.ReactNode }
|
|||||||
</div>
|
</div>
|
||||||
<div className="order-last min-h-screen w-full md:order-none">{children}</div>
|
<div className="order-last min-h-screen w-full md:order-none">{children}</div>
|
||||||
<div className="order-none flex-none md:order-last md:w-[125px]">
|
<div className="order-none flex-none md:order-last md:w-[125px]">
|
||||||
<FilterList list={sorting} title="Sort by" />
|
{/* <FilterList list={sorting} title="Sort by" /> */}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<Footer />
|
<Footer />
|
||||||
|
@ -3,8 +3,7 @@ import Link from 'next/link';
|
|||||||
import { GridTileImage } from './grid/tile';
|
import { GridTileImage } from './grid/tile';
|
||||||
|
|
||||||
export async function Carousel() {
|
export async function Carousel() {
|
||||||
// Collections that start with `hidden-*` are hidden from the search page.
|
const products = await getCollectionProducts({});
|
||||||
const products = await getCollectionProducts({ collection: 'hidden-homepage-carousel' });
|
|
||||||
|
|
||||||
if (!products?.length) return null;
|
if (!products?.length) return null;
|
||||||
|
|
||||||
|
@ -38,9 +38,8 @@ function ThreeItemGridItem({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function ThreeItemGrid() {
|
export async function ThreeItemGrid() {
|
||||||
// Collections that start with `hidden-*` are hidden from the search page.
|
|
||||||
const homepageItems = await getCollectionProducts({
|
const homepageItems = await getCollectionProducts({
|
||||||
collection: 'hidden-homepage-featured-items'
|
tag: 'featured'
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!homepageItems[0] || !homepageItems[1] || !homepageItems[2]) return null;
|
if (!homepageItems[0] || !homepageItems[1] || !homepageItems[2]) return null;
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { SHOPIFY_GRAPHQL_API_ENDPOINT, TAGS } from 'lib/constants';
|
import { SHOPIFY_GRAPHQL_API_ENDPOINT, TAGS } from 'lib/constants';
|
||||||
import { find, findByID } from 'lib/shopify/payload';
|
import { Where, find, findByID } from 'lib/shopify/payload';
|
||||||
import { Category, Media, Option, Product } from 'lib/shopify/payload-types';
|
import { Category, Media, Option, Product } from 'lib/shopify/payload-types';
|
||||||
import { isShopifyError } from 'lib/type-guards';
|
import { isShopifyError } from 'lib/type-guards';
|
||||||
import { ensureStartsWith } from 'lib/utils';
|
import { ensureStartsWith } from 'lib/utils';
|
||||||
@ -271,16 +271,36 @@ const reshapeProduct = (product: Product): ExProduct => {
|
|||||||
|
|
||||||
export async function getCollectionProducts({
|
export async function getCollectionProducts({
|
||||||
collection,
|
collection,
|
||||||
|
tag,
|
||||||
reverse,
|
reverse,
|
||||||
sortKey
|
sortKey
|
||||||
}: {
|
}: {
|
||||||
collection: string;
|
collection?: string;
|
||||||
|
tag?: string;
|
||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
sortKey?: string;
|
sortKey?: string;
|
||||||
}): Promise<ExProduct[]> {
|
}): Promise<ExProduct[]> {
|
||||||
console.log(collection);
|
const filters: Where[] = [];
|
||||||
|
if (collection) {
|
||||||
|
filters.push({
|
||||||
|
categories: {
|
||||||
|
equals: collection
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (tag) {
|
||||||
|
filters.push({
|
||||||
|
tags: {
|
||||||
|
equals: collection
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const products = await find<Product>('products', {});
|
const products = await find<Product>('products', {
|
||||||
|
where: {
|
||||||
|
and: filters
|
||||||
|
}
|
||||||
|
});
|
||||||
return products.docs.map(reshapeProduct);
|
return products.docs.map(reshapeProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,7 +383,25 @@ export async function getProducts({
|
|||||||
reverse?: boolean;
|
reverse?: boolean;
|
||||||
sortKey?: string;
|
sortKey?: string;
|
||||||
}): Promise<ExProduct[]> {
|
}): Promise<ExProduct[]> {
|
||||||
const products = await find<Product>('products', {});
|
let where: Where | undefined;
|
||||||
|
if (query) {
|
||||||
|
where = {
|
||||||
|
or: [
|
||||||
|
{
|
||||||
|
title: {
|
||||||
|
contains: query
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
description: {
|
||||||
|
contains: query
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const products = await find<Product>('products', { where });
|
||||||
return products.docs.map(reshapeProduct);
|
return products.docs.map(reshapeProduct);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ type Operator = (typeof OPERATORS)[number];
|
|||||||
type WhereField = {
|
type WhereField = {
|
||||||
[key in Operator]?: unknown;
|
[key in Operator]?: unknown;
|
||||||
};
|
};
|
||||||
type Where = {
|
export type Where = {
|
||||||
[key: string]: Where[] | WhereField;
|
[key: string]: Where[] | WhereField;
|
||||||
and?: Where[];
|
and?: Where[];
|
||||||
or?: Where[];
|
or?: Where[];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user