Search code examples
calculationintershop

How to call custom methods from CalculationResultView class


We implemented custom calculation view class with custom methods e.g. "getMonthlyDiscount", "getMonthlyPrice", etc. and registered it with component framework to BasketBOCalculationResultViewExtensionFactory. The problem is we are unable to find information of how to call those methods to get calculated results.

By calling "basketbo.getExtension(BasketBOCalculationResultViewExtension.class)" we get "BasketBOCalculationResultViewExtensionImpl", so only methods defined in "LineItemCtnrCalculationResultViewProxy" are available, not our custom.

The same example can be applied to question of how to call method "getDuties" from TutorialCalculationResultView given here: https://support.intershop.com/kb/index.php/Display/23V395#Cookbook-BasketCalculation-Recipe:TheResultView

Thank you for your answers! Kind regards


Solution

  • In addition to Willem's answer:

    If you're using an ICM version >= 7.10.8.0 you should be able to retrieve your TutorialCalculationResultView via:

    LineItemCtnrCalculationResultViewProxy resultViewProxy = basketBO.getExtension("CalculationResultView");
    TutorialCalculationResultView resultView = (TutorialCalculationResultView)resultViewProxy.getDelegate();
    

    If you're using a version before 7.10.8.0 and have an Intershop support contract, you could always try asking Intershop tech support if this feature could be downported.

    Alternatively, if the custom methods in your TutorialCalculationResultView are simple and only pass through the values of the associated CalculationRuleSet, then you can also use one of the following methods from the BasketBOCalculationResultViewExtension to retrieve the value directly:

    // returns a single item from the group
    ComputedItem getComputedItem(String group, String id);
    // returns the whole group
    Collection<ComputedItem> getComputedItems(String group);