bottemplates/store-server.gbai/store-server.gbdialog/calculate-shipping.bas

41 lines
1.1 KiB
QBasic

PARAM product_id AS STRING
PARAM quantity AS INTEGER
product = PRODUCT product_id
IF NOT product THEN
RETURN {error: "Product not found"}
END IF
IF NOT quantity THEN
quantity = 1
END IF
dimensions = {
length: product.length,
width: product.width,
height: product.height,
weight: product.gross_weight
}
IF NOT dimensions.weight THEN
dimensions = LLM "Estimate shipping dimensions for: " + product.name + ". Return JSON {length_cm, width_cm, height_cm, weight_kg}"
END IF
volume = dimensions.length * dimensions.width * dimensions.height * quantity
volumetric_weight = volume / 5000
billable = MAX(dimensions.weight * quantity, volumetric_weight)
shipping = {
product_id: product_id,
quantity: quantity,
dimensions: dimensions,
volume_cm3: volume,
billable_weight_kg: billable,
options: [
{carrier: "Ground", days: "5-7", cost: 5.99 + billable * 1.5},
{carrier: "Express", days: "2-3", cost: 12.99 + billable * 2.5},
{carrier: "Overnight", days: "1", cost: 24.99 + billable * 4.0}
]
}
RETURN shipping