Filter store to only show artworks with GBP prices set
The store was fetching all 2,324 artworks and filtering client-side, resulting in 656 items shown (including imported catalog entries with only USD prices and no images). Now filters at the Directus API level for artworks with price_gbp set, showing only the 19 actual store items. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
2523a304cf
commit
94894181ea
|
|
@ -13,11 +13,8 @@ export const revalidate = 0;
|
||||||
|
|
||||||
async function getShopItems(): Promise<{ available: Artwork[]; sold: Artwork[] }> {
|
async function getShopItems(): Promise<{ available: Artwork[]; sold: Artwork[] }> {
|
||||||
try {
|
try {
|
||||||
const allArtworks = await getArtworks({});
|
const available = await getArtworks({ status: 'published', forSale: true });
|
||||||
const available = allArtworks.filter(
|
const sold = await getArtworks({ status: 'sold', forSale: true });
|
||||||
(a) => a.status === 'published' && a.price && a.price > 0
|
|
||||||
);
|
|
||||||
const sold = allArtworks.filter((a) => a.status === 'sold');
|
|
||||||
return { available, sold };
|
return { available, sold };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching shop items:', error);
|
console.error('Error fetching shop items:', error);
|
||||||
|
|
|
||||||
|
|
@ -238,10 +238,14 @@ export async function getArtworks(options?: {
|
||||||
series?: string;
|
series?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
fields?: string[];
|
fields?: string[];
|
||||||
|
forSale?: boolean;
|
||||||
}): Promise<Artwork[]> {
|
}): Promise<Artwork[]> {
|
||||||
const filter: Record<string, unknown> = {};
|
const filter: Record<string, unknown> = {};
|
||||||
if (options?.status) filter.status = { _eq: options.status };
|
if (options?.status) filter.status = { _eq: options.status };
|
||||||
if (options?.series) filter.series = { _eq: options.series };
|
if (options?.series) filter.series = { _eq: options.series };
|
||||||
|
if (options?.forSale) {
|
||||||
|
filter.price_gbp = { _nnull: true, _gt: 0 };
|
||||||
|
}
|
||||||
|
|
||||||
const result = await directus.request(
|
const result = await directus.request(
|
||||||
readItems('artworks', {
|
readItems('artworks', {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue