priceMatrix()

The priceMatrix() function (client-side and server-side function) takes the item pricing information returned by getItemPrice() and returns an object wrapped in a method for retrieving prices. See also getItemPrice().

Syntax

Use this syntax for the priceMatrix() function:

            prices = priceMatrix(priceData); 

          

Return Value

The priceMatrix() function returns pricing information and the getPrice() method to work with it.

Use the following syntax for the getPrice() method:

            prices.getPrice(priceLevel, qty); 

          

Both parameters are optional. If the quantity is omitted, it defaults to 1. If the price level is omitted, it defaults to the lowest price level code. For example, if getItemPrice() returns the price levels 2 and 6, the methods returns the price for price level 2.

Note:

The getPrice() method supports unlimited price levels.

Parameters

The priceMatrix() function accepts the priceData parameter. This required parameter corresponds to the item pricing information returned by the getItemPrice() function.

Examples

The following examples show how to use the priceMatrix() function.

Retrieving and Using an Item Price Matrix Asynchronously

This example shows how to retrieve price details for a specific item using asynchronous code. First, the script retrieves the item pricing data using getItemPrice(). Then, it uses priceMatrix() to create an object to simplify price queries.

              (async function() {
    let data = await getItemPrice({
        items: ['387']
    });
    let item = data.items[0];
    console.log('DATA', item);
    console.log('Pricing data', item.price);
    let matrix = priceMatrix(item.price); // Creating a matrix wrapper
    console.log('Price matrix', matrix);
    console.log('Price (plevel=1, qty=10)', matrix.getPrice(1, 10));
})(); 

            

Related Topics

General Notices