@orderprotection/utils
v1.1.16
Published
Utilities used to support the widget
Downloads
16
Readme
OrderProtection Utils
These OrderProtection utilities are available for custom use cases. This package exposes our price calculation based on the cart total
Notes
- When passing in the cart total, pass in the total without the cost of OrderProtection. Also only pass the total of the items that require shipping.
- The calculation will return
null
if there is no suitable variant with the given subtotal. - Pass all subtotals as pennies. e.g ($1.00 === 100)
Usage
import { getClosestVariant } from '@orderprotection/utils'
(async function init() {
const variant = await getClosestVariant(
"orderprotection.myshopify.com", // replace with your orderprotection store url
5000 // subtotal
)
if (!variant) {
// recommended to remove widget and OrderProtection from the cart
return
}
//
const { id, sku, price } = variant
// do something with the variant
// ...
}())