Optimize preview image size

This commit is contained in:
Michael Bromley 2021-01-25 21:31:25 +01:00
parent 5054f64fcf
commit ec42680e48
2 changed files with 23 additions and 18 deletions

View File

@ -61,10 +61,10 @@ export function normalizeProduct(productNode: any): Product {
price: { price: {
$set: { $set: {
value: prices?.price.value, value: prices?.price.value,
currencyCode: prices?.price.currencyCode currencyCode: prices?.price.currencyCode,
} },
}, },
$unset: ['entityId'] $unset: ['entityId'],
}) })
} }
@ -75,14 +75,14 @@ export function normalizeSearchResult(item: SearchResultFragment): Product {
description: item.description, description: item.description,
slug: item.slug, slug: item.slug,
path: item.slug, path: item.slug,
images: [{ url: item.productAsset?.preview || '' }], images: [{ url: item.productAsset?.preview + '?preset=medium' || '' }],
variants: [], variants: [],
price: { price: {
value: ((item.priceWithTax as any).min / 100), value: (item.priceWithTax as any).min / 100,
currencyCode: item.currencyCode currencyCode: item.currencyCode,
}, },
options: [], options: [],
sku: item.sku sku: item.sku,
} }
} }
@ -93,15 +93,15 @@ export function normalizeCart(order: CartFragment): Cart {
subTotal: order.subTotalWithTax / 100, subTotal: order.subTotalWithTax / 100,
total: order.totalWithTax / 100, total: order.totalWithTax / 100,
customerId: order.customer?.id as number, customerId: order.customer?.id as number,
items: order.lines?.map(l => ({ items: order.lines?.map((l) => ({
id: l.id, id: l.id,
name: l.productVariant.name, name: l.productVariant.name,
quantity: l.quantity, quantity: l.quantity,
url: l.productVariant.product.slug, url: l.productVariant.product.slug,
variantId: l.productVariant.id, variantId: l.productVariant.id,
productId: l.productVariant.productId, productId: l.productVariant.productId,
images: [{ url: l.featuredAsset?.preview || '' }], images: [{ url: l.featuredAsset?.preview + '?preset=thumb' || '' }],
prices: [] prices: [],
})) })),
} }
} }

View File

@ -40,7 +40,7 @@ async function getProduct({
config, config,
}: { }: {
query?: string query?: string
variables: { slug: string; } variables: { slug: string }
config?: VendureConfig config?: VendureConfig
preview?: boolean preview?: boolean
}): Promise<Product | {} | any> { }): Promise<Product | {} | any> {
@ -57,10 +57,16 @@ async function getProduct({
name: product.name, name: product.name,
description: product.description, description: product.description,
slug: product.slug, slug: product.slug,
images: product.assets.map((a: any) => ({ url: a.preview, alt: a.name })), images: product.assets.map((a: any) => ({
url: a.preview,
alt: a.name,
})),
variants: product.variants.map((v: any) => ({ variants: product.variants.map((v: any) => ({
id: v.id, id: v.id,
options: v.options.map((o: any) => ({ displayName: o.name, values: [] })), options: v.options.map((o: any) => ({
displayName: o.name,
values: [],
})),
})), })),
price: { price: {
value: product.variants[0].priceWithTax / 100, value: product.variants[0].priceWithTax / 100,
@ -68,14 +74,13 @@ async function getProduct({
}, },
options: product.optionGroups.map((og: any) => ({ options: product.optionGroups.map((og: any) => ({
displayName: og.name, displayName: og.name,
values: og.options.map((o: any) => ({ label: o.name + ' hello' })), values: og.options.map((o: any) => ({ label: o.name })),
})), })),
} },
}; }
} }
return {} return {}
} }
export default getProduct export default getProduct