cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Tirgger sync on single item programatically.

Former Member
0 Likes
909

I find the CatalogSynchronizationService really developer unfriendly 🙂

Is there an example how to performSynchronization a single item synchronization ?

Most of the code I find even in the current Hybris services uses CatalogManager (from hybris 3) and JALO layer stuff.

it should be easy but it is more like an impossible task ;)

Accepted Solutions (0)

Answers (1)

Answers (1)

Former Member
0 Likes

OK I came with the following code which uses a bit of a Jalo layer.

 String catalogId = product.getCatalogVersion().getCatalog().getId();
 
          final Catalog catalog = CatalogManager.getInstance().getCatalog(catalogId);
          if (catalog != null) {
             final CatalogVersion source = catalog.getCatalogVersion(CatalogManager.OFFLINE_VERSION);
             final CatalogVersion target = catalog.getCatalogVersion(CatalogManager.ONLINE_VERSION);
 
             if (source != null && target != null) {
                SyncItemJob syncJob = CatalogManager.getInstance().getSyncJob(source, target);
                //Convert Jalo to Model so we can use the CatalogSynchronizationService
                SyncItemJobModel syncJobModel = modelService.get(syncJob);
                catalogSynchronizationService.performSynchronization(Collections.singletonList(product), syncJobModel, getSyncConfig());
             }
          }
 
 the syncConfig is created as fallows:
 
 private SyncConfig getSyncConfig() {
       final SyncConfig syncConfig = new SyncConfig();
       syncConfig.setCreateSavedValues(Boolean.TRUE);
       syncConfig.setForceUpdate(Boolean.TRUE);
       syncConfig.setLogLevelDatabase(JobLogLevel.WARNING);
       syncConfig.setLogLevelFile(JobLogLevel.WARNING);
       syncConfig.setLogToFile(Boolean.TRUE);
       syncConfig.setLogToDatabase(Boolean.FALSE);
       syncConfig.setSynchronous(Boolean.FALSE);
       return syncConfig;
    }
Ask a Question