Skip to content

Runtime.js Reference#


Runtime.js is a native JavaScript file for Miva Merchant. It gets output on certain pages and contains functions that Miva uses natively as part of Attribute Machine. However, it also contains functions that a developer can optionally use to build new features.

Examples of these functions include:

  1. Loading the available attributes and options for a product
  2. Loading available Shipping Methods for a basket
  3. Update/Delete items in a basket, including attributes
  4. Apply a shipping method or payment method to a basket and re-calculate tax

Output Runtime.js on a Page#

Starting in 10.03.00 and beyond, the output of runtime.js is controlled by a new component module that you can assign to any page. By default it is assigned to the following pages:

  • BASK
  • OCST
  • OUS1
  • OUSM
  • OPAY

Note

You’ll notice that the PROD page is not listed above. This file is output on the product page automatically as part of the JS Attribute Machine.


Examples & Use Cases#

Starting in 10.03.00, there are new helper functions available in runtime.js that allow you to do things like update items in the basket or calculate and apply shipping to a basket. The underlying functions are available in the JSON API here under Runtime within the JSON API Function list.

These helper functions make it easier to run these runtime operations to manipulate the cart and perform other actions.

function Runtime_BasketItem_Update( line_id, data, callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_BasketItem_Update',
    {
        Line_ID:                line_id,
        Quantity:               data.quantity,
        Subscription_Term_ID:   data.subterm_id,
        Attributes:             data.attributes
    }, delegator );
}

function Runtime_BasketGroup_Update( group_id, data, callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_BasketItem_Update',
    {
        Group_ID:               group_id,
        Quantity:               data.quantity,
        Subscription_Term_ID:   data.subterm_id,
        Attributes:             data.attributes
    }, delegator );
}

function Runtime_BasketItem_Delete( line_id, callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_BasketItem_Delete',
    {
        Line_ID: line_id
    }, delegator );
}

function Runtime_BasketGroup_Delete( group_id, callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_BasketItem_Delete',
    {
        Group_ID: group_id
    }, delegator );
}

function Runtime_ShippingMethodList_Load( callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_ShippingMethodList_Load', null, delegator );
}

function Runtime_PaymentMethodList_Load( callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_PaymentMethodList_Load', null, delegator );
}

function Runtime_CalculateCharges( shipping_method, payment_method, callback, delegator )
{
    return AJAX_Call_JSON( callback, 'runtime', 'Runtime_CalculateCharges',
    {
        ShippingMethod: shipping_method,
        PaymentMethod:  payment_method
    }, delegator );
}

Note

All these functions include an optional delegator parameter which the Miva admin uses to group and prioritize requests. It can be omitted in most cases unless your feature requires that grouping.