Skip to content

ProtectionCalculator

Utility to calculate protection and determine the correct Onward variant to add to cart. Exposed on window as OnwardProtectionCalculator.

In order to use this directly you will need to implement your own loading of the Onward product and its variants from Shopify.

const protectionVariants = myLoadProtectionProductVariants();
const protectionCalculator = new OnwardProtectionCalculator(protectionVariants, OnwardSettings.load());

Constructors

Constructor

new ProtectionCalculator(protectionVariants, settings): ProtectionCalculator

Parameters

protectionVariants

ProductVariant[]

settings

OnwardSettings

Returns

ProtectionCalculator

Properties

protectionVariants

protectionVariants: ProductVariant[]


settings

settings: OnwardSettings

Methods

protectionPrice()

protectionPrice(lines): number

Calculate the price of protection for the cart.

Parameters

lines

CartLine[]

Current cart line items

Returns

number


protectionVariant()

protectionVariant(lines): ProductVariant

Determine the Onward protection variant to add to cart in order to protect the order.

Parameters

lines

CartLine[]

Current cart line items

Returns

ProductVariant