Guide
You can integrate Algolia search into Catalyst storefronts to help shoppers search all products, categories, and more.
This guide demonstrates a basic integration and provides example code for global product search that you can add to the core code of your Catalyst storefront, or to apps/core
in the Catalyst monorepo.
For a working demo of an Algolia integration with Catalyst, see the following example:
https://catalyst-algolia.vercel.app/
To follow this guide, you need the following:
- Node.js 18+
- A Node.js package manager, such as
npm
,pnpm
, oryarn
- Working knowledge of Next.js
- An Algolia account
- A BigCommerce store or sandbox store
-
Configure the core codebase for the Catalyst storefront and get it running in dev mode. See CLI setup for quickstart instructions. If you configure Catalyst using the Monorepo, make sure the storefront is associated with a BigCommerce store channel.
-
At the top of your Algolia dashboard, create an Algolia app that you intend to associate exclusively with your Catalyst storefront channel.
-
Install the BigCommerce Algolia app and associate it with your Catalyst channel. Add the following Algolia-specific environment variables to the existing
.env.local
file in your Catalyst storefront. For more about other Catalyst environment variables, see Environment variables.
Environment variable | Value |
---|---|
NEXT_PUBLIC_ALGOLIA_APP_ID |
Your Algolia app ID |
NEXT_PUBLIC_ALGOLIA_API_KEY |
Your Algolia Search Only API key. You can find this value in the API keys > All API keys section of your Algolia account dashboard. If this is your first time using the new Algolia app, visit the Search > Index section of the Algolia dashboard and click the Refresh index button to generate your search index. |
NEXT_PUBLIC_ALGOLIA_INDEXNAME |
Your Algolia Search Index name. By Defualt the BigCommerce Algolia app uses the index name Bigcommerce. |
- Install the following dependencies in your Catalyst storefront:
npm i react-instantsearch
npm i -S algoliasearch
- Update the files in your Catalyst
/components/quick-search
directory to include the code from the Algolia example repo/components/quick-search
directory
- Add the
algoliaSearchBox.tsx
andalgoliaSearchHits.tsx
files - Update the
index.tsx
file
Your storefront's file tree will mirror the following screenshot.
-
In
components/quick-search/index.tsx
, update the value ofalgoliaClient
to use your correctindexName
. By default, the BigCommerce Algolia app names the search indexBigCommerce
. -
Start your Catalyst storefront app in dev mode. Check the QuickSearch box to see the data supplied by the Algolia app index.
pnpm run dev