intershop

How to acces all SubGroup computed items for a single computed product line item


I have two custom made calculation rules in my ruleset, one for single PLI prices and one for totals: enter image description here

In "calculatePostpaidPrices" I create multiple ComputedDurationItems(custom defined class) which are stored as SubGroup on a single ComputedProductLineItem. This relationship can be observed here: enter image description here

Now in second rule, "calculatePostpaidTotals" (on the left), i am trying to get all durations items for single PLI from first rule, now what is the way to do that (on the right is calculation result view which works fine): enter image description here

Please do note that the SubGroup has been made same as in this cookbook recipe for duties subgroup: https://support.intershop.com/kb/index.php/Display/23V395#l100 But there is no example in this cookbook how to retrieve duties(which are subgroup) in next calculation rule.


Solution

  • After looking at some built-in platform calculation rules, I resorted to creating this method:

     private Map<ComputedProductLineItem, Collection<ComputedDurationItem>> mapDurationItemsToComputedPLIs(
    CalculationRule<ComputedItem, ComputedItem, LineItemCtnr>.Input input) {
    Map<ComputedProductLineItem, Collection<ComputedDurationItem>> durationsMap = new HashMap<>();
    Collection<ComputedDurationItem> durationItems = input.getItems(durationsSubGroup);
    
    for (ComputedDurationItem durationItem : durationItems) {
      ComputedProductLineItem parentPLI = input.getItem(this.durationsSubGroup.getParentCell(durationItem));
    
      if (!durationsMap.containsKey(parentPLI))
        durationsMap.put(parentPLI, new ArrayList<ComputedDurationItem>(1));
    
      durationsMap.get(parentPLI).add(durationItem);
    }
    
    return durationsMap;  
    }
    

    And then I use created map to get only duration items for specific PLI. Basically the case here is that you can't get "child" items for a PLI, but you can get parent item for DurationItem or any other item that is in subgroup and that is used in this method.