Gustav Ehrenborg fullstack developer

Email symbol LinkedIn logo GitHub logo Instagram logo

Commercetools lessons and code snippets Example code using the .NET SDK

Tuesday, March 23, 2021
Commercetools admin UI

I attended the Commercetools developer training and here are some things that I learnt. It may be worth noticing that my experience with ecommerce platforms is limited, thus some of the things that amazed me might be standard in all platforms.

It, of course, has all the basic stuff

Product types, product variants, carts, checkout, shipping alternatives, tax codes, etc.. However, Commercetools is not not a payment provider, so payments must be handled elsewhere. Information about a payment and receipt information can be added to a completed order in Commercetools for traceability.

It has an API Contract

I like the idea of an API Contract. It can be found here and it contains some info on how versioning, deprecations, limits etc... are handled. I would like to see even more specifications and info here, but I still really think it is a kind gesture. It contains all the limits, for example the maximum number of customers or the maximum number of discount codes applied on a cart. I think the limits are generous, and most of them are soft limits that can be increased.

It uses a draft pattern

Pretty much whatever you want to create, a product, a customer, a whatever, you first create a draft object which is sent to the API. The difference between, for example, a CustomerDraft and a Customer, is that the draft object does not contain timestamps (createdAt, updatedAt...) and other meta data that is added by the Commercetools itself.

It has multiple ways of extending it

API Extensions - Synchronous calls to other services can be configured to be triggered on various events, for example advanced validation that validate cart content. These are synchronous, and should return 2xx or 4xx to approve or not.

Subscriptions - There is support for AWS SQS and SNS, Azure Service Bus and Event Grid and Google Cloud Pub/Sub. Messages can be configured to be sent on various events occurring.

Custom applications - The online admin UI can be extended with custom React apps. There is an application kit to work with, and the apps can then be integrated in the existing UI.

API Playground

It has a very useful API Playground

In something called ImpEx, a web tool to run command line commands to import/export various data, exists an API Playground, which is like a preconfigured online Postman which makes it very easy to browse the data returned from the API. There is also a Postman query collection here, but for quickly just having a look at the data, the API Playground rocks.

Example code snippets

I held a talk for my colleagues about Commercetools to which I prepared and showed a couple of these features. My code snippets are in this GitHub repository.