GuardMarket

commerce.cart_total

购物车金额汇总

Round each line to cents, apply one order discount, tax discounted items and add untaxed shipping; caller supplies the rate.

Version 1.0.0确定性数据处理Backend required

使用场景 / Purpose

Commerce: cart total. 本技能对提供的参数执行计算,输入输出契约如下。文档例子来自已实现函数的固定验收样例;网页本身不执行代码。

输入字段 / Parameters

字段类型要求约束与说明
items"array"必填 Required{"items": {"type": "object", "properties": {"sku": {"type": "string", "minLength": 1, "maxLength": 128}, "unit_price": {"type": "string", "minLength": 1, "maxLength": 32}, "quantity": {"type": "integer", "minimum": 1, "maximum": 10000}}, "required": ["sku", "unit_price", "quantity"], "additionalProperties": false, "maxProperties": 1000}, "minItems": 1, "maxItems": 200}
discount_percent"number"必填 Required{"minimum": 0, "maximum": 100}
tax_percent"number"必填 Required{"minimum": 0, "maximum": 100}
shipping"string"必填 Required{"minLength": 1, "maxLength": 32}

输入例子 / Example input

{
  "items": [
    {
      "sku": "A",
      "unit_price": "10.00",
      "quantity": 2
    }
  ],
  "discount_percent": 10,
  "tax_percent": 5,
  "shipping": "3.00"
}

预期输出 / Expected output

{
  "lines": [
    {
      "sku": "A",
      "quantity": 2,
      "line_total": "20.00"
    }
  ],
  "subtotal": "20.00",
  "discount": "2.00",
  "taxable": "18.00",
  "tax": "0.90",
  "shipping": "3.00",
  "total": "21.90"
}
完整输入 JSON Schema
{
  "type": "object",
  "properties": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "sku": {
            "type": "string",
            "minLength": 1,
            "maxLength": 128
          },
          "unit_price": {
            "type": "string",
            "minLength": 1,
            "maxLength": 32
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "maximum": 10000
          }
        },
        "required": [
          "sku",
          "unit_price",
          "quantity"
        ],
        "additionalProperties": false,
        "maxProperties": 1000
      },
      "minItems": 1,
      "maxItems": 200
    },
    "discount_percent": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "tax_percent": {
      "type": "number",
      "minimum": 0,
      "maximum": 100
    },
    "shipping": {
      "type": "string",
      "minLength": 1,
      "maxLength": 32
    }
  },
  "required": [
    "items",
    "discount_percent",
    "tax_percent",
    "shipping"
  ],
  "additionalProperties": false,
  "maxProperties": 1000
}
完整输出 JSON Schema
{
  "type": "object",
  "properties": {
    "lines": {
      "type": "array",
      "items": {
        "type": [
          "object",
          "array",
          "string",
          "number",
          "boolean",
          "null"
        ],
        "maxProperties": 1000,
        "maxItems": 1000,
        "maxLength": 60000,
        "minimum": -1e+100,
        "maximum": 1e+100
      },
      "minItems": 0,
      "maxItems": 10000
    },
    "subtotal": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    },
    "discount": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    },
    "taxable": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    },
    "tax": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    },
    "shipping": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    },
    "total": {
      "type": "string",
      "minLength": 0,
      "maxLength": 128000
    }
  },
  "required": [
    "lines",
    "subtotal",
    "discount",
    "taxable",
    "tax",
    "shipping",
    "total"
  ],
  "additionalProperties": false,
  "maxProperties": 1000
}