Helper methods available in pricing scripts for common calculations and data manipulation These utilities extend the capabilities of pricing scripts and help create more flexible and maintainable pricing logic.

Hierarchy

  • HelperMethods

Properties

CSV parsing and stringifying utilities for data-driven pricing Provides comprehensive CSV handling capabilities for working with external data files, configuration data, and bulk pricing information

Example

// Parse CSV file content
var csvContent = HelperMethods.CSV.parse(fileContent);

// Generate CSV output
var outputData = [["Product", "Price"], ["Item A", "10.99"]];
var csvOutput = HelperMethods.CSV.stringify(outputData);

Methods

  • Check if arrays contain specific values for conditional logic Utility function for checking array membership in conditional pricing logic

    Parameters

    • array: any[]

      Array to check for the specified value

    • value: any

      Value to search for in the array

    Returns boolean

    Whether the value is found in the array

    Example

    if (HelperMethods.Contains(Item.CustomerRoles, "VIP")) {
    // Apply VIP pricing logic
    }
  • Find appropriate pricing tier based on quantity and customer roles Searches through tier arrays to find the best matching tier for the given quantity and customer roles, supporting both regular pricing tiers and batch tiers

    Parameters

    • quantity: number

      The quantity which you would like the price to be worked out based on

    • tiers: Tier[]

      An array of object literals [{Quantity: n, Price: n, CustomerRole?: string}]

    • Optional roles: string[]

      Array of string that contains customer roles, falls back to Customer.Roles if not supplied

    Returns Tier

    Tier object or null if no matching tier found

    Example

    var tiers = [{Quantity: 1, Price: 5}, {Quantity: 50, Price: 17}, {Quantity: 250, Price: 60}];
    var tier = HelperMethods.FindTier(100, tiers, ["SuperAdmin", "Admin"]);
    // Returns the tier with Quantity: 50, Price: 17
  • Get attribute price adjustments including tier-based adjustments Calculates the total price adjustment for all selected attributes, taking into account tier-based pricing adjustments that can vary based on quantity or customer roles

    Parameters

    • quantity: number

      The quantity which you would like the price to be worked out based on

    • Optional roles: string[]

      Array of string that contains customer roles, falls back to Customer.Roles if not supplied

    Returns number

    Total price adjustment including all attribute and tier adjustments

    Example

    var attributeAdjustment = HelperMethods.GetAttributePriceAdjustment(43, ["SuperAdmin", "Admin"]);
    // Returns the total price adjustment for quantity 43 with specified customer roles
  • Interpolate prices between tier boundaries for smooth pricing transitions Calculates a price that falls between tier boundaries based on the specified quantity, providing smooth pricing curves rather than step-based pricing

    Parameters

    • quantity: number

      The quantity which you would like the price to be worked out based on

    • tiers: Tier[]

      An array of object literals [{Quantity: n, Price: n}] for interpolation

    Returns number

    Interpolated price based on quantity position within the specified tiers

    Example

    var interpolationTiers = [
    {Quantity: 1, Price: 5}, {Quantity: 50, Price: 17},
    {Quantity: 250, Price: 60}, {Quantity: 500, Price: 100},
    {Quantity: 1000, Price: 200}
    ];
    var tierPrice = HelperMethods.InterpolatePrice(Item.Quantity, interpolationTiers);
    // Returns interpolated price based on Item.Quantity position within tiers
  • Type checking utility for robust script development Determines if an item is an array

    Parameters

    • item: any

      Item to check if it's an array

    Returns boolean

    Whether the item is an array

    Example

    if (HelperMethods.IsArray(Item.Attributes)) {
    // Process attributes array
    }
  • Type checking utility for robust script development Determines if an item is a plain object (not null, not array, not primitive)

    Parameters

    • item: any

      Item to check if it's an object

    Returns boolean

    Whether the item is an object

    Example

    if (HelperMethods.IsObject(config)) {
    // Process configuration object
    }
  • Log object properties for debugging complex pricing scenarios Outputs all properties of an object to the console for debugging purposes, useful for examining complex data structures during script development

    Parameters

    • data: any

      Object to log all properties from

    Returns void

    Example

    HelperMethods.LogObject(Item);
    // Logs all Item properties to console for debugging
  • Deep merge objects with conflict resolution for combining pricing data Merges source object properties into target object, handling nested objects and providing a way to combine configuration data from multiple sources

    Parameters

    • target: any

      Target object to merge properties into

    • source: any

      Source object to merge properties from

    Returns void

    Example

    var baseConfig = {markup: 20, shipping: 5};
    var overrideConfig = {markup: 25};
    HelperMethods.MergeObject(baseConfig, overrideConfig);
    // baseConfig now has {markup: 25, shipping: 5}

Generated using TypeDoc