Retrieve commercetools Shopping Cart
You can implement a solution based on this recipe that retrieves a shopping cart from commercetools. The same approach would be applicable for other commerce vendors.
There are at least to reasons why you would retrieve a shopping cart from commercetools: to investigate its contents, or to update the cart, such as to add line items, add a shipping address, or convert the cart to an order.
To retrieve a cart from commercetools, you must have the cart’s identifier. For systems that authenticate customers, you may store the cart identifier in the visitor’s profile, and Conscia can access that value to retrieve the cart. If the visitor has not authenticated, you can store the cart identifier on the client, such as in a cookie or local storage.
To update a cart in commercetools, you must know the cart identifier and its current version number. commercetools uses version numbers to prevent overlapping updates to a single cart. To get the cart’s current version before making an update, retrieve the cart from commercetools.
Carts are not visible in the commercetools user interface. After you convert a cart to an order, it becomes visible as an order in commercetools.
The Orchestration Component described in this recipe depends on a DX Engine Connection to commercetools. For instructions to create such a connection, see:
Overall Orchestration Flow
To retrieve a cart in commercetools, you must specify a cart identifier to the commercetools Webservice API that creates a cart.
This recipe passes the cart identifier as context to the Retrieve commercetools Cart (retrieve-commercetools-cart) Component that retrieves the cart from commercetools. Replace {commercetools Cart ID} key with the commercetools identifier for the cart that you want to retrieve:
{
"cartId": "{commercetools Cart ID}"
}
Mapping Out DX Engine Components and Templates
The orcehstation flow to retrieve a commercetools cart consists of a single Orchestration Component that retrieves the cart based on the identifier passed to that Component in context. Solutions that store cart idenfifiers in a Customer Data Platform (CDP) or elsewhere in a customer's profile may include an additional component that retrieves the cart identifier from that system before retrieving the car.
DX Engine Configuration Details
To create the Retrieve commercetools Cart Orchestration Component, in the Conscia DX UI:
- In the top navigation, click Manage Experiences, and then click Components. The Manage Components page appears.
- Click Add Component. The Create Component wizard appears.
- For Component Code, enter an identifier for the component, such as retrieve-commercetools-cart.
- For Name, enter a name for the component, such as Retrieve commercetools Cart.
- Optionally, enter a Component Description.
- Select the No Rules checkbox. Experience Rules are not relevant to this Component.
- For Component Type, select Conscia - Universal API Connector. This Component Type can connect to almost any Webservice API.
- Click Submit.
To configure the Retrieve commercetools Cart Orchestration Component, on the Manage Components page:
- Next to the Retrieve commercetools Cart component, click the Edit button. The Edit Component wizard appears.
- For Connection, select the commercetools DX Engine Connection.
- For Webservice Path, select Literal, and enter /carts for the value. This is the URL path of the commercetools API relative to the base URL defined by the commercetools Connection.
- For Method, select POST.
- Click Submit.
In general, you should not cache the response of this Component.