delivery-packages
Small library to separate items in parcels
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 parcels. 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 parcelify = require('@vtex/delivery-packages')
parcelify(order)
API
parcelify(order, options)
Returns an array of Parcels.
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.
Parcel
A Parcel object shape
{
address: Object,
pickupFriendlyName: String,
seller: String,
items: [Object],
package: Object,
selectedSla: String,
slas: [Object],
shippingEstimate: String,
shippingEstimateDate: String,
deliveryChannel: String,
deliveryIds: [Object]
}
address
The address
used for that parcel. If it is a pickup point, the address of the pickup point is returned.
pickupFriendlyName
If the parcel is delivered to a pickup point, this field has its friendly name.
items
The items of the parcel.
seller
The seller of the parcel.
package
The package
object from packageAttachment
, if it is one.
slas, selectedSla, shippingEstimate, shippingEstimateDate, deliveryChannel, deliveryIds
These properties are taken from the logisticsInfo
of the parcel.
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 }
]
}
]
}
}
parcelify(order, { criteria: { seller: false } })
License
MIT © VTEX