mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 23:46:58 +00:00
WIP pages implementation & fix add to cart variant ID bug
Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
parent
16e475067b
commit
3112c7fc80
@ -49,7 +49,7 @@ const ProductView: FC<Props> = ({ product }) => {
|
|||||||
|
|
||||||
await addItem({
|
await addItem({
|
||||||
productId: String(product.id),
|
productId: String(product.id),
|
||||||
variantId: String(selectedVariant.id),
|
variantId: String(selectedVariant.sku),
|
||||||
pricing: {
|
pricing: {
|
||||||
amount: selectedVariant.price,
|
amount: selectedVariant.price,
|
||||||
currencyCode: product.price.currencyCode,
|
currencyCode: product.price.currencyCode,
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { getConfig, ReactionCommerceConfig } from '../api'
|
import { getConfig, ReactionCommerceConfig } from '../api'
|
||||||
import { PageEdge } from '../schema'
|
import { NavigationTreeItem } from '../schema'
|
||||||
import { getAllPagesQuery } from '../utils/queries'
|
import { getAllPagesQuery } from '../utils/queries'
|
||||||
|
|
||||||
type Variables = {
|
type Variables = {
|
||||||
@ -23,20 +23,32 @@ const getAllPages = async (options?: {
|
|||||||
config: ReactionCommerceConfig
|
config: ReactionCommerceConfig
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
}): Promise<ReturnType> => {
|
}): Promise<ReturnType> => {
|
||||||
// let { config, variables = { first: 250 } } = options ?? {}
|
let { config, variables } = options ?? {}
|
||||||
// config = getConfig(config)
|
config = getConfig(config)
|
||||||
// const { locale } = config
|
const { locale } = config
|
||||||
// const { data } = await config.fetch(getAllPagesQuery, { variables })
|
console.log('locale', locale)
|
||||||
//
|
const { data } = await config.fetch(getAllPagesQuery, {
|
||||||
// const pages = data.pages?.edges?.map(
|
variables: {
|
||||||
// ({ node: { title: name, handle, ...node } }: PageEdge) => ({
|
...variables,
|
||||||
// ...node,
|
shopId: config.shopId,
|
||||||
// url: `/${locale}/${handle}`,
|
},
|
||||||
// name,
|
})
|
||||||
// })
|
|
||||||
// )
|
|
||||||
|
|
||||||
return { pages: [] }
|
const pages = data.shop?.defaultNavigationTree?.items?.map(
|
||||||
|
({
|
||||||
|
navigationItem: {
|
||||||
|
_id: id,
|
||||||
|
data: { contentForLanguage: name, url },
|
||||||
|
},
|
||||||
|
}: NavigationTreeItem) => ({
|
||||||
|
id,
|
||||||
|
url,
|
||||||
|
name,
|
||||||
|
body: '',
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
return { pages }
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getAllPages
|
export default getAllPages
|
||||||
|
@ -210,6 +210,10 @@ function normalizeLineItem({
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function normalizeCustomer(viewer: Account): Customer {
|
export function normalizeCustomer(viewer: Account): Customer {
|
||||||
|
if (!viewer) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
firstName: viewer.firstName ?? '',
|
firstName: viewer.firstName ?? '',
|
||||||
lastName: viewer.lastName ?? '',
|
lastName: viewer.lastName ?? '',
|
||||||
|
@ -1,11 +1,18 @@
|
|||||||
export const getAllPagesQuery = /* GraphQL */ `
|
export const getAllPagesQuery = /* GraphQL */ `
|
||||||
query getAllPages($first: Int = 250) {
|
query getAllPages($shopId: ID!, $language: String! = "en") {
|
||||||
pages(first: $first) {
|
shop(id: $shopId) {
|
||||||
edges {
|
defaultNavigationTree(language: $language) {
|
||||||
node {
|
items {
|
||||||
id
|
navigationItem {
|
||||||
title
|
_id
|
||||||
handle
|
data {
|
||||||
|
contentForLanguage
|
||||||
|
classNames
|
||||||
|
url
|
||||||
|
isUrlRelative
|
||||||
|
shouldOpenInNewWindow
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user