@@ -11,6 +11,7 @@ against a [CartDiscountDraft](https://docs.commercetools.com/http-api-projects-c
1111- [ Usage] ( #usage )
1212 - [ Sync list of cart discount drafts] ( #sync-list-of-cart-discount-drafts )
1313 - [ Prerequisites] ( #prerequisites )
14+ - [ About SyncOptions] ( #about-syncoptions )
1415 - [ Running the sync] ( #running-the-sync )
1516 - [ More examples of how to use the sync] ( #more-examples-of-how-to-use-the-sync )
1617 - [ Build all update actions] ( #build-all-update-actions )
@@ -47,7 +48,88 @@ actual ids of the type reference, the `key` of the `Type` has to be supplied.
4748final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder . of(sphereClient). build();
4849````
4950
50- [ More information about Sync Options] ( SYNC_OPTIONS.md ) .
51+ #### About SyncOptions
52+ ` SyncOptions ` is an object which provides a place for users to add certain configurations to customize the sync process.
53+ Available configurations:
54+
55+ ##### 1. ` errorCallback `
56+ A callback that is called whenever an error event occurs during the sync process. Each resource executes its own
57+ error-callback. When sync process of particular resource runs successfully, it is not triggered. It contains the
58+ following context about the error-event:
59+
60+ * sync exception
61+ * cart discount draft from the source
62+ * cart discount of the target project (only provided if an existing cart discount could be found)
63+ * the update-actions, which failed (only provided if an existing cart discount could be found)
64+
65+ ##### Example
66+ ```` java
67+ final Logger logger = LoggerFactory . getLogger(CartDiscountSync . class);
68+ final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder
69+ .of(sphereClient)
70+ .errorCallback((syncException, draft, cartDiscount, updateActions) - >
71+ logger. error(new SyncException (" My customized message" ), syncException)). build();
72+ ````
73+
74+ ##### 2. ` warningCallback `
75+ A callback that is called whenever a warning event occurs during the sync process. Each resource executes its own
76+ warning-callback. When sync process of particular resource runs successfully, it is not triggered. It contains the
77+ following context about the warning message:
78+
79+ * sync exception
80+ * cart discount draft from the source
81+ * cart discount of the target project (only provided if an existing cart discount could be found)
82+
83+ ##### Example
84+ ```` java
85+ final Logger logger = LoggerFactory . getLogger(CartDiscountSync . class);
86+ final CartDiscountSyncOptions cartDiscountSyncOptions = CartDiscountSyncOptionsBuilder
87+ .of(sphereClient)
88+ .warningCallback((syncException, draft, cartDiscount, updateActions) - >
89+ logger. warn(new SyncException (" My customized message" ), syncException)). build();
90+ ````
91+
92+ ##### 3. ` beforeUpdateCallback `
93+ During the sync process if a target cart discount and a cart discount draft are matched, this callback can be used to
94+ intercept the ** _ update_ ** request just before it is sent to commercetools platform. This allows the user to modify
95+ update actions array with custom actions or discard unwanted actions. The callback provides the following information :
96+
97+ * cart discount draft from the source
98+ * cart discount from the target project
99+ * update actions that were calculated after comparing both
100+
101+ ##### Example
102+ ```` java
103+ final TriFunction<
104+ List<UpdateAction<CartDiscount > > , CartDiscountDraft , CartDiscount , List<UpdateAction<CartDiscount > > >
105+ beforeUpdateCartDiscountCallback =
106+ (updateActions, newCartDiscountDraft, oldCartDiscount) - > updateActions. stream()
107+ .filter(updateAction - > ! (updateAction instanceof ChangeCartPredicate ))
108+ .collect(Collectors . toList());
109+
110+ final CartDiscountSyncOptions cartDiscountSyncOptions =
111+ CartDiscountSyncOptionsBuilder . of(sphereClient). beforeUpdateCallback(beforeUpdateCartDiscountCallback). build();
112+ ````
113+
114+ ##### 4. ` beforeCreateCallback `
115+ During the sync process if a cart discount draft should be created, this callback can be used to intercept
116+ the ** _ create_ ** request just before it is sent to commercetools platform. It contains following information :
117+
118+ * cart discount draft that should be created
119+
120+ Please refer to [ example in product sync document] ( PRODUCT_SYNC.md#example-set-publish-stage-if-category-references-of-given-product-draft-exists ) .
121+
122+ ##### 5. ` batchSize `
123+ A number that could be used to set the batch size with which cart discounts are fetched and processed,
124+ as cart discounts are obtained from the target project on commercetools platform in batches for better performance. The
125+ algorithm accumulates up to ` batchSize ` resources from the input list, then fetches the corresponding cart discounts
126+ from the target project on commecetools platform in a single request. Playing with this option can slightly improve or
127+ reduce processing speed. If it is not set, the default batch size is 50 for cart discount sync.
128+ ##### Example
129+ ```` java
130+ final CartDiscountSyncOptions cartDiscountSyncOptions =
131+ CartDiscountSyncOptionsBuilder . of(sphereClient). batchSize(30 ). build();
132+ ````
51133
52134#### Running the sync
53135After all the aforementioned points in the previous section have been fulfilled, to run the sync:
0 commit comments