Using Commercetools to build your e-commerce website

Written By Chetan Iterate ()

Updated at January 20th, 2021

The commercetools solutions provide a one-stop service to set up your own shop on the internet, it handles your purchase, pricing, and checkouts, Interplay makes it much simpler to integrate its APIs and services and easier to handle transactions, so for this project, we will be creating an e-commerce website backend.

Prerequisites :

1) Commercetools merchant account, you can make it in mc.commercetools.com

2) Register if not having an account

3) Got to "Dashboard" and create a new project on a name your choice

4) After creating your project the "ProjectKey" gets generated, also take note of "clientID" and "clientSecret"

Steps :

1) Get customer details by customerID :

Search nodes :

HTTP : 

Get-auth-token

Get-customer-by-id


HTTP response

Drop them in the editor and connect them as shown below:


Edit the node HTTP to capture customer information by ID :

Enter your Project Key, ClientID, and Client Secret Keys in Get-auth-node and it is very important to authenticate every request and easy by reusing this node.

Generated Token is used for assigning cart to customer and transaction.


This Get-auth-token is always needed for interaction with commercetools API hence we can reuse this exact node by copy-pasting with other nodes.

Get-customer-by-id node hits API to commercetools to get the customer data by its ID and key.


the final flow should be similar to this :


2) Fetch all categories from the project :

find "Get-categories" node


and make flow with other three nodes, HTTP, Get-auth-token, and HTTP response

same as above, modify HTTP node similar to this :

Get-auth-token: same as the previous node.

Get -Categories: You can modify them like this :


The final flows should be :

3) fetch-all-products : 

Search for Get-products : 

make flow by copying earlier nodes: HTTP, Get-auth-token, and HTTP response

as in this project, we are hitting /products, change HTTP node as :

Also modifying "Get Products" node as : 


The final node will look like this : 

4) Fetch a product by productID :

Find "HTTP "


 

Function (we need 2 hence 2 times) : 


Get-auth-token :  

HTTP request : 

HTTP Response : 


From these nodes, make flow like this: Modify HTTP node such as :

Modify Node.js function as : 


Get-auth-token: Same as previous flows

Function (2nd node named "NodeJS function" ) : 

HTTP request : 

The final Flow looks Similar this : 


5) Creating Cart for customer : 

Find "HTTP","HTTP Response", "NodeJS function", "Get-auth-token", "Get-cart" and connect them as shown : 

Edit HTTP :

NodeJS function : 

Creat-cart Node : 

6) Request Checkout API :

Find "HTTP","HTTP Response", "Get-auth-token", "Create-order" and connect them as shown : 

as we hitting on /checkout

HTTP node :

Create-order node :

The flow should look similar to this:
 


7) Fetch cart content from the consumer : 

Search for Get-cart-by-customer-id:

Search and drop "HTTP", "HTTP response" and copy "Get-auth-token" from previous flows, and connect them like this :

as we are hitting " /cartByCustomerId " Modify HTTP node as : 

Get-auth-token: as a previous flow 

Get-cart-by-customer-id : 

8) Fetch-Order-list: This flow is similar to 6) Request Checkout API but instead of "Get-cart-by-customer-id" we take "Get-order-by-id"

Modifying 

Get Order By ID : 

9) Fetch Customer List :

Search and Drop "HTTP""HTTP responce", "Get-auth-token","Function","Create-customer" and create flow similar to this : 

HTTP : 

Here "Create-customer" modified as :


By These examples, we can easily integrate an e-commerce set up easily!