我如何指定客户群的对立面
How can I specify the opposite of a customer segment
在您没有排除段的组件中:
我的主题是创建客户群的对立面。
如果我有一个客户群 DEVELOPER 那么我想创建 EXCEPT_DEVELOPER (“除了 DEVELOPER 之外每个人都可以看到这个组件”)。
我们想要 override/enhance 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";
你怎么看?您有什么建议或其他方法可以实现这一目标吗?
谢谢!
覆盖或增强 pagelet 分配查找的方法是提供自定义 PageletVisibilityFilter。 2016 年,我在 Intershop 开发者大会上就该主题发表了演讲。
通常,它们连接在基于 position/priority 的开箱即用过滤器列表中,并且当内容入口点(例如插槽、占位符)时,它们从最高优先级到最低优先级执行, page, include) 被呈现。
您需要实现该接口:
/**
* 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" />
准备好覆盖客户群的原始开箱即用过滤器,以表达您试图实现的补充逻辑。
这与 Johannes 的建议一致。这是我的做法
- 写一个implementations.component
<implementation name="PageletUserGroupVisibilityFilterNegated" class="YOUR.CUSTOM.JAVA.CLASS">
<implements contract="PageletVisibilityFilter" />
</implementation>
- 写一个instances.component
<instance name="pageletUserGroupVisibilityFilterNegated" with="PageletUserGroupVisibilityFilterNegated" />
<replace name="pageletUserGroupVisibilityFilter" with="PageletUserGroupVisibilityFilterNegated" delegate="pageletUserGroupVisibilityFilterNegated" />
- 现在编写 class PageletUserGroupVisibilityFilterNegated 来支持这种连接。获取 OOB PageletUserGroupVisibilityFilter.java 并更改决定方法 returns 接受的方式。这是 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;
}
在您没有排除段的组件中:
我的主题是创建客户群的对立面。
如果我有一个客户群 DEVELOPER 那么我想创建 EXCEPT_DEVELOPER (“除了 DEVELOPER 之外每个人都可以看到这个组件”)。
我们想要 override/enhance 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";
你怎么看?您有什么建议或其他方法可以实现这一目标吗? 谢谢!
覆盖或增强 pagelet 分配查找的方法是提供自定义 PageletVisibilityFilter。 2016 年,我在 Intershop 开发者大会上就该主题发表了演讲。
通常,它们连接在基于 position/priority 的开箱即用过滤器列表中,并且当内容入口点(例如插槽、占位符)时,它们从最高优先级到最低优先级执行, page, include) 被呈现。
您需要实现该接口:
/**
* 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" />
准备好覆盖客户群的原始开箱即用过滤器,以表达您试图实现的补充逻辑。
这与 Johannes 的建议一致。这是我的做法
- 写一个implementations.component
<implementation name="PageletUserGroupVisibilityFilterNegated" class="YOUR.CUSTOM.JAVA.CLASS">
<implements contract="PageletVisibilityFilter" />
</implementation>
- 写一个instances.component
<instance name="pageletUserGroupVisibilityFilterNegated" with="PageletUserGroupVisibilityFilterNegated" />
<replace name="pageletUserGroupVisibilityFilter" with="PageletUserGroupVisibilityFilterNegated" delegate="pageletUserGroupVisibilityFilterNegated" />
- 现在编写 class PageletUserGroupVisibilityFilterNegated 来支持这种连接。获取 OOB PageletUserGroupVisibilityFilter.java 并更改决定方法 returns 接受的方式。这是 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;
}