mirror of
https://github.com/vercel/commerce.git
synced 2025-07-26 19:51:23 +00:00
Merge branch 'agnostic' of https://github.com/vercel/commerce into agnostic
This commit is contained in:
13
framework/shopify/utils/storage.ts
Normal file
13
framework/shopify/utils/storage.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const getCheckoutIdFromStorage = (token: string) => {
|
||||
if (window && window.sessionStorage) {
|
||||
return window.sessionStorage.getItem(token)
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export const setCheckoutIdInStorage = (token: string, id: string | number) => {
|
||||
if (window && window.sessionStorage) {
|
||||
return window.sessionStorage.setItem(token, id + '')
|
||||
}
|
||||
}
|
60
framework/shopify/utils/to-commerce-products.ts
Normal file
60
framework/shopify/utils/to-commerce-products.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { Product, Image } from '../types'
|
||||
|
||||
export default function toCommerceProducts(products: Product[]) {
|
||||
return products.map((product: Product) => {
|
||||
return {
|
||||
id: product.id,
|
||||
entityId: product.id,
|
||||
name: product.title,
|
||||
slug: product.handle,
|
||||
title: product.title,
|
||||
vendor: product.vendor,
|
||||
description: product.descriptionHtml,
|
||||
path: `/${product.handle}`,
|
||||
price: {
|
||||
value: +product.variants[0].price,
|
||||
currencyCode: 'USD', // TODO
|
||||
},
|
||||
images: product.images.map((image: Image) => {
|
||||
return {
|
||||
url: image.src,
|
||||
}
|
||||
}),
|
||||
variants: product.variants.map((variant) => {
|
||||
return {
|
||||
id: variant.id,
|
||||
options: variant.selectedOptions.map((selectedOption) => {
|
||||
return {
|
||||
__typename: 'MultipleChoiceOption',
|
||||
displayName: selectedOption.name,
|
||||
values: [
|
||||
{
|
||||
node: {
|
||||
id: variant.id,
|
||||
label: selectedOption.value,
|
||||
},
|
||||
},
|
||||
],
|
||||
}
|
||||
}),
|
||||
}
|
||||
}),
|
||||
productOptions: product.options.map((option) => {
|
||||
return {
|
||||
__typename: 'MultipleChoiceOption',
|
||||
displayName: option.name,
|
||||
values: option.values.map((value) => {
|
||||
return {
|
||||
node: {
|
||||
entityId: 1,
|
||||
label: value.value,
|
||||
hexColors: [value.value],
|
||||
},
|
||||
}
|
||||
}),
|
||||
}
|
||||
}),
|
||||
options: [],
|
||||
}
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user