mirror of
https://github.com/vercel/commerce.git
synced 2025-06-19 05:31:22 +00:00
Merge branch 'shopify-i18n' of https://github.com/cond0r/commerce into shopify-i18n
This commit is contained in:
commit
fd57e5029b
@ -10,11 +10,15 @@ export const handler: SWRHook<Customer | null> = {
|
|||||||
query: getCustomerQuery,
|
query: getCustomerQuery,
|
||||||
},
|
},
|
||||||
async fetcher({ options, fetch }) {
|
async fetcher({ options, fetch }) {
|
||||||
const data = await fetch<any | null>({
|
const customerAccessToken = getCustomerToken()
|
||||||
...options,
|
if (customerAccessToken) {
|
||||||
variables: { customerAccessToken: getCustomerToken() },
|
const data = await fetch({
|
||||||
})
|
...options,
|
||||||
return data.customer ?? null
|
variables: { customerAccessToken: getCustomerToken() },
|
||||||
|
})
|
||||||
|
return data.customer
|
||||||
|
}
|
||||||
|
return null
|
||||||
},
|
},
|
||||||
useHook: ({ useData }) => (input) => {
|
useHook: ({ useData }) => (input) => {
|
||||||
return useData({
|
return useData({
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { getConfig, ShopifyConfig } from '../api'
|
import { getConfig, ShopifyConfig } from '../api'
|
||||||
import fetchAllProducts from '../api/utils/fetch-all-products'
|
|
||||||
import { ProductEdge } from '../schema'
|
import { ProductEdge } from '../schema'
|
||||||
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query'
|
||||||
|
|
||||||
@ -20,21 +19,22 @@ const getAllProductPaths = async (options?: {
|
|||||||
config?: ShopifyConfig
|
config?: ShopifyConfig
|
||||||
preview?: boolean
|
preview?: boolean
|
||||||
}): Promise<ReturnType> => {
|
}): Promise<ReturnType> => {
|
||||||
let { config, variables = { first: 250 } } = options ?? {}
|
let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } =
|
||||||
|
options ?? {}
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
|
|
||||||
const products = await fetchAllProducts({
|
const { data } = await config.fetch(getAllProductsPathsQuery, {
|
||||||
config,
|
|
||||||
query: getAllProductsPathsQuery,
|
|
||||||
variables,
|
variables,
|
||||||
})
|
})
|
||||||
|
|
||||||
return {
|
return {
|
||||||
products: products?.map(({ node: { handle } }: ProductEdge) => ({
|
products: data.products?.edges?.map(
|
||||||
node: {
|
({ node: { handle } }: ProductEdge) => ({
|
||||||
path: `/${handle}`,
|
node: {
|
||||||
},
|
path: `/${handle}`,
|
||||||
})),
|
},
|
||||||
|
})
|
||||||
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,6 @@ const getAllProducts = async (options: {
|
|||||||
}): Promise<ReturnType> => {
|
}): Promise<ReturnType> => {
|
||||||
let { config, variables = { first: 250 } } = options ?? {}
|
let { config, variables = { first: 250 } } = options ?? {}
|
||||||
config = getConfig(config)
|
config = getConfig(config)
|
||||||
let products: Product[] = []
|
|
||||||
|
|
||||||
const { data } = await config!.fetch<QueryRoot, QueryRootProductsArgs>(
|
const { data } = await config!.fetch<QueryRoot, QueryRootProductsArgs>(
|
||||||
getAllProductsQuery,
|
getAllProductsQuery,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user