This repository will help you to set up and customize a personal price engine for your toncarton account.
The price engine is a simple JavaScript function
.
It will receive as inputs all data provided by the customers
it will receive also a base price
computed by toncarton.
The function should return an object containing:
transportation
: the cost of the transportation ( tax included )handling
: The cost of the handling ( tax included )persons
: the number of handlers needederror
: (optional) an error message
return {
transportation: 10,
handling: 10,
persons: 1,
}
When there is en error, you can return
return {
transportation: 0,
handling: 0,
error: "Your error message"
}
function priceEngine(TCT_ADDRESSES) {
const PRICE_ETAPE = 20;
if(TCT_ADDRESSES.length === 0) {
return {
transportation: 0, handling: 0
};
}
const NOMBRE_ETAPE = TCT_ADDRESSES.length - 1;
return {
transportation: PRICE_ETAPE * NOMBRE_ETAPE * 1.2,
handling: 0, persons: 1
};
}
module.exports = priceEngine;
npm install
npm test
npm run build
The result will be in dist/
folder.
The resulting files are starting with tct_
The last step is to copy the content of the file present in the dist/
folder
The function will be called with the arguments computed from the inputs of the customers
TCT_TRANSPORTATION_FEE: Base Price for a transportation cost in TTC (tax included)
TCT_HANDLING_FEE: Base Price fro the handling cost in TTC (tax included)
TCT_PERSONS: Number of handlers needed to move all the items
TCT_ADDRESSES: Array of the addresses provided on the order form
TCT_ITEMS: Array of items provided on the order form
TCT_DISTANCE: Total distance for the transportation in (metre)
TCT_CAPACITY: Total volume occupied by the items in (cubic metre)
TCT_HANDLING_DURATION: Handling time computed in (seconds)
TCT_TRANSPORTATION_DURATION: Transportation time computed in (seconds)
Toncarton will compute the cost based on the addresses/elevator/floor and the items and expose this result on:
TCT_TRANSPORTATION_FEE
, TCT_HANDLING_FEE
and TCT_PERSONS
The price is in euro-based in Paris, France.
Your price Engine can return this computed cost simply by returning them
return {
transportation: TCT_TRANSPORTATION_FEE, // prix TTC
handling: TCT_HANDLING_FEE, // prix TTC
persons: TCT_PERSONS
};
You can also customize these prices like this example when the cost is 20%
greater than the base price of toncarton.
return {
transportation: TCT_TRANSPORTATION_FEE * 1.2, // prix TTC
handling: TCT_HANDLING_FEE * 1.2, // prix TTC
persons: TCT_PERSONS
};
You can use await and async to do async call,
You should use only browser supported function like fetch
to do async http calls
When your customer choose addresses on the order form
TCT_ADDRESSES: Array of
{
geocodeResolved: true
lat: 48.8556174 // latitude
lng: 2.3600226 // longitude
locality: "Paris"
country: "FR"
postalCode: "75004"
id: 0.6906698340755291
placeId: null
elevator: true
floor: 3
address: "12 Rue Rivoli, Paris, France"
index: 0 // address order, 0: first
label: ""
notes: ""
}
Items are the object chosen by the customer like (box, table ..etc)
TCT_ITMES: array of:
{
minimal_truck_capacity: 0 // The minimal size of the truck to load this item in cubic metre
elevator: true // The presence of an elevator
customPrice: undefined
id: 8
name: "Carton grand"
category: "stuff"
volume: 0.4 // volume occupied in cubic metre (m3)
time_factor: 0.05 // ratio form 1 hour to handle this object ( grether => more complicated to handle)
persons_needed: 1 // number of handlers needed to lift and move the item
quantity: 1 // the quantity present of this item
}