Multiple carts and favourites

If your site provides functionality for working with multiple carts and favourites lists, enKod allows you to integrate such mechanics as well. To do this, you need to use identifiers (string) for carts/favourites when passing change events of these entities to enKod.

The identifiers for carts and favourites are optional, and if they are not passed, we assume that the work is done with the contact's default cart/favourite. The implication is that there may exist in parallel and independently on the account for a contact:

  • cart/favourite without an identifier (hereinafter referred to as a “default” cart/favourite)
  • cart/favourite with an identifier

Setting up and peculiarities of tracking methods

Cart actions (script)

Parameter “cartId” is required to pass the cart identifier (data type - string). If this parameter is not passed - actions will be performed with default cart without identifier.

  • to add a single product to a specific cart, use the method:
<script type="text/javascript">
    ekEvents.push('productAdd', {productId: '...', cartId: '...'});
</script>
  • to add multiple products to a specific cart, use the method:
<script type="text/javascript">
    ekEvents.push('productAdd', [{productId: '...', cartId: '...'}, {productId: '...', cartId: '...'}]); 
</script>
  • to remove a single product from a specific cart, use the method:
<script type="text/javascript">
    ekEvents.push('productRemove', {productId: '...', cartId: '...'});
</script>
  • to remove multiple products from a specific cart, use the method:
<script type="text/javascript">
    ekEvents.push('productRemove', [{productId: '...', cartId: '...'}, {productId: '...', cartId: '...'}]); 
</script>

When passing multiple products with different cartId in one request - they will be grouped and written each to the appropriate cart. An example of such request:

<script type="text/javascript">
    ekEvents.push('productAdd', [{productId: '...', cartId: '1'}, {productId: '...', cartId: '2'}]);
</script>

Cart Actions (API)

Parameter “id” is required to pass the cart identifier (data type - string). If this parameter is not passed - actions will be performed with the default cart without identifier.

In the body of the request at the level with the parameters “cart” and “history” pass the parameter “id” to work with a specific cart:

{
  "id": "...",
  "cart": {...},
  "history": [...]
}

Pass the body of the request with a single parameter “id” to work with a specific cart:

{
  "id": "..."
}

Actions with favourites (script)

Parameter “favouriteId” is required to pass the identifier of the favourite (data type - string). If this parameter is not passed - actions will be performed with default favourite without identifier.

  • to add a single product to a specific favorite, use the method:
<script type="text/javascript">
    ekEvents.push('productLike', {productId: '...', favouriteId: '...'});
</script>
  • to add multiple products to a specific favorite, use the method:
<script type="text/javascript">
    ekEvents.push('productLike', [{productId: '...', favouriteId: '...'}, {productId: '...', favouriteId: '...'}]); 
</script>
  • to remove a single product from a specific favorite, use the method:
<script type="text/javascript">
    ekEvents.push('productDislike', {productId: '...', favouriteId: '...'});
</script>
  • to remove multiple products from a specific favorite, use the method:
<script type="text/javascript">
    ekEvents.push('productDislike', [{productId: '...', favouriteId: '...'}, {productId: '...', favouriteId: '...'}]); 
</script>

When passing multiple products with different favouriteId in one request - they will be grouped and written each to the corresponding favourite. An example of such a request:

<script type="text/javascript">
    ekEvents.push('productLike', [{productId: '...', favouriteId: '1'}, {productId: '...', favouriteId: '2'}]);
</script>

Actions with favourites (API)

Parameter “id” is required to pass the identifier of the favourite (data type - string). If this parameter is not passed - actions will be performed with default favourite without identifier.

In the body of the request at the level with the “wishlist” and “history” parameters, pass the “id” parameter to handle a specific favourite:

{
  "id": "...",
  "wishlist": {...},
  "history": [...]
}

Pass the request body with a single parameter “id” to handle a specific favourite:

{
  "id": "..."
}

Handling in contact handling methods in the context of parameters affecting the state of the carts/favourites

API

For API method Contact data with mapping to system fields (POST /v1/subscribe/) the logic of work for cases with several carts/favourites depending on passed cartMergeMethod and favouriteMergeMethod parameters is as follows:

  • replace - the contents of the cart/favourite of an existing contact will be overwritten by the contents of the cart/favourite of the contact we are merging with (including the default cart/favourite can be replaced by multiple carts/favourites with identifiers and vice versa)
  • merge - contents of the existing contact's cart/favourite contact will be merged with the contents of the cart/favourite contact we are merging with (default carts/favourite contact will be merged with each other, carts with identifiers will exist in parallel (if identifiers of carts/favourites contact match by id - their contents will be merged))
  • ignore - the contents of the cart/favourite new contact will be ignored, the contents of the cart/favourite existing contact will be saved.

Script

For the script method Capture the contact on any of the forms (login, registration, quick purchase)) logic of work for cases with several carts/favourites depending on passed cartMergeMethod and favouriteMergeMethod parameters is completely similar to API.

Example of a case with contact merging

Contact 1

  • default cart (product 1, product 2)
  • cart id “cart1” (product 3, product 4)
  • cart id “cart2” (product 5, product 6)

Contact 2

  • default cart (product 7, product 8)
  • cart id “cart3” (product 9, product10)
  • cart id “cart2” (product11, product 12)

Merge via cartMergeMethod = merge, we get:

  • default cart (product 1, product 2, product 7, product 8)
  • cart id “cart1” (product 3, product 4)
  • cart id “cart2” (product 5, item 6, product 11, product 12)
  • cart id “cart3” (product 9, product 10)

Clearing the cart after ordering in case of multiple carts

When working with a single cart after the order it is automatically cleared in the database. In the case of multiple carts, we cannot clear the cart automatically, because we do not know which of the several carts was purchased. You need to additionally pass a method to clear the cart whose order was placed (use the corresponding API method or script method).

Segmentation and dynamic content

Segmentation terms:

  • added to cart
  • added to favourite

by default work with the cart/favourite with the most recent update date (update means the event of adding an item to cart/favourite). This can be either the default cart/favourite or one of the cart/favourite with an identifier.

At the same time dynamic content methods:

  • All products from the cart - GetCart.Products
  • All products from favourites - GetFavourite.Products

by default also return products from the cart/favourite with the most recent update date (by update we mean the event of adding a product to cart/favourite). This can be either the default cart/favourite or one of the carts/favourites with an identifier.

In order to display in an email content of all cart and all favourites in the email use methods:

  • N or all products from all carts - GetAllCarts.Products
  • N or all products from all favourites - GetAllFavourites.Products

Note that when using these constructs, the output is only sorted by the carts/favourites themselves, the products inside will not be sorted. The first to be retrieved will be the contents of the cart/favourite to which the product was the most recent addition of products, then the next by the date of update, etc.

Last modified: 2025.06.10 12:11 by Anastasia Aniskova