# 注文の確認メールの振り分けを商品と決済方法に合わせて行いたい

**URL:** <https://community.shopify.com/t/topic/268764>\
**Category:** 技術的なQ＆A\
**Created:** [November 15, 2023, 10:19am UTC](https://community.shopify.com/t/topic/268764 "2023-11-15T10:19:33Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

Shopifyの注文確認メールで、商品と決済方法の組み合わせに応じて文面を振り分ける方法についての質問と解決。

**要件:**
- Dawnテーマを使用
- 商品A/B/Cと決済方法(クレジットカード/銀行振込)の組み合わせで計6パターンのメール文面を振り分けたい

**問題点:**
- 初期コードでは振り分けが正しく動作していなかった
- Liquidテンプレートのロジックに不具合があった

**解決策:**
Qcoltd氏が修正コードを提供:
- 各商品フラグ(`has_item_a`等)を`false`で初期化
- `line_items`をループして商品を判定
- 各商品ごとに`order.transactions[0].gateway`で決済方法を取得
- 条件分岐で適切なメール文面を表示

**結果:**
- 質問者は解決を確認し、感謝の意を表明
- 実装前の検証テストが推奨された

<div class="post-metadata">

**Author:** ![KDesign](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@KDesign](https://community.shopify.com/u/KDesign)\
**Post date:** [November 15, 2023, 10:19am UTC](https://community.shopify.com/t/topic/268764/1 "2023-11-15T10:19:33Z")

</div>

お世話になります。

コーディングについて初心者となります。初歩的な質問かもしれません。

テーマはDawnを使用しております。

商品と決済方法に合わせて何パターンかのメールの文面を振り分けたいと考えております。

たとえば、商品A・B・Cと3種類ありましたら計6種類のメールの文面を振り分けたいと考えております。

1.商品Aのクレジットカード決済

2.商品Aの銀行決済

3.商品Bのクレジットカード決済

4.商品Bの銀行決済

5.商品Cのクレジットカード決済

6.商品Cの銀行決済

現状、以下のようなコードを書いたのですが、うまく振り分けができておりません。

```auto
{% for line in subtotal_line_items %}
{% if line.title contains '商品A' %}
{% assign has_item_a = true %}
{% endif %}
{% if line.title contains '商品B' %}
{% assign has_item_b = true %}
{% endif %}
{% if line.title contains '商品C' %}
{% assign has_item_c = true %}
{% endif %}
{% endfor %}

{% if has_item_a %}
    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_a = false %}

        商品A銀行振込の文章

    {% else %}

    　商品Aクレジットカードの文章

    {% endif %}

{% elsif has_item_b %}

    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_b = false %}

        商品B銀行振込の文章

    {% else %}

    　商品Bクレジットカードの文章

    {% endif %}

{% elsif has_item_c %}

    {% if order.transactions[0].gateway == "Bank Deposit" %}
    {% assign has_item_c = false %}

        商品C銀行振込の文章

    {% else %}

    　商品Cクレジットカードの文章

    {% endif %}
 {% endif %}

```

何時間も苦戦しているのですが、一向に解決できずにおります。

ご教授いただけますと幸いです。

---

<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:** [November 17, 2023, 10:29am UTC](https://community.shopify.com/t/topic/268764/2 "2023-11-17T10:29:17Z")

</div>

@KDesign 様

注文の確認メールで文面を変更したい件ですが、記載いただいたコードを元に下記のように調整させていただきました。

```markup
{% assign has_item_a = false %}
{% assign has_item_b = false %}
{% assign has_item_c = false %}

{% for line in line_items %}
  {% if line.title contains '商品A' %}
    {% assign has_item_a = true %}
  {% endif %}
  {% if line.title contains '商品B' %}
    {% assign has_item_b = true %}
  {% endif %}
  {% if line.title contains '商品C' %}
    {% assign has_item_c = true %}
  {% endif %}
{% endfor %}

{% if has_item_a %}
  {% assign gateway_a = order.transactions[0].gateway %}
  {% if gateway_a == "Bank Deposit" %}
    商品Aの銀行振込の文章
  {% else %}
    商品Aのクレジットカードの文章
  {% endif %}
{% endif %}

{% if has_item_b %}
  {% assign gateway_b = order.transactions[0].gateway %}
  {% if gateway_b == "Bank Deposit" %}
    商品Bの銀行振込の文章
  {% else %}
    商品Bのクレジットカードの文章
  {% endif %}
{% endif %}

{% if has_item_c %}
  {% assign gateway_c = order.transactions[0].gateway %}
  {% if gateway_c == "Bank Deposit" %}
    商品Cの銀行振込の文章
  {% else %}
    商品Cのクレジットカードの文章
  {% endif %}
{% endif %}

```

大きな変更点としては、商品毎にif文を書かせていただきました。

コードの検証テストはできておりませんので、ご利用時は実際にチェックください。

ご参考まで。

（キュー小坂）

---

<div class="post-metadata">

**Author:** ![KDesign](https://avatars.discourse-cdn.com/v4/letter/k/c57346/32.png) [@KDesign](https://community.shopify.com/u/KDesign)\
**Post date:** [November 17, 2023, 11:14am UTC](https://community.shopify.com/t/topic/268764/3 "2023-11-17T11:14:00Z")

</div>

うまくいきました！

本当に本当に感謝いたします。

ありがとうございます。
