猿问

如何在 Hybris 中不设置硬编码目录版本的情况下获取导航节点?

我从一个自定义类别服务中调用一个方法AfterSaveListener,在这个方法中我需要返回的根导航节点,cmsNavigationService但是每当我调用这个方法时,它都会抛出一个错误:

de.hybris.platform.cms2.exceptions.CMSItemNotFoundException:没有带有 id 的 NavigationNode。

当我通过设置硬编码内容目录时

getCatalogVersionService().setSessionCatalogVersion(".....")

我处理这个问题,但对我来说似乎不是真的。我可以通过使用来处理类别的相同问题

userService.setCurrentUser(userService.getAdminUser());

为了消除灵活搜索的所有限制,但此解决方案不适用于导航节点。

我怎么解决这个问题?


米琪卡哇伊
浏览 190回答 2
2回答

慕工程0101907

CMSNavigationService 提供了两种获取根导航节点的方法:一种是不接受任何参数,另一种是接受目录版本作为参数。当您传递目录版本时,该服务将搜索此特定目录版本中的导航节点。当您不指定时,它将在会话目录版本中搜索。hybris 不会在会话中为 cronjobs 设置目录版本。所以你不应该找到导航节点。当您手动将目录版本设置到会话中时(使用您问题中的代码段),它将再次起作用。我希望我正确理解了这个问题。

慕容708150

一般来说,如果没有目录版本,您将无法获得导航节点,因为它们可以识别目录,这意味着您有一个 NavigationNode 的多个实例。在这种情况下,Hybris 无法知道您到底需要哪个。但是,您可以以更好的方式处理您的变通方法。当您的代码中的某些内容需要特定用户时,您可以像这样使用它。可以肯定的是,您可以在 execute() 中添加一个 try - finally 块,并在 try 中设置您的参数并在 finally 中删除它们。private Object myMethod(){&nbsp; &nbsp; return getSessionService().executeInLocalView(new SessionExecutionBody()&nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; @Override&nbsp; &nbsp; &nbsp; &nbsp; public Object execute()&nbsp; &nbsp; &nbsp; &nbsp; {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; // Your code for an isolated session. Set session params here, remove restrictions and so on.&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; //searchRestrictionService.disableSearchRestrictions(); for example&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return new Object();&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }, userService.getAdminUser()); // You can also specify as which user you want to execute the code}另一个有趣的事情是这个。final Map<String, Object> params = ImmutableMap.of(InterceptorExecutionPolicy.DISABLED_INTERCEPTOR_TYPES,&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ImmutableSet.of(InterceptorExecutionPolicy.InterceptorType.VALIDATE));&nbsp; &nbsp; &nbsp; &nbsp; sessionService.executeInLocalViewWithParams(params, new SessionExecutionBody()您可以在哪里指定不同的参数。例如,这个禁用了一些拦截器。
随时随地看视频慕课网APP

相关分类

Java
我要回答