Utilities library to for VTEX lean shipping options
$ npm install @vtex/lean-shipping-calculator -S
Returns lean shipping options (cheapest, fastest and combined)
Type: Array
Logistics info for each item
Type: String
Default: delivery
Active channel
Type: boolean
Default: false
Get more details about each lean option
Type: Object
Lean shipping options
Get lean shipping option that is current selected
Type: Object
Object with lean shipping options
Return all options are only returned if they are worthy according to the calculation.
const leanShippingCalculator = require('@vtex/lean-shipping-calculator')
const options = leanShippingCalculator.getLeanShippingOptions({
logisticsInfo,
activeChannel,
})
console.log(options)
// {
// cheapest: [{item1}, {item2}],
// fastest: [{item1}, {item2}],
// combined: [{item1}, {item2}]
// }
An example of the function returning only cheapest option:
console.log(options)
// {
// cheapest: [{item1}, {item2}]
// }
Returns more details about each lean shipping option
const leanShippingCalculator = require('@vtex/lean-shipping-calculator')
const optionDetails = leanShippingCalculator.getOptionsDetails({
[CHEAPEST]: cheapestOption,
[COMBINED]: combinedOption,
[FASTEST]: fastestOption,
})
console.log(optionDetails)
// [
// {
// averageEstimatePerItem: 520200,
// id: 'CHEAPEST',
// packagesLength: 2,
// price: 1000,
// shippingEstimate: '8bd',
// },
// {
// averageEstimatePerItem: 220200,
// id: 'COMBINED',
// packagesLength: 2,
// price: 3000,
// shippingEstimate: '2bd',
// },
// {
// averageEstimatePerItem: 300200,
// id: 'FASTEST',
// packagesLength: 2,
// price: 1500,
// shippingEstimate: '5bd',
// }
// ]
Returns the selected lean options
const leanShippingCalculator = require('@vtex/lean-shipping-calculator')
const optionToBeSelected = leanShippingCalculator.getSelectedDeliveryOption({
optionsDetails = null,
newCombined,
newFastest,
newCheapest,
activeDeliveryOption,
})
console.log(optionToBeSelected) // CHEAPEST