Fluent Commerce Logo
Docs
Sign In

Commercetools Category Sync

Feature

Changed on:

13 Dec 2023

Overview

The Category Sync is responsible for synchronizing categories from commercetools to Fluent.

Key features

  • Manually synchronize the entire categories at any time
  • Automatic detection and synchronization of modified category

Detailed Technical Description

Sync Type

There are two types of synchronization available

  • Manually synchronize all the categories at any time via a scheduler
  • Automatic detection and synchronization of any modification in category on commercetools

Although Category Sync is initiated differently, it uses the same flow as described below. Categories are added to the external message queue and a dedicated message commercetools-connect-sdk consumer will handle the message and export the data to Fluent.

No alt provided

CT Queue: Any category creation/modification will be pushed to ct-queue using commercetools subscriptions. Out-of-the-box(OOTB) connector uses AWS Event Bridge and it is possible to implement with other queues/subscriptions supported by commercetools. More details on commercetools Subscription.

CT Queue Listener: This class reads the message from CT-Queue and pushes it to the Event queue.

Event Queue: The event queue is responsible for holding the event message to be processed further.

Message Router: It will read the message name from the Event queue and pass it to the appropriate handler. i.e in case of category changes the message name will be “category“ and the route will be “commercetools.connect.category.upsert“.

Category Updates Handler: This will be a class that reads message data from the internal queue and based on the category identifier fetches more information from commercetools-SDK ( The core commercetools sdk which interacts with commercetools APIs ) and maps them with Fluent data model and pushes it to Fluent OMS.

Batch Queue: The Batch queue will handle Bulk data sync. This request will be triggered by Fluent admin with the data like start date, end date, execution-start, etc. This request is to fetch categories from commercetools API with filters ( last updated from - to ) and sync with Fluent OMS.

Job Router: The Job router contains the name of the job and passes it to the job handler.

Category Batch Handler: This receives the job name and filters data to fetch data from commercetools SDK and pushes it to the category Update handler.

The message handlers are fully extensible. Partners can make the changes as per their requirements. The connect-sdk allows message routing with flexible message handlers to process and transform data moving from a source to a destination. Partners can change the message names and override/extend the classes.

Example to extend the functionality

Partners can override existing handlers using application-connector.yml and Handler class. To change the logic of the Category Upsert handler first go to 

`commercetools-modules/commercetools-connector/src/main/resources/application-connector.yml`
 replace the “handler” under routes > name > handler node.

1fluent-connect:
2 - route: "commercetools.connect.category.upsert"
3     props:
4       name: "category"
5       inclusion-filter:
6          - "ResourceUpdated"
7          - "ResourceCreated"
8 - route: "commercetools.connect.category.deactivate"
9     props:
10       name: "category"
11       inclusion-filter:
12          - "ResourceDeleted"

Language: json

Name: application-connector.yml

Description:

[Warning: empty required content area]

New handlers can be added in 

`application-connector.yml `
specific to CT message types for the category entity.

Create a new Handler that extends 

`MessageHandler`
 and ensure that your package is under the main SDK package 
`com.fluentcommerce.connect`
 eg): 
`com.fluentcommerce.connect.custom.commercetools.handler.message.<your-handler>.java`
. For more details on how to extend, please refer to the extend guidelines.

1@Slf4j
2@Component
3@HandlerInfo(name = "FluentCategoryUpsert", description = "Upsert a category at Fluent OMS")
4public class FluentCategoryCreateHandler extends MessageHandler {
5    private static final String CATEGORY_ATTRIBUTE = "category";
6    // write your logic
7}

Language: json

Name: <your-handler>.java

Description:

[Warning: empty required content area]

Batch Job

This option enables product syncing with the help of the Job scheduler. The number of products pushed will depend on the date selected from 

`Fluent Settings > Product Catalog Sync`
. The extension will look for products that have been modified from the date specified until the synchronization starts running. It implicitly adds the categories mapped against the products.

Automatic Delta Sync

This is an automated synchronization that runs in the background to keep Fluent up to date. This synchronization is based on commercetools subscriptions. Out-of-the-box(OOTB) we are supporting 

`ResourceCreated`
 and 
`ResourceUpdated`
 messages. Please refer to commercetools Category Messages for more information on supported messages from CT.

Category APIs and Payloads
CT category API
  • GET: {{host}}/{{project-key}}/categories
  • GET: {{host}}/{{project-key}}/categories/{{category-id}}
Category Message Payload

The Message Payload in CT-queue

1{
2  "notificationType": "Message",
3  "projectKey": "fluent-ct-dev",
4  "id": "96be0961-6b89-4ea8-b9e7-3c367e769f68",
5  "version": 1,
6  "sequenceNumber": 1,
7  "resource": {
8    "typeId": "category",
9    "id": "3f1d5cf9-e5f3-47eb-aa97-a845279c26f4"
10  },
11  "resourceVersion": 1,
12  "resourceUserProvidedIdentifiers": {
13    "slug": {
14      "en": "heel-shoes"
15    }
16  },
17  "type": "ResourceCreated",
18  "category": {
19    "id": "3f1d5cf9-e5f3-47eb-aa97-a845279c26f4",
20    "version": 1,
21    "versionModifiedAt": "2022-07-29T02:30:57.180Z",
22    "lastMessageSequenceNumber": 1,
23    "createdAt": "2022-07-29T02:30:57.180Z",
24    "lastModifiedAt": "2022-07-29T02:30:57.180Z",
25    "lastModifiedBy": {
26      "isPlatformClient": true,
27      "user": {
28        "typeId": "user",
29        "id": "0b28d312-6263-4fba-a0a4-da389fa7aef7"
30      }
31    },
32    "createdBy": {
33      "isPlatformClient": true,
34      "user": {
35        "typeId": "user",
36        "id": "0b28d312-6263-4fba-a0a4-da389fa7aef7"
37      }
38    },
39    "name": {
40      "en": "Heel Shoes"
41    },
42    "slug": {
43      "en": "heel-shoes"
44    },
45    "description": {
46      "en": "All Heel Shoes"
47    },
48    "ancestors": [],
49    "parent": {
50      "typeId": "category",
51      "id": "a122bf5e-feb4-4378-a37e-44306078d7ce"
52    },
53    "orderHint": "c2",
54    "assets": []
55  },
56  "createdAt": "2022-07-29T02:30:57.180Z",
57  "lastModifiedAt": "2022-07-29T02:30:57.180Z"
58}

Language: json

Name: The Message Payload

Description:

[Warning: empty required content area]

Copyright © 2024 Fluent Retail Pty Ltd (trading as Fluent Commerce). All rights reserved. No materials on this docs.fluentcommerce.com site may be used in any way and/or for any purpose without prior written authorisation from Fluent Commerce. Current customers and partners shall use these materials strictly in accordance with the terms and conditions of their written agreements with Fluent Commerce or its affiliates.

Fluent Logo