Unified Shipping Module - Callbacks

Callback functions for the unified shipping module

The Porterbuddy Unified Shipping Module provides callback function references to trigger actions in the widget from external sources. To access the callback function references, a function is defined for the configuration option "onSetCallbacks". This function gets called by the widget after initialization, the argument passed is an object containing references to the callback functions. These references can be stored and used to trigger actions in the widget from external sources.

Available callback functions

Function Description
forceRefresh() Refreshes the unified shipping module with the currently specified values from the window.porterbuddy variable.
setRecipientInfo(recipientInfo: RecipientInfo) Sets the recipient info in the unified shipping module to the specified value.
refreshShippingOptions() Refreshes the shipping options with the values currently specified in window.porterbuddy. Only the 3 arrays specifying the shipping options are read from the configuration object, all other properties will remain unchanged.

Example

Entered PostCode

Callback Triggers

Configuration

In this example, the refresh function is exposed as window.refresh, in consequence, calling window.refresh within the page will refresh the whole checkout.

<script>
  window.porterbuddy = {
    homeDeliveryOptions: [],
    pickupPointOptions: [],
    storeOptions: [],
    language: 'NO',
    now: '2019-03-14T12:30:00+01:00',
    onPostCodeEntered: function (postCode) {
      document.getElementById('postCodeData').value = postCode;
      window.porterbuddy.homeDeliveryOptions = homeOptions;
      window.porterbuddy.storeOptions = storeOptions;
      window.porterbuddy.pickupPointOptions = pickupOptions;
      window.setRecipientInfo({
        postCode: postCode,
        email: 'test.d.testensen@porterbuddy.com',
      });
      window.refreshShippingOptions();
    },
    onSetCallbacks: function(callbacks) {
      window.refresh = callbacks.forceRefresh;
      window.setRecipientInfo = callbacks.setRecipientInfo;
      window.refreshShippingOptions = callbacks.refreshShippingOptions;
    }
  }
</script>
```javascript