mirror of
https://github.com/vercel/commerce.git
synced 2025-07-04 04:01:21 +00:00
Type Spree variants and line items and temporarily remove height, width and depth
This commit is contained in:
parent
bf4adbdd2c
commit
c9323443ce
@ -44,3 +44,47 @@ export interface OptionTypeAttr extends JsonApiDocument {
|
|||||||
filterable: boolean
|
filterable: boolean
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LineItemAttr extends JsonApiDocument {
|
||||||
|
attributes: {
|
||||||
|
name: string
|
||||||
|
quantity: number
|
||||||
|
slug: string
|
||||||
|
options_text: string
|
||||||
|
price: string
|
||||||
|
currency: string
|
||||||
|
display_price: string
|
||||||
|
total: string
|
||||||
|
display_total: string
|
||||||
|
adjustment_total: string
|
||||||
|
display_adjustment_total: string
|
||||||
|
additional_tax_total: string
|
||||||
|
display_additional_tax_total: string
|
||||||
|
discounted_amount: string
|
||||||
|
display_discounted_amount: string
|
||||||
|
pre_tax_amount: string
|
||||||
|
display_pre_tax_amount: string
|
||||||
|
promo_total: string
|
||||||
|
display_promo_total: string
|
||||||
|
included_tax_total: string
|
||||||
|
display_inluded_tax_total: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface VariantAttr extends JsonApiDocument {
|
||||||
|
attributes: {
|
||||||
|
sku: string
|
||||||
|
price: string
|
||||||
|
currency: string
|
||||||
|
display_price: string
|
||||||
|
weight: string
|
||||||
|
height: string
|
||||||
|
width: string
|
||||||
|
depth: string
|
||||||
|
is_master: boolean
|
||||||
|
options_text: string
|
||||||
|
purchasable: boolean
|
||||||
|
in_stock: boolean
|
||||||
|
backorderable: boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -7,7 +7,6 @@ import type {
|
|||||||
import MissingLineItemVariantError from '@framework/errors/MissingLineItemVariantError'
|
import MissingLineItemVariantError from '@framework/errors/MissingLineItemVariantError'
|
||||||
import { requireConfigValue } from '@framework/isomorphic-config'
|
import { requireConfigValue } from '@framework/isomorphic-config'
|
||||||
import type {
|
import type {
|
||||||
JsonApiDocument,
|
|
||||||
JsonApiListResponse,
|
JsonApiListResponse,
|
||||||
JsonApiSingleResponse,
|
JsonApiSingleResponse,
|
||||||
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
|
} from '@spree/storefront-api-v2-sdk/types/interfaces/JsonApi'
|
||||||
@ -17,7 +16,11 @@ import type { RelationType } from '@spree/storefront-api-v2-sdk/types/interfaces
|
|||||||
import createGetAbsoluteImageUrl from './create-get-absolute-image-url'
|
import createGetAbsoluteImageUrl from './create-get-absolute-image-url'
|
||||||
import getMediaGallery from './get-media-gallery'
|
import getMediaGallery from './get-media-gallery'
|
||||||
import { findIncluded, findIncludedOfType } from './find-json-api-documents'
|
import { findIncluded, findIncludedOfType } from './find-json-api-documents'
|
||||||
import type { OptionTypeAttr } from '@framework/types'
|
import type {
|
||||||
|
LineItemAttr,
|
||||||
|
OptionTypeAttr,
|
||||||
|
VariantAttr,
|
||||||
|
} from '@framework/types'
|
||||||
|
|
||||||
const isColorProductOption = (productOptionType: OptionTypeAttr) => {
|
const isColorProductOption = (productOptionType: OptionTypeAttr) => {
|
||||||
return productOptionType.attributes.presentation === 'Color'
|
return productOptionType.attributes.presentation === 'Color'
|
||||||
@ -25,7 +28,7 @@ const isColorProductOption = (productOptionType: OptionTypeAttr) => {
|
|||||||
|
|
||||||
const normalizeVariant = (
|
const normalizeVariant = (
|
||||||
spreeSuccessResponse: JsonApiSingleResponse | JsonApiListResponse,
|
spreeSuccessResponse: JsonApiSingleResponse | JsonApiListResponse,
|
||||||
spreeVariant: JsonApiDocument
|
spreeVariant: VariantAttr
|
||||||
): ProductVariant => {
|
): ProductVariant => {
|
||||||
const productIdentifier = spreeVariant.relationships.product
|
const productIdentifier = spreeVariant.relationships.product
|
||||||
.data as RelationType
|
.data as RelationType
|
||||||
@ -81,18 +84,22 @@ const normalizeVariant = (
|
|||||||
image: lineItemImage,
|
image: lineItemImage,
|
||||||
isInStock: spreeVariant.attributes.in_stock,
|
isInStock: spreeVariant.attributes.in_stock,
|
||||||
availableForSale: spreeVariant.attributes.purchasable,
|
availableForSale: spreeVariant.attributes.purchasable,
|
||||||
weight: spreeVariant.attributes.weight,
|
...(spreeVariant.attributes.weight === '0.0'
|
||||||
height: spreeVariant.attributes.height,
|
? {}
|
||||||
width: spreeVariant.attributes.width,
|
: {
|
||||||
depth: spreeVariant.attributes.depth,
|
weight: {
|
||||||
|
value: parseFloat(spreeVariant.attributes.weight),
|
||||||
|
unit: 'KILOGRAMS',
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
// TODO: Add height, width and depth when Measurement type allows distance measurements.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const normalizeLineItem = (
|
const normalizeLineItem = (
|
||||||
spreeSuccessResponse: JsonApiSingleResponse | JsonApiListResponse,
|
spreeSuccessResponse: JsonApiSingleResponse | JsonApiListResponse,
|
||||||
spreeLineItem: JsonApiDocument
|
spreeLineItem: LineItemAttr
|
||||||
): LineItem => {
|
): LineItem => {
|
||||||
//TODO: Replace JsonApiDocument type in spreeLineItem with more specific, new Spree line item item
|
|
||||||
const variantIdentifier = spreeLineItem.relationships.variant
|
const variantIdentifier = spreeLineItem.relationships.variant
|
||||||
.data as RelationType
|
.data as RelationType
|
||||||
const variant = findIncluded(
|
const variant = findIncluded(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user