Skip to content

Instantly share code, notes, and snippets.

@kevinsproles
Last active March 5, 2020 05:57
Show Gist options
  • Select an option

  • Save kevinsproles/58b73747e14a3f83c3cb230ef615e2c2 to your computer and use it in GitHub Desktop.

Select an option

Save kevinsproles/58b73747e14a3f83c3cb230ef615e2c2 to your computer and use it in GitHub Desktop.
/***************************************************************************/
// map volt to shipstation
/***************************************************************************/
// left side is the volt order format... --> right side is shipstation order model
// but first, map a few new properties ShipStation expects
let totalOrderWeight = 0
order.cart.items.map( item => {
item.product.weight_unit = 'grams';
item.product.weight = item.product.weight * 454; // convert our lbs to gram
if (!item.product.weight) {
item.product.weight = 1;
}
totalOrderWeight = totalOrderWeight + item.product.weight
})
if (order.paid === true) {
order.amountPaid = order.grandTotal;
} else {
order.amountPaid = 0;
}
order.weight = totalOrderWeight;
order.weight_unit = 'grams';
// now do the mapping
let volt_to_shipstation_mappings = {
"orderNumber": "orderNumber",
"id": "orderKey",
"createdOn": "orderDate",
"status": {
key: "orderStatus",
transform: function (value) {
switch (value) {
case "New":
return "awaiting_payment";
case "In Progress":
return "awaiting_shipment";
case "Complete":
return "shipped";
case "Cancelled":
return "cancelled";
}
}
},
"customerId": "customerUsername",
"placedBy.emailAddress": "customerEmail",
"deliverTo": {
key: "shipTo.name",
transform: function (value) {
return value.firstName + " " + value.lastName;
}
},
"deliverTo.address.address1": "shipTo.street1",
"deliverTo.address.address2": "shipTo.street2",
"deliverTo.address.city": "shipTo.city",
"deliverTo.address.state": "shipTo.state",
"deliverTo.address.postalCode": "shipTo.postalCode",
"deliverTo.address.country": "shipTo.country",
"placedBy.phoneNumber": "shipTo.phone",
"deliverTo.isResidential": "shipTo.residential",
"cart.items[].product.sku": "items[].sku",
"cart.items[].product.name": "items[].name",
"cart.items[].product.imageMetadata.imageLink.fullUri": "items[].imageUrl",
"cart.items[].product.weight": "items[].weight.value",
"cart.items[].product.weight_unit": "items[].weight.units",
"cart.items[].quantity": "items[].quantity",
"cart.items[].product.price": "items[].unitPrice",
"cart.items[].product.productVariantId": "items[].product_id",
"cart.items[].product.fulfillmentData.sourceSku": "items[].fulfillmentSku",
"taxAmount": "taxAmount",
"cart.shippingMethod.shippingCost": "shippingAmount",
"shopperNote": "customerNotes",
"merchantNote": "internalNotes",
"paymentMethod": "paymentMethod",
"cart.shippingMethod.name": "requestedShippingService",
"weight": "weight.value",
"weight_unit": "weight.units",
};
// run the map
let orderInShipStationFormat = objectMapper(order, volt_to_shipstation_mappings);
// one more post processing step
orderInShipStationFormat.billTo = orderInShipStationFormat.shipTo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment