How to load catalogs using groovy script in hybris
We can use groovy script to check the output at runtime rather than running the application
We can run groovy script in HAC
We can also use the similar code in our application
Let’s see below groovy script to get all the catalogs
- import de.hybris.platform.catalog.CatalogService;
- import de.hybris.platform.core.Registry;
- import de.hybris.platform.catalog.model.CatalogModel;
- CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService');
- println(“ Catalogs available are :");
- for (CatalogModel catModel : catalogService.getAllCatalogs()) {
- println(catModel.getId() + " " + catModel.getVersion());
- }
import de.hybris.platform.catalog.CatalogService; import de.hybris.platform.core.Registry; import de.hybris.platform.catalog.model.CatalogModel; CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService'); println(“ Catalogs available are :"); for (CatalogModel catModel : catalogService.getAllCatalogs()) { println(catModel.getId() + " " + catModel.getVersion()); }
We can run this in HAC->console->scripting languages
Select script type as “groovy”
Execute this script and check the output
Similarly, we can get catalog model using catalog id as below
- import de.hybris.platform.catalog.CatalogService;
- import de.hybris.platform.core.Registry;
- import de.hybris.platform.catalog.model.CatalogModel;
- CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService');
- println("catalog for Id is :");
- CatalogModel catModel=catalogService.getCatalogForId("electronicsProductCatalog");
- println(catModel.getId() + " " + catModel.getVersion());
import de.hybris.platform.catalog.CatalogService; import de.hybris.platform.core.Registry; import de.hybris.platform.catalog.model.CatalogModel; CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService'); println("catalog for Id is :"); CatalogModel catModel=catalogService.getCatalogForId("electronicsProductCatalog"); println(catModel.getId() + " " + catModel.getVersion());