WIP pages implementation & fix add to cart variant ID bug

Signed-off-by: Loan Laux <loan@outgrow.io>
This commit is contained in:
Loan Laux 2021-05-17 15:28:04 +04:00
parent 16e475067b
commit 3112c7fc80
No known key found for this signature in database
GPG Key ID: AF9E9BD6548AD52E
4 changed files with 45 additions and 22 deletions

View File

@ -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,

View File

@ -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

View File

@ -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 ?? '',

View File

@ -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
}
}
} }
} }
} }