From 990bdf1e6a610b6b047cffdcdec7295dff0e9568 Mon Sep 17 00:00:00 2001
From: Catalin Pinte <catalin.pinte@vercel.com>
Date: Thu, 6 Oct 2022 17:08:58 +0300
Subject: [PATCH] Fix bigcommerce brands (#837)

---
 packages/bigcommerce/src/lib/normalize.ts       | 6 ++++--
 packages/bigcommerce/src/product/use-search.tsx | 6 +++---
 site/components/search.tsx                      | 2 +-
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/packages/bigcommerce/src/lib/normalize.ts b/packages/bigcommerce/src/lib/normalize.ts
index 1cf20b136..b01de3233 100644
--- a/packages/bigcommerce/src/lib/normalize.ts
+++ b/packages/bigcommerce/src/lib/normalize.ts
@@ -139,10 +139,12 @@ export function normalizeCategory(category: BCCategory): Category {
 }
 
 export function normalizeBrand(brand: BCBrand): Brand {
+  const path = brand.node.path.replace('/brands/', '')
+  const slug = getSlug(path)
   return {
     id: `${brand.node.entityId}`,
     name: brand.node.name,
-    slug: getSlug(brand.node.path),
-    path: brand.node.path,
+    slug,
+    path: `/${slug}`,
   }
 }
diff --git a/packages/bigcommerce/src/product/use-search.tsx b/packages/bigcommerce/src/product/use-search.tsx
index 9fa275f19..9edd47f77 100644
--- a/packages/bigcommerce/src/product/use-search.tsx
+++ b/packages/bigcommerce/src/product/use-search.tsx
@@ -6,8 +6,8 @@ export default useSearch as UseSearch<typeof handler>
 
 export type SearchProductsInput = {
   search?: string
-  categoryId?: number | string
-  brandId?: number
+  categoryId?: string
+  brandId?: string
   sort?: string
   locale?: string
 }
@@ -24,7 +24,7 @@ export const handler: SWRHook<SearchProductsHook> = {
     if (search) url.searchParams.set('search', search)
     if (Number.isInteger(Number(categoryId)))
       url.searchParams.set('categoryId', String(categoryId))
-    if (Number.isInteger(brandId))
+    if (Number.isInteger(Number(brandId)))
       url.searchParams.set('brandId', String(brandId))
     if (sort) url.searchParams.set('sort', sort)
 
diff --git a/site/components/search.tsx b/site/components/search.tsx
index c57f094d1..29b992c4a 100644
--- a/site/components/search.tsx
+++ b/site/components/search.tsx
@@ -50,7 +50,7 @@ export default function Search({ categories, brands }: SearchPropsType) {
   const { data, error } = useSearch({
     search: typeof q === 'string' ? q : '',
     categoryId: activeCategory?.id,
-    brandId: (activeBrand as any)?.id,
+    brandId: activeBrand?.id,
     sort: typeof sort === 'string' ? sort : '',
     locale,
   })