Search code examples
javasap-commerce-cloud

SAP Hybris Commerce - Change to both online and offline catalog causes desynchronization


I'm trying to create a cronjob in Hybris 1811 which updates an attribute on some products in both Staged and Online catalog versions.

However, even when I make the exact same change to the product in both versions of the catalog, the product is then marked as desynchronized between versions in Backoffice.

When I make the change in the online catalog only, the product is not desynchronized, but any sync from staged to online overwrites the changed.

Code:

productStaged = productService.getProductForCode(stagedCatalog, productCode);
productOnline = productService.getProductForCode(onlineCatalog, productCode);

if (productStaged != null) {
    productStaged.setMargin(margin, locale);
    modelService.save(productStaged);
}

if (productOnline != null) {
    productOnline.setMargin(margin, locale);
    modelService.save(productOnline);
}

Is there a way to make this job possible without causing the product to seem desynchronized in Backoffice?

Thank you!


Solution

  • The correct way is to make the changes in Staged, and sync from Staged to Online. You shouldn't be editing both catalog versions. Online is ideally read-only.

    To sync a list of items, check the CatalogSynchronizationService API: https://help.sap.com/doc/02d5152884b34821a06408495ba0b771/1905/en-US/de/hybris/platform/catalog/synchronization/CatalogSynchronizationService.html#performSynchronization(java.util.List,de.hybris.platform.catalog.model.SyncItemJobModel,de.hybris.platform.catalog.synchronization.SyncConfig)