delivery-packages
Small library to separate items in packages
Motivation
The UX of displaying to the user how their items are going to be delivered can be tricky to be expressed and developed.
There are many criteria to split items in different packages. They are:
- Seller
- SLAs options
- Selected SLA ID
- Selected SLA Shipping Estimate
- Selected SLA Delivery Channel
- Packages already delivered (post purchase scenario)
This module provides a consistent way to handle all those criteria.
Install
$ npm install @vtex/delivery-packages
Usage
const packagify = require('@vtex/delivery-packages')
packagify(order)
API
packagify(order, options)
Returns an array of Packages.
order
An order shaped like an orderForm.
options.criteria
Type: Object
Default:
{
slaOptions: false,
selectedSla: true,
seller: true,
shippingEstimate: true,
deliveryChannel: true
}
This param will be merged with the default options.
Package
A Package object shape
{
address: Object,
pickupFriendlyName: String,
seller: String,
items: [Object],
package: Object,
selectedSla: String,
slas: [Object],
shippingEstimate: String,
shippingEstimateDate: String,
deliveryChannel: String,
}
address
The address
used for that package. If it is a pickup point, the address of the pickup point is returned.
pickupFriendlyName
If the package is delivered to a pickup point, this field has its friendly name.
items
The items of the package.
seller
The seller of the package.
package
The package
object from packageAttachment
, if it is one.
slas, selectedSla, shippingEstimate, shippingEstimateDate, deliveryChannel
These properties are taken from the logisticsInfo
of the package.
Example
const order = {
items: [
{ "id": 0, "quantity": 1, "seller": "1" },
{ "id": 1, "quantity": 1, "seller": "1" }
],
shippingData: {
selectedAddresses: [
{ "addressId": "-4556418741084", "street": "Rua Barão" }
],
logisticsInfo: [
{
"addressId": "-4556418741084",
"selectedSla": "Expressa",
"shippingEstimate": "5bd",
"shippingEstimateDate": "2018-02-23T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 0,
"slas": [
{ "id": "Expressa", "deliveryChannel": "delivery" }
]
},
{
"addressId": "-4556418741084",
"selectedSla": "Normal",
"shippingEstimate": "6bd",
"shippingEstimateDate": "2018-02-24T19:01:07.0336412+00:00",
"deliveryChannel": "delivery",
"itemIndex": 1,
"slas": [
{ "id": "Normal", "deliveryChannel": "delivery" }
]
}
]
},
packageAttachment: {
packages: [
{
"courierStatus": { "finished": false },
"trackingNumber": "123",
"trackingUrl": "",
"invoiceNumber": "456",
"items": [
{ "itemIndex": 0, "quantity": 1 }
]
}
]
}
}
packagify(order, { criteria: { seller: false } })
License
MIT © VTEX