In some cases you may need to customize your shipping calculation.
For example, if an item and its parent product are under different
categories and each category has a different shipping calculation
code attached, then both shipping calculation codes will be picked
up by the runtime, and the final result will be cumulative. To avoid
this, you can customize the code, by overriding CalculationCodeCombineCmdImpl.getIndirectlyAttachedCodes().
Procedure
- Create a task command that extends CalculationCodeCombineCmd.
For example,
public interface EGShippingCalculationCodeCombineCmd extends
CalculationCodeCombineCmd {
public static final String defaultCommandClassName =
"com.example.commerce.order.calculation.EGShippingCalculationCodeCombineCmd
Impl";
}
- Create an implementation of the task command that extends
CalculationCodeCombineCmdImpl. For example,
EGShippingCalculationCodeCombineCmdImpl extends
CalculationCodeCombineCmdImpl implements
EGShippingCalculationCodeCombineCmd {
}
- Extend the default behavior of getIndirectlyAttachedCodes(Item)
to filter the extraneous shipping calculation codes. For example,
protected CalculationCodeAccessBean[]
getIndirectlyAttachedCodes(Item
iItem) {
CalculationCodeAccessBean[] abCodes =
super.getIndirectlyAttachedCodes(iItem);
//if the array contains both the product and item level shipping
calculation codes, get rid of the product level one
return abCodes;
}
- Register the task command as a calculation method in the
CALMETHOD table. For example,
INSERT INTO CALMETHOD VALUES (some unique ID, -1, -2,
'com.example.commerce.order.calculation.EGShippingCalculationCodeCombineCmd
', 'EG custom CalculationCodeCombine for shipping', 1,
'EGShippingCalculationCodeCombine')
- Set the calculation method as the CalculationCodeCombine
calculation method for shipping:
UPDATE STENCALUSG SET ACTCC_CALMETHOD_ID=calculation methodID WHERE
STOREENT_ID IN (store ID, -1) AND CALUSAGE_ID=-2
Note: Do not customize CalculationHelper.getProductAndItemIds(nCatalogEntryId).