Use original product image by default instead of resized

This commit is contained in:
tniezg 2021-08-31 13:35:24 +02:00
parent 92bb7bcf51
commit e9397bcb72
2 changed files with 12 additions and 2 deletions

View File

@ -26,10 +26,14 @@ export interface ImageStyle {
url: string
width: string
height: string
size: string
}
export interface SpreeProductImage extends JsonApiDocument {
attributes: {
position: number
alt: string
original_url: string
styles: ImageStyle[]
}
}

View File

@ -2,13 +2,19 @@ import { SpreeProductImage } from '../types'
import getImageUrl from './get-image-url'
const createGetAbsoluteImageUrl =
(host: string) =>
(host: string, useOriginalImageSize: boolean = true) =>
(
image: SpreeProductImage,
minWidth: number,
minHeight: number
): string | null => {
const url = getImageUrl(image, minWidth, minHeight)
let url
if (useOriginalImageSize) {
url = image.attributes.original_url || null
} else {
url = getImageUrl(image, minWidth, minHeight)
}
if (url === null) {
return null