问题
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
回答1:
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);
回答2:
I see that the magic happens in this instance:
<instance name="BasketBOCalculationResultViewExtensionFactory"
with="BasketBOCalculationResultViewExtensionFactoryImpl" > ..</>
This BasketBOCalculationResultViewExtensionFactory
creates the BasketBOCalculationResultViewExtensionImpl
instances. It is hardcoded so u cant replace this with your own implementation sadly.
So the only option i see is to replace the whole BasketBOCalculationResultViewExtensionFactory
factory.
<implementation name="BasketBOCalculationResultViewExtensionFactoryImpl"
implements="BusinessObjectExtensionFactory"
class="your.custom.cartridge.MyBasketBOCalculationResultViewExtensionFactory">
<requires name="assignment" contract="CalculationResultViewFactoryAssignment" cardinality="0..n" />
</implementation>
MyBasketBOCalculationResultViewExtensionFactory
can then extend BasketBOCalculationResultViewExtensionFactory
and you have to override the methods addAssignment
and createExtension
来源:https://stackoverflow.com/questions/56456891/how-to-call-custom-methods-from-calculationresultview-class