commerce/framework/shopify/utils/get-vendors.ts
cond0r f3b9d94b2f
Shopify provider fixes (#225)
* Changed to query page by id

* Fixed page query, Changed use-search GraphQl query

* Update use-search.tsx

* remove unused util

* Changed cookie expiration

* Update tsconfig.json

* Fix add to cart & prepare for user activation

* Update helpers.ts

* Update helpers.ts

* Changes, fix Shopify GraphQL deprecations

* Update checkout-to-cart.ts

* Default to BigCommerce

* Update index.ts

* Fixed types
2021-03-16 10:55:24 -03:00

41 lines
859 B
TypeScript

import { ShopifyConfig } from '../api'
import fetchAllProducts from '../api/utils/fetch-all-products'
import getAllProductVendors from './queries/get-all-product-vendors-query'
export type Brand = {
entityId: string
name: string
path: string
}
export type BrandEdge = {
node: Brand
}
export type Brands = BrandEdge[]
const getVendors = async (config: ShopifyConfig): Promise<BrandEdge[]> => {
const vendors = await fetchAllProducts({
config,
query: getAllProductVendors,
variables: {
first: 250,
},
})
let vendorsStrings = vendors.map(({ node: { vendor } }) => vendor)
return [...new Set(vendorsStrings)].map((v) => {
const id = v.replace(/\s+/g, '-').toLowerCase()
return {
node: {
entityId: id,
name: v,
path: `brands/${id}`,
},
}
})
}
export default getVendors