on 2017 May 17 6:37 PM
Hi,
I am getting the following error when I run the following groovy script. Can anyone advice why I am getting the error message?
Thank you
Script execution has failed [reason: java.lang.IllegalArgumentException: Value is instanceof Collection but cannot be empty collection for key: catalogVersions]
The script is:
import de.hybris.platform.cms2.model.contents.components.AbstractCMSComponentModel;
import de.hybris.platform.cms2.model.navigation.CMSNavigationNodeModel;
import de.hybris.platform.acceleratorcms.model.components.NavigationBarComponentModel;
import de.hybris.platform.cms2.servicelayer.services.CMSComponentService;
import java.util.ArrayList;
import java.util.List;
CMSComponentService cmsComponentService = spring.getBean("cmsComponentService");
AbstractCMSComponentModel component = (AbstractCMSComponentModel) cmsComponentService.getSimpleCMSComponent("categoryId");
if (component != null){
CMSNavigationNodeModel levels=((NavigationBarComponentModel)component).getNavigationNode();
if (levels!=null){
List<CMSNavigationNodeModel> listLevels=levels.getChildren();
for (CMSNavigationNodeModel level:listLevels){
println " level: " + level.getUid();
for (CMSNavigationNodeModel subLevel1:level.getChildren()){
println " subLevel1: " + subLevel1.getUid();
}
}
}
}
Request clarification before answering.
Hi ,
In Above Your Code Snippet CatalogVersion not give the argument for getting the cmscomponent.Use Bellow Code
import de.hybris.platform.acceleratorcms.model.components.NavigationBarComponentModel
import de.hybris.platform.catalog.CatalogVersionService
import de.hybris.platform.catalog.model.CatalogVersionModel
import de.hybris.platform.cms2.model.contents.components.AbstractCMSComponentModel
import de.hybris.platform.cms2.model.navigation.CMSNavigationNodeModel
import de.hybris.platform.cms2.servicelayer.services.CMSComponentService
import de.hybris.platform.core.Registry
CMSComponentService cmsComponentService = spring.getBean("cmsComponentService");
CatalogVersionModel version=Registry.getApplicationContext().
getBean("catalogVersionService",CatalogVersionService.class).getCatalogVersion("apparelProductCatalog", "Online");
List versionslist=new ArrayList();
versionslist.add(version);
AbstractCMSComponentModel component = (AbstractCMSComponentModel) cmsComponentService.getAbstractCMSComponent("A101010",versionslist);
if (component != null){
CMSNavigationNodeModel levels=((NavigationBarComponentModel)component).getNavigationNode();
if (levels!=null){
List<CMSNavigationNodeModel> listLevels=levels.getChildren();
for (CMSNavigationNodeModel level:listLevels){
println " level: " + level.getUid();
for (CMSNavigationNodeModel subLevel1:level.getChildren()){
println " subLevel1: " + subLevel1.getUid();
}
}
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to set the session catalog version.
e.g.
catalogVersionService.setSessionCatalogVersion 'Default', 'Staged'
Also, although that will run as Groovy, it's not very groovy. What are all those types and semi colons doing there? And you definitely don't need to access the application context directly to retrieve beans.
Perhaps something more like this?
catalogVersionService.setSessionCatalogVersion 'myContentCatalog','Staged'
component = cmsComponentService.getSimpleCMSComponent('MyAccountComponent')
component?.navigationNode?.children.each { level ->
println " level: ${level.uid}"
level.children.each { subLevel ->
println " subLevel1: ${subLevel1.uid}"
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.