# 通知メールの条件分岐について

**URL:** <https://community.shopify.com/t/topic/278152>\
**Category:** 技術的なQ＆A\
**Created:** [December 18, 2023, 3:01am UTC](https://community.shopify.com/t/topic/278152 "2023-12-18T03:01:14Z")\
**Posts on this page:** 3\
**Page:** 1

## AI-generated summary

**質問内容：**
通知メールのカスタマイズに関する2つの質問が投稿されました：
1. 購入商品の商品タイプによって通知メールの文言を条件分岐できるか
2. 商品タイトルでの条件分岐がうまく動作しない

**解決方法：**
株式会社Qの小坂氏が、商品タイプによる条件分岐が可能であることを確認し、具体的なサンプルコードを提供しました。

**提供されたコード構造：**
- `hasSalesProduct`と`hasBuybackProduct`の変数を初期化（false）
- 注文データを解析し、「販売商品」「買取商品」の商品タイプが存在する場合、対応する変数をtrueに設定
- 条件分岐で3パターンの文面を表示：
  - 販売商品のみの場合
  - 買取商品のみの場合
  - 両方が含まれる場合

**結果：**
質問者は理想的な分岐が実現でき、今後の応用にも活用できると感謝の意を表明。問題は解決済み。

<div class="post-metadata">

**Author:** ![ho-jo](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@ho-jo](https://community.shopify.com/u/ho-jo)\
**Post date:** [December 18, 2023, 3:01am UTC](https://community.shopify.com/t/topic/278152/1 "2023-12-18T03:01:14Z")

</div>

通知メールのカスタマイズで以下２つ質問です。

１、購入された商品の商品タイプによって通知メールの文言を条件分岐させることは可能でしょうか。

調べたのですが変数がなさそうだったので質問させていただきました。

参考：[https://help.shopify.com/ja/manual/orders/notifications/email-variables#line-item-properties](https://help.shopify.com/ja/manual/orders/notifications/email-variables#line-item-properties)

２、もし変数がない場合、商品タイトルで条件分岐させようと思ったのですが、こちらもうまくできません。

やりたいことは3パターンに分けることなのですが、ifなのかunlessがふさわしいのかも困っております。

ご教示お願いいたします。

・販売商品のみ含まれていた場合の文面 A

・買取商品のみ含まれていた場合の文面 B

・両方含まれていた場合の文面 C

```auto
{% for line in line_items %}
{% for title in line.title %}
{% unless line.title contains '買取' %}
A
{% else unless line.title contains '販売' %}
B
{% else %}
C（AもBも両方とも含まれる場合） 
{% endunless %}
{% endfor %}
{% 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:** [December 18, 2023, 9:23am UTC](https://community.shopify.com/t/topic/278152/2 "2023-12-18T09:23:25Z")

</div>

@ho-jo 様

ご質問いただいている、商品タイプで通知メールの文面を変更することは可能かと思います。

下記に商品タイプが「販売商品」「買取商品」において、

文面が変更できるサンプルコードを記載させていただきました。

### サンプルコード

```markup
{% assign hasSalesProduct = false %}
{% assign hasBuybackProduct = false %}
{% for line in line_items %}
  {% for product_type in line.product.type %}
    {% if product_type == '販売商品' %}
      {% assign hasSalesProduct = true %}
    {% elsif product_type == '買取商品' %}
      {% assign hasBuybackProduct = true %}
    {% endif %}
  {% endfor %}
{% endfor %}
{% if hasSalesProduct == true and hasBuybackProduct == false %}
  販売商品のみの場合
{% elsif hasSalesProduct == false and hasBuybackProduct == true %}
  買取商品のみの場合
{% else %}
  販売商品と買取商品の両方が含まれている場合
{% endif %}

```

#### コードの簡単な説明

下記部分で、販売商品・買取商品の商品タイプの変数設定（初期値はfalse）

```markup
{% assign hasSalesProduct = false %}
{% assign hasBuybackProduct = false %}

```

下記部分で、実際の注文データを解析し、それぞれの商品タイプがあった場合、  
上記で設定した変数にtrueを代入

```markup
{% for line in line_items %}
  {% for product_type in line.product.type %}
    {% if product_type == '販売商品' %}
      {% assign hasSalesProduct = true %}
    {% elsif product_type == '買取商品' %}
      {% assign hasBuybackProduct = true %}
    {% endif %}
  {% endfor %}
{% endfor %}

```

下記部分で、それぞれの文面を表示するための分岐（注文データにそれぞれの商品タイプが有るか無いかで判断）

```markup
{% if hasSalesProduct == true and hasBuybackProduct == false %}
  販売商品のみの場合
{% elsif hasSalesProduct == false and hasBuybackProduct == true %}
  買取商品のみの場合
{% else %}
  販売商品と買取商品の両方が含まれている場合
{% endif %}

```

ご参考まで

（キュー小坂）

---

<div class="post-metadata">

**Author:** ![ho-jo](https://avatars.discourse-cdn.com/v4/letter/h/90ced4/32.png) [@ho-jo](https://community.shopify.com/u/ho-jo)\
**Post date:** [December 19, 2023, 12:41am UTC](https://community.shopify.com/t/topic/278152/3 "2023-12-19T00:41:23Z")

</div>

株式会社Q (キュー) 小坂様

ご丁寧な解説とご教示ありがとうございました。

理想の分岐ができました。

こちらのサンプルをもとに応用もできるかと思いますので今後も参考にさせていただきます。

お忙しいところ本当にありがとうございました。
