Initial work, copied from the Shopify provider

This commit is contained in:
Patryk Zawadzki
2021-04-14 14:09:40 +02:00
committed by Zaiste
parent 685fb932db
commit ffe5a1c20e
79 changed files with 16981 additions and 1 deletions

View File

@@ -0,0 +1,40 @@
import { SaleorConfig } 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: SaleorConfig): 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