2026-01-14 11:43:46 -03:00
|
|
|
PARAM product_id AS STRING
|
|
|
|
|
PARAM quantity AS INTEGER
|
|
|
|
|
|
|
|
|
|
product = PRODUCT product_id
|
|
|
|
|
IF NOT product THEN
|
2026-01-14 12:23:03 -03:00
|
|
|
RETURN WITH error AS "Product not found"
|
2026-01-14 11:43:46 -03:00
|
|
|
END IF
|
|
|
|
|
|
|
|
|
|
IF NOT quantity THEN
|
|
|
|
|
quantity = 1
|
|
|
|
|
END IF
|
|
|
|
|
|
2026-01-14 12:23:03 -03:00
|
|
|
IF NOT product.gross_weight THEN
|
|
|
|
|
dims = LLM "Estimate shipping dimensions for: " + product.name + ". Return JSON with length_cm, width_cm, height_cm, weight_kg"
|
|
|
|
|
UPDATE "products" WITH length AS dims.length_cm, width AS dims.width_cm, height AS dims.height_cm, gross_weight AS dims.weight_kg WHERE id = product_id
|
|
|
|
|
product = PRODUCT product_id
|
2026-01-14 11:43:46 -03:00
|
|
|
END IF
|
|
|
|
|
|
2026-01-14 12:23:03 -03:00
|
|
|
volume = product.length * product.width * product.height * quantity
|
2026-01-14 11:43:46 -03:00
|
|
|
volumetric_weight = volume / 5000
|
2026-01-14 12:23:03 -03:00
|
|
|
actual_weight = product.gross_weight * quantity
|
|
|
|
|
billable = MAX actual_weight, volumetric_weight
|
2026-01-14 11:43:46 -03:00
|
|
|
|
|
|
|
|
|
2026-01-26 11:44:55 -03:00
|
|
|
RETURN WITH product_id AS product_id, quantity AS quantity, length AS product.length, width AS product.width, height AS product.height, weight AS product.gross_weight, volume_cm3 AS volume, billable_weight_kg AS billable
|