/dynamic-plp-front-end

Next.js sample front end to use the dynamic PLP POC

Primary LanguageTypeScript

This is a Next.js project bootstrapped with create-next-app.

Prerequisites

Code

Commerce-service with Dynamic PLP changes running locally using this branch: https://github.com/coveo/commerce-service/tree/feat/com-1710-dynamic-plp-poc Product Listing headless controller with Dynamic PLP changes from this branch: https://github.com/coveo/ui-kit/tree/feat/com-1710-dynamic-plp-poc

Create a Symlink to the headless library in this project by first using npm link in the headless package. And then do a npm link @coveo/headless in this project. Detailed information in the npm instructions.

Demo environment

Ensure you have an organisation setup on the platform. And provide the api key (TODO) in environment variables. Setup a catalog and fill it with products from mystore-products.json. Add 2 PLP's names Catalog and Sales.

Demo setup

We hava a catalog setup with 6 products. Sneakers from Nike, Puma and Adidas. One PLP named Catalog to show the whole content, being 6 products. 2 of each brand. One PLP names Sales that filters products with a price less then 100. Which gives 3 products. 1 of each brand.

Demo

The POC implementation is based on the concept of dynamic routing in the front-end world. We take the path withouth the slug and use it as a way to indentify the PLP specified as rooturl. It's used on the backend to extract the slug from the full url. The slug parts are used as values for the dynamic part of the PLP. The fields segments to resolve the slug values are specified in the slug options. We choose to let the client specify it for ease of implementation and experimentation. It could be easily stored or configured together with the PLP definition if we want to.

You can show show the content of the PLP's by navigating to http://localhost:3000/pages/catalog or http://localhost:3000/pages/sales. The dynamic part is specified by the client. Currently it's setup on ec_brand. You can change it to a different field as desired. Now you can dynamically navigate to the brand pages inside the product listing. For example http://localhost:3000/pages/sales/nike should give you only the Nike sneaker that's on sale. Or doing the same for the catalog PLP will give you 2 Nike sneakers. And so on. Depending on the amount of fields specified by the client you can stack them like /nike/puma and so on. In the example implementation there are 3 fields ec_brand specified. So you're able to stack all 3 brands in the example. You can change the field to something different if you want the dynamic field to be something different like gender or category for example.

Getting Started

First, run the development server:

npm run dev
# or
yarn dev

Open http://localhost:3000 with your browser to see the result.

You can start editing the page by modifying pages/index.tsx. The page auto-updates as you edit the file.

API routes can be accessed on http://localhost:3000/api/hello. This endpoint can be edited in pages/api/hello.ts.

The pages/api directory is mapped to /api/*. Files in this directory are treated as API routes instead of React pages.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.