0

In backoffice I have two nodes as below. I have only one Itemtype "appeasement".So how to filter and show it in backoffice.

  1. code="PendingAppeasements" id="PendingAppeasements"
  2. code="CompletedAppeasements" id="CompletedAppeasements"

Code for reference:

custome_backoffice_config.xml :- 
<context component="explorer-tree" merge-by="module">
  <explorer-tree:explorer-tree xmlns:explorer-tree="hybris.com/cockpitng/config/explorertree">
    <explorer-tree:navigation-node id="AppeasementsDetails">
      <explorer-tree:type-node code="PendingAppeasements" id="PendingAppeasements" />
      <explorer-tree:type-node code="CompletedAppeasements" id="CompletedAppeasements" />
    </explorer-tree:navigation-node>
  </explorer-tree:explorer-tree>
</context>
Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39
user3809154
  • 53
  • 2
  • 6

1 Answers1

0

I dont have a full step-by-step answer, but in the 6.7 version of hybris the promotion source rules show two nodes, one node showing all promotion source rules and one showing only the promotion source rules of status published or unpublished (leaving out inactive, archived etc), so there is some filtering being done between the two nodes. (to see in backoffice navigate to Marketing -> Promotion Rules and you'll see two subnodes) Note: In later versions this was changed again and there is only one node.

If I understand it right, the "filtered view" works by adding an initial advanced search configuration that filters out promotion source rules based on its status. You could probably achieve something similar by copying and adjusting the approach.

The key config elements seem to be in /promotionenginebackoffice/resources/promotionenginebackoffice-backoffice-config.xml (declaring the two explorer tree nodes) :

        <explorer-tree:explorer-tree xmlns:explorer-tree="http://www.hybris.com/cockpitng/config/explorertree">
            <explorer-tree:navigation-node id="hmc_treenode_marketing">
                <explorer-tree:navigation-node id="hmc_type_tree_abstractpromotion" merge-mode="remove" />
                <explorer-tree:navigation-node id="hmc_typenode_promotion_rules">
                    <explorer-tree:type-node id="hmc_published_and_unpublished_promotion_rules_only" code="PromotionSourceRule"/>
                    <explorer-tree:type-node id="hmc_all_promotion_rules_only" code="PromotionSourceRule"/>
                </explorer-tree:navigation-node>
                <explorer-tree:type-node id="hmc_typenode_promotion_rule_templates" code="PromotionSourceRuleTemplate"/>
                <explorer-tree:type-node id="hmc_type_tree_promotiongroup" code="PromotionGroup"/>
                <explorer-tree:type-node id="hmc_typenode_promotion_modules" code="DroolsKIEModule"/>
            </explorer-tree:navigation-node>
        </explorer-tree:explorer-tree>
    </context>

and in /promotionenginebackoffice/resources/promotionenginebackoffice-backoffice-widgets.xml (declaring the filtering bean) :

<widget id="initPromotionSourceRuleAdvancedSearch" widgetDefinitionId="com.hybris.cockpitng.widgets.common.advancedsearchengine.genericinitializer"
                slotId="cockpitWidgetChildrenInvisible" template="false">
            <setting key="requiredTypeCode" type="String" value="PromotionSourceRule"/>
            <setting key="navigationNodeId" type="String" value="hmc_published_and_unpublished_promotion_rules_only"/>
            <setting key="handlerBeanId" type="String" value="sourceRuleAdvancedSearchInitHandler"/>
            <virtual-sockets/>
        </widget>

The bean doing the filtering (referred in the prior snippet) is defined in:

<alias name="defaultSourceRuleAdvancedSearchInitHandler" alias="sourceRuleAdvancedSearchInitHandler"/>
    <bean id="defaultSourceRuleAdvancedSearchInitHandler" class="de.hybris.platform.ruleenginebackoffice.handlers.SourceRuleAdvancedSearchInitializer"/>

The bean code itself is this:

public class SourceRuleAdvancedSearchInitializer implements AdvancedSearchInitializer
{
    private static final String STATUS = "status";

    @Override
    public void addSearchDataConditions(final AdvancedSearchData searchData, final Optional<NavigationNode> navigationNode)
    {
        if (nonNull(searchData))
        {
            removeExistingStatusCondition(searchData);
            searchData.addConditionList(ValueComparisonOperator.OR, createStatusSearchConditions());
        }
    }

    protected void removeExistingStatusCondition(final AdvancedSearchData searchData)
    {
        final List<SearchConditionData> conditions = searchData.getConditions(STATUS);
        if (isNotEmpty(conditions))
        {
            conditions.clear();
        }
    }

    protected List<SearchConditionData> createStatusSearchConditions()
    {
        return newArrayList(createStatusConditionsList());
    }

    protected SearchConditionDataList createStatusConditionsList()
    {
        final FieldType status = createStausField();
        final List statusConditionsList = new ArrayList();
        statusConditionsList.add(createCondition(status, RuleStatus.UNPUBLISHED));
        statusConditionsList.add(createCondition(status, RuleStatus.PUBLISHED));
        return SearchConditionDataList.or(statusConditionsList);
    }

    protected FieldType createStausField()
    {
        final FieldType status = new FieldType();
        status.setDisabled(Boolean.FALSE);
        status.setSelected(Boolean.TRUE);
        status.setName(STATUS);
        return status;
    }

    protected SearchConditionData createCondition(final FieldType status, final RuleStatus predicate)
    {
        return new SearchConditionData(status, predicate, ValueComparisonOperator.EQUALS);
    }

}

Hope this helps :)

Sebastian
  • 1,743
  • 1
  • 16
  • 35
  • I create my own AdvancedSearchInitializer but when I click on the node it never goes in the AdvancedSearchInitializer I followed all the steps mentioned above also added in custon widgets.xml file. is their any think missing? – user3809154 Jan 10 '20 at 09:28