1

在您没有排除段的组件中: 在此处输入图像描述

我的主题是创建客户细分的对立面。
如果我有一个客户群DEVELOPER,那么我想创建EXCEPT_DEVELOPER(“除 DEVELOPER 之外的每个人都可以看到这个组件”)。

我们想要覆盖/增强检索分配的 Intershop 的核心方法。
目标是动态检查用户是否在 EXCEPT 客户群中。

...
...
forEach(CustomerSegment csItem : customerSegmentList) { 
   if(csItem.contains("EXCEPT")){ //EXCEPT~DEVELOPER
      String customerSegmentToExcept = csItem.split("~")[1]; //DEVELOPER
      if(currentUser.isIn(customerSegmentToExcept)) //current user is in customer segment DEVELOPER
         return "Don't display component";
   }
}
...
...
return "Display component";

你怎么看 ?你有什么建议或其他方法来实现这一点吗?谢谢 !

4

2 回答 2

1

覆盖或增强 pagelet 分配查找的方法是提供自定义 PageletVisibilityFilter。2016 年,我在 Intershop 开发者大会上就该主题发表了演讲。

通常,它们连接在一个基于位置/优先级的开箱即用过滤器列表中,并且在呈现内容入口点(例如插槽、占位符、页面、包含)时,它们从最高优先级到最低优先级执行.

您需要实现该接口:

/**
 * A pagelet visibility filter is a class that decides if a pagelet 
 * is visible to the end user or not. The <code>decide</code> method is invoked 
 * to get the decision from the implementation. 
 */
public interface PageletVisibilityFilter
{
    /**
     * Returns the decision if a pagelet should be filtered or not.
     * 
     * @param pagelet the pagelet which visibility is tested
     * 
     * @return the decision for the pagelet visibility
     * 
     * @see PageletVisibilityFilterReply
     */
    public PageletVisibilityFilterReply decide(Pagelet pagelet);
}

并将该实现注册到组件框架中。快速浏览一下就会app_sf_responsive发现实例化和连接您的实例的位置。

<instance name="pageletABTestGroupVisibilityFilter" with="PageletABTestGroupVisibilityFilter" />
<fulfill requirement="pageletVisibilityFilter" of="pageletVisibilityFilterCtnr" with="pageletABTestGroupVisibilityFilter" />

准备好覆盖客户细分的原始开箱即用过滤器,以表达您试图实现的补充逻辑。

于 2021-09-08T07:54:01.063 回答
1

这符合 Johannes 的建议。这是我的做法

  1. 编写一个 implementations.component
<implementation name="PageletUserGroupVisibilityFilterNegated" class="YOUR.CUSTOM.JAVA.CLASS">
  <implements contract="PageletVisibilityFilter" />
</implementation>   
  1. 编写一个instances.component
<instance name="pageletUserGroupVisibilityFilterNegated" with="PageletUserGroupVisibilityFilterNegated" />
<replace name="pageletUserGroupVisibilityFilter" with="PageletUserGroupVisibilityFilterNegated" delegate="pageletUserGroupVisibilityFilterNegated" />
  1. 现在编写 PageletUserGroupVisibilityFilterNegated 类来支持这种连接。获取 OOB PageletUserGroupVisibilityFilter.java 并更改确定方法返回接受的方式。这是java的关键代码片段。在我的逻辑中,如果有一个以“EXCLUDE”结尾的客户群 ID,那么逻辑会切换,否则它会继续以原始逻辑运行。
final Collection<UserGroup> currentUserUserGroups = getCurrentUserGroups();
boolean accept = false;
for(final Assignment<Pagelet, UserGroup> assignment : assignments)
{
    if (currentUserUserGroups.contains(assignment.getTo()))
    {
         if(assignment.getTo().getID().endsWith("_EXCLUDE"))
         {
             //return DENY as soon as at least one user group of the assignment is contained within current user's user groups and ends with _EXCLUDE
             return PageletVisibilityFilterReply.DENY;
         }
         else if (currentUserUserGroups.contains(assignment.getTo()))
         {
             accept = true;
         }
    }
}
if (accept) {
    //return ACCEPT as at least one user group of the assignment is contained within current user's user groups
    return PageletVisibilityFilterReply.ACCEPT;
}
于 2021-09-08T10:03:44.387 回答