> ## Documentation Index
> Fetch the complete documentation index at: https://foliant-help.iforiti.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 模板中的订单项目

> 在 Liquid 中遍历订单的各个项目，打印其标题、数量、价格、SKU、图片、重量和属性。

订单中的商品位于 `line_items` 中。要打印它们，请遍历这个列表：`{% for line_item in line_items %}` 和 `{% endfor %}` 之间的所有内容会对每个项目重复一次，`line_item` 就是当前项目。订单项目字段只在循环内有效。

## 基本的项目表格

```liquid theme={null}
<table>
  {% for line_item in line_items %}
    <tr>
      <td>{{ line_item.title }}</td>
      <td>{{ line_item.sku }}</td>
      <td>{{ line_item.quantity }}</td>
      <td>{{ line_item.price | money }}</td>
      <td>{{ line_item.line_price | money }}</td>
    </tr>
  {% endfor %}
</table>
```

## 订单项目字段

| 变量 | 打印内容 |
| - | - |
| `line_item.title` | 项目标题（产品和多属性） |
| `line_item.name` | 项目名称 |
| `line_item.product_title` | 产品标题 |
| `line_item.variant_title` | 多属性标题，例如“Blue / Large” |
| `line_item.quantity` | 订购数量，包括已退款的项目 |
| `line_item.fulfillable_quantity` | 仍待发货的数量 |
| `line_item.refunded_quantity` | 已退款的数量 |
| `line_item.sku` | SKU |
| `line_item.vendor` | 厂商 |
| `line_item.price` | 扣除项目折扣后的单价（以分为单位） |
| `line_item.original_price` | 折扣前的单价（以分为单位） |
| `line_item.line_price` | 项目总价：单价 × 数量，已扣除项目折扣（以分为单位） |
| `line_item.total_discount` | 该项目的折扣（以分为单位） |
| `line_item.discount_per_item` | 每件商品的折扣（以分为单位） |
| `line_item.total_tax` | 该项目的税费（以分为单位） |
| `line_item.cost` | 商品成本，用于采购订单（以分为单位） |
| `line_item.tax_lines` | 该项目的各项税费：遍历以获取 `title`、`rate`、`price` |
| `line_item.discount_allocations` | 应用于该项目的折扣：遍历以获取 `amount` |
| `line_item.properties` | 订单项目属性。请参阅[订单属性和订单项目属性](https://foliant-help.iforiti.com/cn/template-editor/liquid-custom-fields.md)。 |
| `line_item.hs_tariff_code` | HS 关税编码 |
| `line_item.country_of_origin` | 原产国 |
| `line_item.weight` | 单件商品的重量，使用其自身的单位 |
| `line_item.grams` | 单件商品的重量，以克为单位；`{{ line_item.grams \| weight_with_unit }}` 会加上单位 |
| `line_item.total_weight` | 该项目的重量（单件 × 数量） |
| `line_item.image` | 商品图片；`{{ line_item.image \| img_url: 'thumb' \| img_tag }}` 会将其打印出来 |
| `line_item.requires_shipping` | 该商品是否需要发货 |
| `line_item.gift_card` | 该商品是否为礼品卡 |
| `line_item.product` | 产品（`title`、`type`、`vendor`、`tags`、`handle`…） |
| `line_item.variant` | 多属性（`title`、`sku`、`barcode`、`option1`、`inventory_quantity`…） |

## 常用写法

仅在有多属性标题时，将其打印在产品下方：

```liquid theme={null}
{{ line_item.product_title }}
{% if line_item.variant_title != blank %}<br>{{ line_item.variant_title }}{% endif %}
```

在装箱单上省略已全额退款的项目：

```liquid theme={null}
{% for line_item in line_items %}
  {% if line_item.quantity > line_item.refunded_quantity %}
    {{ line_item.title }} × {{ line_item.quantity | minus: line_item.refunded_quantity }}
  {% endif %}
{% endfor %}
```

为每个 SKU 显示条形码：

```liquid theme={null}
{{ line_item.sku | barcode }}
```

## 每批发货一份文档

当模板为每批发货打印一份文档时（模板设置页面上的**拆分发货**），`document_fulfillment` 就是正在打印的那批发货。要只列出其中的商品：

```liquid theme={null}
{% if document_fulfillment %}
  {% assign line_items = document_fulfillment.line_items %}
{% endif %}
```

## 注意事项

* 价格以分为单位：请始终使用金额过滤器打印。请参阅[模板中的金额和货币](https://foliant-help.iforiti.com/cn/template-editor/liquid-money-and-currency.md)。
* 商品图片会按您通过 `img_url` 指定的尺寸打印，例如 `'thumb'`、`'small'`、`'medium'` 或 `'120x120'`。
* 产品和多属性的元字段位于 `line_item.product.metafields` 和 `line_item.variant.metafields` 下。请参阅[模板中的元字段](https://foliant-help.iforiti.com/cn/template-editor/metafields.md)。
* 循环变量名可由您自行选择，但 `line_item` 与参考文档和初始模板保持一致。
* 来自 Bold Product Options 和 Infinite Options 的订单会添加 `line_item.options`, `line_item.option_addon`, `line_item.option_addons` 以及包含附加项的价格，因此您可以将付费附加项打印在所属商品下方。请参阅 [商品选项应用（Bold、Infinite Options）](https://foliant-help.iforiti.com/cn/templates/product-options-apps.md)。

## 相关文章

* [订单对象和常用变量](https://foliant-help.iforiti.com/cn/template-editor/liquid-order-variables.md)
* [模板中的金额和货币](https://foliant-help.iforiti.com/cn/template-editor/liquid-money-and-currency.md)
* [订单属性和订单项目属性](https://foliant-help.iforiti.com/cn/template-editor/liquid-custom-fields.md)
* [模板中的元字段](https://foliant-help.iforiti.com/cn/template-editor/metafields.md)
* [商品选项应用（Bold、Infinite Options）](https://foliant-help.iforiti.com/cn/templates/product-options-apps.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.