Unified Shipping Module - Periodic Updates

Periodic updates for shipping options in the unified shipping module

The unified shipping module supports periodic update calls for each individual shipping option. It can be configured by specifying an update interval and providing a handler function for the update. The handler function gets passed a callback function as propery to support asynchronous fetching of updated data. To avoid blocking the checkout for too long, a maximum time of 10 seconds is granted for an update call,

All properties of a shipping option definition except for the id, update interval and update handler function can be changed in a periodic update. The callback function accepts a partial definition of the ShippingOption data, so that only the changed values need to be passed.

Example

Configuration

Only relevant parts are shown, the complete configuration is as shown in the "integration" example.

<script>
  var discount = 10000;
  var homeOptions = [
    {
      id: 'porterbuddy',
      name: 'Levert hjem',
      deliveryWindows: deliveryWindows,
      showLeaveAtDoorstep: true,
      updateInterval: 30,
      discount: discount,
      onUpdateOption: function(callback) {
        window.setTimeout(function() {
          discount -= 500;
          callback({
            deliveryWindows: deliveryWindows,
            discount: discount
          });
        }, 2500);
      }
    },
    {
      id: 'postnord',
      name: 'Levert hjemme',
      price: {
        fractionalDenomination: 9900,
        currency: 'NOK',
      },
      description: 'Levering på dørmatte eller i postkasse',
      minDeliveryDays: 2,
      maxDeliveryDays: 5,
      logoUrl: hostUrl + '/logos/postnord.png',
    },
  ];

  var pickupMinDeliveryDays = 1;
  var pickupOptions = [
    {
      id: 'posten',
      name: 'Hente på utleveringssted',
      price: {
        fractionalDenomination: 5900,
        currency: 'NOK',
      },
      minDeliveryDays: pickupMinDeliveryDays,
      maxDeliveryDays: pickupMinDeliveryDays + 2,
      locations: pickupLocations,
      updateInterval: 60,
      onUpdateOption: function(callback) {
        window.setTimeout(function() {
          pickupMinDeliveryDays += 1;
          callback({
            minDeliveryDays: pickupMinDeliveryDays,
            maxDeliveryDays: pickupMinDeliveryDays + 2,
          });
        }, 2500);
      }
    },
  ];
</script>