Created by potrace 1.16, written by Peter Selinger 2001-2019

Miva Developer Docs


Runtime.js is a native JavaScript file for Miva. 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.


Try runtime functions in Postman#

The Miva: Runtime Functions collection in the Miva Postman workspace has requests for the runtime functions, in folders for Catalog, Checkout, Customer, WishList, Volume Pricing and Combination Facet applications.

Runtime functions are public, so the requests send "Session_Type": "runtime" and need no API token or signature. They use the same Miva Environment as the JSON API collection; see Set Up Postman for how to import it.

Set these variables before sending:

Variable Used by
Domain_Name, Store_Code Every request
Session_ID Basket, checkout and wish list requests. Copy the shopper’s session ID from a storefront session in your browser.
Checkout_Session_ID Runtime_CalculateCharges, Runtime_PaymentMethodList_Load and Runtime_ShippingMethodList_Load
Customer_Session_ID Requests for a logged-in customer, such as Runtime_WishListItemList_Load_Query
Customer_Login, Customer_Password Runtime_Customer_Login
Product_Code, Variant_ID, Category_Code Catalog requests

Requests that change a basket or wish list change it for the session you set, so use a test session.