Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vtex/lean-shipping-calculator
https://github.com/vtex/lean-shipping-calculator
srv-checkout-ui xp-shopping
Last synced: about 1 month ago
JSON representation
- Host: GitHub
- URL: https://github.com/vtex/lean-shipping-calculator
- Owner: vtex
- Created: 2018-06-13T17:10:16.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-05-16T16:29:18.000Z (8 months ago)
- Last Synced: 2024-05-17T16:28:50.098Z (8 months ago)
- Topics: srv-checkout-ui, xp-shopping
- Language: JavaScript
- Size: 681 KB
- Stars: 4
- Watchers: 149
- Forks: 1
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Codeowners: .github/CODEOWNERS
Awesome Lists containing this project
README
# lean-shipping-calculator
> Utilities library to for VTEX lean shipping options
[Documentation](https://docs.google.com/document/d/1tDhV1ZOhHhwRYXRGcYmsLvNjsc2pzfQGHKePV68BEKg)
## Install
```sh
$ npm install @vtex/lean-shipping-calculator -S
```---
## API
### getLeanShippingOptions({ logisticsInfo, activeChannel, isScheduledDeliveryActive })
Returns lean shipping options (cheapest, fastest and combined)
#### logisticsInfo
Type: `Array`
Logistics info for each item
#### activeChannel
Type: `String`
Default: `delivery`Active channel
#### isScheduledDeliveryActive
Type: `boolean`
Default: `false`---
### getOptionsDetails(delivery)
Get more details about each lean option
#### delivery
Type: `Object`
Lean shipping options
---
### getSelectedDeliveryOption
Get lean shipping option that is current selected
#### delivery
Type: `Object`
Object with lean shipping options
---
## Usage
### getLeanShippingOptions
Return all options are only returned if they are worthy according to the calculation.
```js
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:
```js
console.log(options)
// {
// cheapest: [{item1}, {item2}]
// }
```### getOptionsDetails
Returns more details about each lean shipping option
```js
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',
// }
// ]
```### getSelectedDeliveryOption
Returns the selected lean options
```js
const leanShippingCalculator = require('@vtex/lean-shipping-calculator')const optionToBeSelected = leanShippingCalculator.getSelectedDeliveryOption({
optionsDetails = null,
newCombined,
newFastest,
newCheapest,
activeDeliveryOption,
})console.log(optionToBeSelected) // CHEAPEST
```