This section comprises the sample callback class that enables you to apply an appropriate shipping charge to a cart.

Before you define the shipping callback ensure that you have set the following:

  • If shipping charges change based on the ship to or shipping address of the account, ensure that the account associated with the proposal has both specified.

    In addition, you can add additional custom fields on the quote or order line item such as Shipping Speed to calculate the shipping charge.

The sample callback class comprises the following objects:


Data Object - Apttus_Config2.ShippingInput
FieldTypeDescription
ShippingAddressAddressShipping Address. The address for shipping charge calculation obtained from the "Ship To" account for the line item. Accordingly, Ship To Account should be populated on each line item by the implementation.
ItemSObjectApttus_Config2__LineItem__c. The Cart Line item. This is the reference to the cart line items. Implementation can use this cart line item to get any additional custom fields that might be needed to calculate Shipping.
HandbackObject

Any Apex Object passed by the caller and passed back to the caller in the result. Handback is used only in case when the shipping needs to be calculated for an object other than Cart line item. For example, Billing Schedule line items.

  • For calculating shipping for cart , there is no need to pass the Handback object. It can be blank

  • For calculating the Shipping for object other than line items, "Item" field will be blank and the actual object will be passed as handback object to identify object for which shipping is calculated.



Data Object - Apttus_Config2.CustomClass.ShippingResult
FieldTypeDescription
ShippingChargeDecimalShipping amount total of all the cart line items. This is the total shipping amount for the line item. Line item is identified by the sequence in which the shipping result is added. This needs to be calculated and populated by the implementation.
HandbackObjectAny Apex Object passed by the calling class and passed back to the calling class in the result.

Handback is used only in case when the shipping charge needs to be calculated for an object other than Cart line item e.g. Billing Schedule line items.

  • For calculating shipping charges for a cart, there is no need to pass the Handback object. It can be blank

  • For calculating the shipping charges for objects other than line items, "Item" field will be blank and the actual object will be passed as handback object to identify the object for which shipping charges are calculated.


Once you have set shipping to, shipping address or shipping speed to your quote or order, create a Shipping Callback class and specify the name of the callback class in Custom Settings > Config Custom Classes > (Edit) Custom Classes > Shipping Callback Class.

In the sample callback class below, we fetch and create a list of all the products added to the cart. Then we fetch the shipping charges applicable for a product using an SOQL query. If a corresponding shipping code and a valid shipping charge exist for a product in the order or cart, the total shipping amount for a cart is added directly.