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

  1. import de.hybris.platform.catalog.CatalogService;
  2. import de.hybris.platform.core.Registry;
  3. import de.hybris.platform.catalog.model.CatalogModel;
  4. CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService');
  5. println(“ Catalogs available are :");
  6. for (CatalogModel catModel : catalogService.getAllCatalogs()) {
  7. println(catModel.getId() + " " + catModel.getVersion());
  8. }
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

  1. import de.hybris.platform.catalog.CatalogService;
  2. import de.hybris.platform.core.Registry;
  3. import de.hybris.platform.catalog.model.CatalogModel;
  4. CatalogService catalogService = (CatalogService) Registry.getApplicationContext().getBean('catalogService');
  5. println("catalog for Id is :");
  6. CatalogModel catModel=catalogService.getCatalogForId("electronicsProductCatalog");
  7. 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());

About the Author

Founder of javainsimpleway.com
I love Java and open source technologies and very much passionate about software development.
I like to share my knowledge with others especially on technology 🙂
I have given all the examples as simple as possible to understand for the beginners.
All the code posted on my blog is developed,compiled and tested in my development environment.
If you find any mistakes or bugs, Please drop an email to kb.knowledge.sharing@gmail.com

Connect with me on Facebook for more updates

Share this article on