# Order Printer で 特定の商品タグごとに納品書を作成したい。

**URL:** <https://community.shopify.com/t/order-printer/234333>\
**Category:** 技術的なQ＆A\
**Created:** [July 20, 2023, 2:54pm UTC](https://community.shopify.com/t/order-printer/234333 "2023-07-20T14:54:08Z")\
**Posts on this page:** 2\
**Page:** 1

## AI-generated summary

ユーザーは Order Printer を使用して、商品タグごとに納品書を分けて作成する方法を探しています。

**背景と目的:**
- 1つの注文に複数回の配送があるため、配送ごとに納品書を作成したい
- 商品に「DEL-01」「DEL-02」などの配送時期を示すタグを付与し、タグごとに商品を表示・合計金額を計算したい

**技術的な課題:**
- Liquid テンプレートで商品タグごとの合計金額計算ができない
- 四則演算の記述方法に問題がある

**解決策:**
Qcoltd が修正コードを提供しました:
- Liquid の正しい演算方法として `| plus:` と `| times:` フィルターを使用
- タグごとに合計金額を計算し、`{{ total_price_for_tag_DEL01 | money }}` などで表示する方法を提示

コードスニペットが中心的な役割を果たしており、具体的な実装方法が共有されています。

<div class="post-metadata">

**Author:** ![shogof](https://avatars.discourse-cdn.com/v4/letter/s/c77e96/32.png) [@shogof](https://community.shopify.com/u/shogof)\
**Post date:** [July 20, 2023, 2:54pm UTC](https://community.shopify.com/t/order-printer/234333/1 "2023-07-20T14:54:08Z")

</div>

Order Printer で 特定の商品タグごとに納品書を作成したいと考えています。

# 背景

- 一度の注文に対して複数回の配送があります。
- そのため、配送ごとに配送した商品が分かるように、配送ごとに商品が一覧化された納品書を作成したいと考えています。

# 現状検討している方針

- 現状、配送ごとに納品書を作成する事ができないため、OrderPrinterを活用する
- OrderPrinterで配送ごとに納品書を分ける事ができないため、商品に配送時期を示すタグとして”DEL-01”などのタグを付与する。
- OrderPrinterのテンプレートにて、商品タグごとに商品を表示・合計金額を計算する

# 現状の問題点

- 商品のタグをDEL-の接頭辞がついているものだけを表示したいができない。
- 以下の様なコードを記載しているが、商品タグごとに合計料金を計算する事ができない。

```auto
{% for line in line_items %}
  {% for tag in line.product.tags %}
    {% if tag == 'DEL-01' %}
      {% assign total_price_for_tag_DEL01 = total_price_for_tag_DEL01 + line.price * line.quantity %}
    {% elsif tag == 'DEL-02' %}
      {% assign total_price_for_tag_DEL02 = total_price_for_tag_DEL02 + line.price * line.quantity %}
    {% elsif tag == 'DEL-03' %}
      {% assign total_price_for_tag_DEL03 = total_price_for_tag_DEL03 + line.price * line.quantity %}
    {% endif %}
    <!-- 省略 -->
  {% endfor %}

```

是非皆様の知見

---

<div class="post-metadata">

**Author:** ![Qcoltd](https://yyz1.discourse-cdn.com/shopifyforum/user_avatar/community.shopify.com/qcoltd/32/900_2.png) [@Qcoltd](https://community.shopify.com/u/Qcoltd)\
**Post date:** [July 21, 2023, 10:25am UTC](https://community.shopify.com/t/order-printer/234333/2 "2023-07-21T10:25:16Z")

</div>

@shogof

ご質問いただいているソースコードですが、liquidでの四則演算と異なっておりますので  
ご希望の動きをしていないと思われます。

下記に調整を加えたコードを記載させていただきます。

```markup
{% for line in line_items %}
  {% for tag in line.product.tags %}
    {% if tag == 'DEL-01' %}
      {% assign total_price_for_tag_DEL01 = total_price_for_tag_DEL01 | plus:line.price | times:line.quantity %}
    {% elsif tag == 'DEL-02' %}
       {% assign total_price_for_tag_DEL02 = total_price_for_tag_DEL02 | plus:line.price | times:line.quantity %}
    {% elsif tag == 'DEL-03' %}
      {% assign total_price_for_tag_DEL03 = total_price_for_tag_DEL03 | plus:line.price | times:line.quantity %}
    {% endif %}
  {% endfor %}
{% endfor %}

```

上記コードの下部に下記コードを記載いただくとタグ毎の合計額がご確認いただけると思います。

```markup
total_price_for_tag_DEL01の合計

{{ total_price_for_tag_DEL01 | money }}

total_price_for_tag_DEL02の合計

{{ total_price_for_tag_DEL02 | money }}

total_price_for_tag_DEL03の合計

{{ total_price_for_tag_DEL03 | money }}

```

ご参考まで  
(キュー小坂)
