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({
productId: String(product.id),
variantId: String(selectedVariant.id),
variantId: String(selectedVariant.sku),
pricing: {
amount: selectedVariant.price,
currencyCode: product.price.currencyCode,

View File

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

View File

@ -210,6 +210,10 @@ function normalizeLineItem({
}
export function normalizeCustomer(viewer: Account): Customer {
if (!viewer) {
return {}
}
return {
firstName: viewer.firstName ?? '',
lastName: viewer.lastName ?? '',

View File

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