diff --git a/framework/shopify/customer/use-customer.tsx b/framework/shopify/customer/use-customer.tsx index 137f0da74..7b600838e 100644 --- a/framework/shopify/customer/use-customer.tsx +++ b/framework/shopify/customer/use-customer.tsx @@ -10,11 +10,15 @@ export const handler: SWRHook = { query: getCustomerQuery, }, async fetcher({ options, fetch }) { - const data = await fetch({ - ...options, - variables: { customerAccessToken: getCustomerToken() }, - }) - return data.customer ?? null + const customerAccessToken = getCustomerToken() + if (customerAccessToken) { + const data = await fetch({ + ...options, + variables: { customerAccessToken: getCustomerToken() }, + }) + return data.customer + } + return null }, useHook: ({ useData }) => (input) => { return useData({ diff --git a/framework/shopify/product/get-all-product-paths.ts b/framework/shopify/product/get-all-product-paths.ts index 4431d1e53..e8ee04065 100644 --- a/framework/shopify/product/get-all-product-paths.ts +++ b/framework/shopify/product/get-all-product-paths.ts @@ -1,6 +1,4 @@ -import { Product } from '@commerce/types' import { getConfig, ShopifyConfig } from '../api' -import fetchAllProducts from '../api/utils/fetch-all-products' import { ProductEdge } from '../schema' import getAllProductsPathsQuery from '../utils/queries/get-all-products-paths-query' @@ -21,21 +19,22 @@ const getAllProductPaths = async (options?: { config?: ShopifyConfig preview?: boolean }): Promise => { - let { config, variables = { first: 250 } } = options ?? {} + let { config, variables = { first: 100, sortKey: 'BEST_SELLING' } } = + options ?? {} config = getConfig(config) - const products = await fetchAllProducts({ - config, - query: getAllProductsPathsQuery, + const { data } = await config.fetch(getAllProductsPathsQuery, { variables, }) return { - products: products?.map(({ node: { handle } }: ProductEdge) => ({ - node: { - path: `/${handle}`, - }, - })), + products: data.products?.edges?.map( + ({ node: { handle } }: ProductEdge) => ({ + node: { + path: `/${handle}`, + }, + }) + ), } } diff --git a/framework/shopify/product/get-all-products.ts b/framework/shopify/product/get-all-products.ts index 14e486563..3915abebf 100644 --- a/framework/shopify/product/get-all-products.ts +++ b/framework/shopify/product/get-all-products.ts @@ -27,10 +27,9 @@ const getAllProducts = async (options: { { variables } ) - const products = - data.products?.edges?.map(({ node: p }: ProductEdge) => - normalizeProduct(p) - ) ?? [] + const products = data.products?.edges?.map(({ node: p }: ProductEdge) => + normalizeProduct(p) + ) return { products,