A simple React app for testing various API functions from the browser. This example calls the product projections Search API to fetch a list of products. Optionally, you can use commercetools' price selection logic to fetch the correct price for a product using a combination of currency, country, channel, and customer group parameters
The motivation for building this application is to provide some working examples of working with commercetools APIs from a simple, bare-bones, React front-end.
The code to authenticate with commercetools and call the APIs is encapsulated inside src/commercetools-ts.js. This is a simple "wrapper" for the commercetools TypeScript SDK, exposing apiRoot (with project key)
src/components/home:
Home page / search page. Displays an input form that lets the user search for products
src/components/product-detail:
Display a single product & variants
src/components/context:
This displays a set of input elements to allow the user to choose the 'context' for product/price lookup: Country, Currency, Channel, and Customer Group.
src/components/cart:
Display the shopping cart with detailed discount information.
src/components/discount-detail:
Searches for product that are a part of the given discount id.
Because this application has some additional functionality beyond a 'traditional' web app, you'll need additional scopes when creating the developer key.
First, start with the "Mobile & Single Page Application" template, and then add
under View:
- Products (all)
- Project Settings
- Stores
Download the Environment Variables format, remove the 'export ' and replace CTP_ with REACT_APP_
Install Dependencies:
yarn
yarn start
Runs the app in development mode.
Open http://localhost:3000 to view it in the browser.