mirror of
https://github.com/vercel/commerce.git
synced 2025-07-22 20:26:49 +00:00
Shopify Provider (#186)
* Start of Shopify provider * add missing comment to documentation * add missing env vars to documentation * update reference to types file
This commit is contained in:
37
framework/shopify/product/get-product.ts
Normal file
37
framework/shopify/product/get-product.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import Client from 'shopify-buy'
|
||||
import { ShopifyConfig } from '../api'
|
||||
import { Product } from '../types'
|
||||
import toCommerceProducts from '../utils/to-commerce-products'
|
||||
|
||||
export type ProductNode = Product
|
||||
|
||||
type Variables = {
|
||||
slug: string
|
||||
}
|
||||
|
||||
type Options = {
|
||||
variables: Variables
|
||||
config: ShopifyConfig
|
||||
preview?: boolean
|
||||
}
|
||||
|
||||
type ReturnType = {
|
||||
product: any
|
||||
}
|
||||
|
||||
const getProduct = async (options: Options): Promise<ReturnType> => {
|
||||
const { variables, config } = options
|
||||
|
||||
const client = Client.buildClient({
|
||||
storefrontAccessToken: config.apiToken,
|
||||
domain: config.commerceUrl,
|
||||
})
|
||||
|
||||
const res = (await client.product.fetchByHandle(variables.slug)) as Product
|
||||
|
||||
return {
|
||||
product: toCommerceProducts([res])[0],
|
||||
}
|
||||
}
|
||||
|
||||
export default getProduct
|
Reference in New Issue
Block a user