mirror of
https://github.com/vercel/commerce.git
synced 2025-05-18 15:36: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({
|
||||
productId: String(product.id),
|
||||
variantId: String(selectedVariant.id),
|
||||
variantId: String(selectedVariant.sku),
|
||||
pricing: {
|
||||
amount: selectedVariant.price,
|
||||
currencyCode: product.price.currencyCode,
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { getConfig, ReactionCommerceConfig } from '../api'
|
||||
import { PageEdge } from '../schema'
|
||||
import { NavigationTreeItem } from '../schema'
|
||||
import { getAllPagesQuery } from '../utils/queries'
|
||||
|
||||
type Variables = {
|
||||
@ -23,20 +23,32 @@ const getAllPages = async (options?: {
|
||||
config: ReactionCommerceConfig
|
||||
preview?: boolean
|
||||
}): Promise<ReturnType> => {
|
||||
// let { config, variables = { first: 250 } } = options ?? {}
|
||||
// config = getConfig(config)
|
||||
// const { locale } = config
|
||||
// const { data } = await config.fetch(getAllPagesQuery, { variables })
|
||||
//
|
||||
// const pages = data.pages?.edges?.map(
|
||||
// ({ node: { title: name, handle, ...node } }: PageEdge) => ({
|
||||
// ...node,
|
||||
// url: `/${locale}/${handle}`,
|
||||
// name,
|
||||
// })
|
||||
// )
|
||||
let { config, variables } = options ?? {}
|
||||
config = getConfig(config)
|
||||
const { locale } = config
|
||||
console.log('locale', locale)
|
||||
const { data } = await config.fetch(getAllPagesQuery, {
|
||||
variables: {
|
||||
...variables,
|
||||
shopId: config.shopId,
|
||||
},
|
||||
})
|
||||
|
||||
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
|
||||
|
@ -210,6 +210,10 @@ function normalizeLineItem({
|
||||
}
|
||||
|
||||
export function normalizeCustomer(viewer: Account): Customer {
|
||||
if (!viewer) {
|
||||
return {}
|
||||
}
|
||||
|
||||
return {
|
||||
firstName: viewer.firstName ?? '',
|
||||
lastName: viewer.lastName ?? '',
|
||||
|
@ -1,11 +1,18 @@
|
||||
export const getAllPagesQuery = /* GraphQL */ `
|
||||
query getAllPages($first: Int = 250) {
|
||||
pages(first: $first) {
|
||||
edges {
|
||||
node {
|
||||
id
|
||||
title
|
||||
handle
|
||||
query getAllPages($shopId: ID!, $language: String! = "en") {
|
||||
shop(id: $shopId) {
|
||||
defaultNavigationTree(language: $language) {
|
||||
items {
|
||||
navigationItem {
|
||||
_id
|
||||
data {
|
||||
contentForLanguage
|
||||
classNames
|
||||
url
|
||||
isUrlRelative
|
||||
shouldOpenInNewWindow
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user