Shopify Flowの変数
変数は、ワークフローの実行時に値に置き換えられるプレースホルダーです。これらの変数は、ワークフローに関係するお客様、注文、商品の属性を表します。たとえば、注文番号、注文価格、お客様名などの変数があります。
Flowでは、Shopifyテーマとは異なるバージョンのLiquidを使用し、GraphQL Admin APIを通して使用可能な任意に変数にアクセスできます。
ほとんどの変数の名前は自己記述型です。たとえば、商品の名前を表示する変数は、{{ product.title }}
です。メッセージが送信されると、この変数は、Large Coffee Mug
のような注文された商品の名前に置き換えられます。
アクションに変数を追加する
[変数を追加する] のリンクを含むテキストフィールドに変数を追加することができます。関連するフィールドの下にある [変数を追加する] のリンクをクリックして、リストから変数を選択します。
[変数を追加] リストの変数はフィルタリングされているため、選択したトリガーに適用される変数のみが表示されます。リストから変数を選択すると、変数が適切にフォーマットされ、テキストボックスに追加されます。
Flowは、ほとんどすべてのGraphQL Admin APIをサポートしています。
Liquid変数
Liquidコードを記述した経験がある開発者の場合、Liquidを使用して変数を記述したり、[変数を追加する] リンクを使用して挿入した変数を編集したりすることができます。詳細については、「GraphQL Admin APIの参考情報」を参照してください。
条件タグと繰り返しタグ
Liquidの変数タグをワークフローメッセージに手動で追加できます。これらのタグを使用して、メッセージにさらに情報を含めることができます。
たとえば、for loop
オブジェクトを使用して、注文の項目といったオブジェクトのリスト全体を繰り返し処理できます。このようなタグを使用すると、商品名、SKU、価格、注文数量など各項目の詳細を含むメッセージを作成できるため、受信者が管理画面でこの情報を調べる必要がなくなります。
Flowでは、以下のLiquid条件 (または制御フロー) タグをサポートしています。
- if
- unless
- elsif/else
- case/when
- and/or (複数の条件)
Flowでは、以下のLiquidの繰り返しタグもサポートしています。
絞り込み
Flowは以下のLiquidフィルターに対応しています。
フィルター名 | フィルターのタイプ |
---|---|
abs | Math |
append | String |
at_least | Math |
at_most | Math |
capitalize | String |
ceil | Math |
concat | Array |
date | Additional |
デフォルト | Additional |
divided_by | Math |
downcase | String |
escape | String |
first | Array |
floor | Math |
join | Array |
last | Array |
lstrip | String |
map | Array |
minus | Math |
modulo | Math |
newline_to_br | String |
Shopifyプラス | Math |
prepend | String |
削除する | String |
remove_first | String |
replace | String |
replace_first | String | reverse | Array |
round | Math |
rstrip | String |
サイズ | Array |
slice | String |
並び替え | Array |
split | String |
strip | String |
strip_html | String |
strip_newlines | String |
times | Math |
truncate | String |
truncatewords | String |
uniq | Array |
upcase | String |
url_encode | String |
where | Array |
変数の例
たとえば、お客様が500ドルを超える注文をしたときに従業員にメールを送信するワークフローを作成するとします。[注文が作成されたとき] トリガーを使用するワークフローを作成し、注文合計が500ドルより多い場合にtrueとする条件を設定して、[内部メールを送信する] アクションを使用します。[内部メールを送信する] アクションの [メッセージ] セクションに、以下の変数を使用できます。
入力 | 出力 |
---|---|
{{ order.customer.firstName }} {{ order.customer.lastName }}({{ order.customer.email }})に、 {{ order.totalPriceSet.shopMoney.amount }}ドルの注文に関するサンキュー通知を送信してください。 | Jeanne Dupont (jeanne@example.com) に763.42ドルの注文に関するサンキュー通知を送ってください。 |
あなたは、商品在庫が少なくなり在庫を増やすための入荷が必要になったタイミングでスタッフメンバーに通知をする必要があると考えます。[在庫数量が変更されたとき] トリガーで起動するワークフローを作成し、[数量が変わる前の商品バリエーションの在庫数量] が10以下の場合にtrueとなる条件を設定します。[内部メールを送信する] アクションの [メッセージ] セクションに、以下の変数を使用できます。
入力 | 出力 |
---|---|
{{ product.title }}を再入荷してください。owner@store.comにメールを送信して先方が注文書を受け取ったかどうかを確認してください。 | ハイウエストレギンス - 黒を再入荷してください。owner@example.comにメールを送信して先方が注文書を受け取ったかどうかを確認してください。 |
あなたは、リスクレベルの高い注文をキャンセルする場合に、スタッフの手動による注文のキャンセルを希望します。[注文が作成されたとき] トリガーで起動するワークフローを作成し、注文のリスクレベルが「高」と一致する場合にtrueとなる条件を設定します。[内部メールを送信する] アクションの [メッセージ] セクションに、以下の変数を使用できます。
入力 | 出力 |
---|---|
Shopifyストアが、不正注文のリスクが高い注文を受け取りました。この注文内容が製造工程に送られる前に、以下の注文を即座にキャンセルしたいと思います。 {{ order.name }} {{ order.billingAddress.lastName }},{{ order.billingAddress.firstName }} {{ order.email }} その後の注文状況を確認してください。よろしくお願いします。 |
Shopifyストアが、不正注文のリスクが高い注文を受け取りました。この注文内容が製造工程に送られる前に、以下の注文を即座にキャンセルしたいと思います。 #1001 Dupont, Jeanne jeanne@example.com その後の注文状況を確認してください。よろしくお願いします。 |
forループの例
注文を受け付けた際には、注文の商品情報を含むメッセージを送信すると便利です。それを行うのに、for loop
を使用すると、コードブロックを繰り返し実行してくれます。変数に対応しているテキストフィールドは、for loopsおよびforloopオブジェクトにも対応しています。
たとえば、注文内のすべてのSKUと数量のリストを返すワークフローを作成するとします。[内部メールを送信する] アクションの [メッセージ] セクションに、以下の変数を使用できます。
入力 | 出力 |
---|---|
注文サマリー: {% for a in order.lineItems %} SKU: {{a.sku}} ({{a.quantity}}), {% endfor %} |
注文サマリー: 8987097979 (50) 8877778887 (3) 888998898B (1) |
メールに商品名、SKU、アイテムごとの価格、お客様の配送情報などの詳細情報を追加することにしたとします。[内部メールを送信する] アクションの [メッセージ] セクションに、以下の変数を使用できます。
入力 | 出力 |
---|---|
注文サマリー: {% for a in order.lineItems %} 商品: {{a.title}} SKU: {{a.sku}} 価格 (単価): {{a.originalUnitPriceSet.shopMoney.amount}}ドル 数量: {{a.quantity}} {% endfor %} |
注文サマリー: 商品: ハイウエストレギンス - 黒 SKU: 8987097979 価格 (単価): $8.49 数量: 5 商品: アスレチックソックス - 青 SKU: 888998898B 価格 (単価): 5.61ドル 数量: 2 |
特定の販売元から仕入れて販売したアイテムを追跡する必要があるとします。[内部メールを送信する] アクションの [メッセージ] セクションで、以下の変数を使用してfor loop
にif
文を加えることができます。
入力 | 出力 |
---|---|
販売済みのAcme商品: {% for x in order.lineItems %} {% if x.vendor == 'acme-vendor' %} 商品名: {{x.title}} SKU: {{x.sku}} {% endif %} {% endfor %} |
販売済みのAcme商品: 商品名: ハイウエストレギンス - 黒 SKU: 8987097979 |
Shopify Flowの複雑なデータオブジェクト
以下の理由により、Shopify Flowでは配列やオブジェクトの出力がサポートされていません。
- 必要のないデータを出力することは、GraphQL APIでは推奨されません。また、それによってクエリのサイズが大きくなり、ワークフローが失敗する可能性があります。
- 新機能が導入された場合、新しいAPIフィールドが追加され、ワークフローが壊れる可能性があります。
あまりにも多くのデータが自動的に送信されると、ワークフローの実行に失敗します。配列とオブジェクトを直接呼び出す代わりに、配列をループ処理して、必要なフィールドのみを含めます。
たとえば、{{ order.lineItems }}
を直接呼び出す代わりに、以下の形式で特定のフィールドを呼び出します。これには、配列またはオブジェクトを直接呼び出すことによって加えられるすべてのフィールドが含まれています。必要なフィールドをコピーして貼り付けてください。
{% for li in order.lineItems %}
{% comment %}li.contract - omitted{% endcomment %}
{% for ca in li.customAttributes %}
{{ ca.key }}
{{ ca.value }}
{% endfor %}
{% for da in li.discountAllocations %}
{{ da.allocatedAmountSet.presentmentMoney.amount }}
{{ da.allocatedAmountSet.presentmentMoney.currencyCode }}
{{ da.allocatedAmountSet.shopMoney.amount }}
{{ da.allocatedAmountSet.shopMoney.currencyCode }}
{% endfor %}
{{ li.discountedTotalSet.presentmentMoney.amount }}
{{ li.discountedTotalSet.presentmentMoney.currencyCode }}
{{ li.discountedTotalSet.shopMoney.amount }}
{{ li.discountedTotalSet.shopMoney.currencyCode }}
{{ li.discountedUnitPriceSet.presentmentMoney.amount }}
{{ li.discountedUnitPriceSet.presentmentMoney.currencyCode }}
{{ li.discountedUnitPriceSet.shopMoney.amount }}
{{ li.discountedUnitPriceSet.shopMoney.currencyCode }}
{% comment %}li.duties - omitted {% endcomment %}
{{ li.fulfillableQuantity }}
{{ li.fulfillmentService.callbackUrl }}
{{ li.fulfillmentService.fulfillmentOrdersOptIn }}
{{ li.fulfillmentService.handle }}
{{ li.fulfillmentService.id }}
{{ li.fulfillmentService.inventoryManagement }}
{% comment %}rest of location omitted{% endcomment %}
{{ li.fulfillmentService.location.name }}
{{ li.fulfillmentService.productBased }}
{{ li.fulfillmentService.serviceName }}
{% for sm in li.fulfillmentService.shippingMethods %}
{{ sm.code }}
{{ sm.label }}
{% endfor %}
{{ li.fulfillmentService.type }}
{{ li.fulfillmentStatus }}
{{ li.id }}
{{ li.image.altText }}
{{ li.image.height }}
{{ li.image.id }}
{% comment %}li.image.metafield omitted{% endcomment %}
{% comment %}li.image.privateMetafield omitted{% endcomment %}
{{ li.image.width }}
{{ li.merchantEditable }}
{{ li.name }}
{{ li.nonFulfillableQuantity }}
{{ li.originalTotalSet.presentmentMoney.amount }}
{{ li.originalTotalSet.presentmentMoney.currencyCode }}
{{ li.originalTotalSet.shopMoney.amount }}
{{ li.originalTotalSet.shopMoney.currencyCode }}
{{ li.originalUnitPriceSet.presentmentMoney.amount }}
{{ li.originalUnitPriceSet.presentmentMoney.currencyCode }}
{{ li.originalUnitPriceSet.shopMoney.amount }}
{{ li.originalUnitPriceSet.shopMoney.currencyCode }}
{% comment %}rest of product omitted{% endcomment %}
{{ li.product.title }}
{{ li.quantity }}
{{ li.refundableQuantity }}
{{ li.requiresShipping }}
{{ li.restockable }}
{{ li.sellingPlan.name }}
{{ li.sku }}
{% for tl in li.taxLines %}
{{ tl.priceSet.presentmentMoney.amount | json }}
{{ tl.priceSet.presentmentMoney.currencyCode | json }}
{{ tl.priceSet.shopMoney.amount | json }}
{{ tl.priceSet.shopMoney.currencyCode | json }}
{{ tl.rate | json }}
{{ tl.ratePercentage | json }}
{{ tl.title | json }}
{% endfor %}
{{ li.taxable }}
{{ li.title }}
{{ li.totalDiscountSet.presentmentMoney.amount }}
{{ li.totalDiscountSet.presentmentMoney.currencyCode }}
{{ li.totalDiscountSet.shopMoney.amount }}
{{ li.totalDiscountSet.shopMoney.currencyCode }}
{{ li.unfulfilledDiscountedTotalSet.presentmentMoney.amount }}
{{ li.unfulfilledDiscountedTotalSet.presentmentMoney.currencyCode }}
{{ li.unfulfilledDiscountedTotalSet.shopMoney.amount }}
{{ li.unfulfilledDiscountedTotalSet.shopMoney.currencyCode }}
{{ li.unfulfilledOriginalTotalSet.presentmentMoney.amount }}
{{ li.unfulfilledOriginalTotalSet.presentmentMoney.currencyCode }}
{{ li.unfulfilledOriginalTotalSet.shopMoney.amount }}
{{ li.unfulfilledOriginalTotalSet.shopMoney.currencyCode }}
{{ li.unfulfilledQuantity }}
{% comment %}rest of variant omitted{% endcomment %}
{{ li.variant.title }}
{{ li.variantTitle }}
{{ li.vendor }}
{% endfor %}
{
"lineItems": [
{% for li in order.lineItems %}
{% if forloop.first != true %},{% endif %}
{
"contract": {
{% comment %}rest of contract omitted{% endcomment %}
"id": {{ li.contract.id | json }}
},
"customAttributes": [
{% for ca in li.customAttributes %}
{% if forloop.first != true %},{% endif %}
{
"key":{{ ca.key | json }},
"value":{{ ca.value | json }}
}
{% endfor %}
],
"discountAllocations": [
{% for da in li.discountAllocations %}
{% if forloop.first != true %},{% endif %}
"allocatedAmountSet": {
"presentmentMoney" : {
"amount": {{ da.allocatedAmountSet.presentmentMoney.amount | json }},
"currencyCode": {{ da.allocatedAmountSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ da.allocatedAmountSet.shopMoney.amount | json }},
"currencyCode": {{ da.allocatedAmountSet.shopMoney.currencyCode | json }}
}
}
{% endfor %}
],
"discountedTotalSet": {
"presentmentMoney" : {
"amount": {{ li.discountedTotalSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.discountedTotalSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.discountedTotalSet.shopMoney.amount | json }},
"currencyCode": {{ li.discountedTotalSet.shopMoney.currencyCode | json }}
}
},
"discountedUnitPriceSet": {
"presentmentMoney" : {
"amount": {{ li.discountedUnitPriceSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.discountedUnitPriceSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.discountedUnitPriceSet.shopMoney.amount | json }},
"currencyCode": {{ li.discountedUnitPriceSet.shopMoney.currencyCode | json }}
}
},
"duties": [
{% for duty li.duties %}
{% if forloop.first != true %},{% endif %}
{
{% comment %}rest of duties omitted{% endcomment %}
"id": {{ duty.id | json }}
}
{% endfor %}
],
"fulfillableQuantity": {{ li.fulfillableQuantity | json }},
"fulfillmentService": {
"callbackUrl":{{ li.fulfillmentService.callbackUrl | json }},
"fulfillmentOrdersOptIn": {{ li.fulfillmentService.fulfillmentOrdersOptIn | json }},
"handle": {{ li.fulfillmentService.handle | json }},
"id": {{ li.fulfillmentService.id | json }},
"inventoryManagement": {{ li.fulfillmentService.inventoryManagement | json }},
{% comment %}fulfillmentService.inventoryManagement - omitted {% endcomment %}
"productBased": {{ li.fulfillmentService.productBased | json }},
"serviceName": {{ li.fulfillmentService.serviceName | json }},
"shippingMethods": [
{% for sm in li.fulfillmentService.shippingMethods %}
{% if forloop.first != true %},{% endif %}
{
"code": {{ sm.code | json }},
"label": {{ sm.label | json }}
}
{% endfor %}
],
"type": {{ li.fulfillmentService.type | json }}
},
"fulfillmentStatus": {{ li.fulfillmentStatus | json }},
"id": {{ li.id | json }},
"image": {
"altText": {{ li.image.altText | json }},
"height": {{ li.image.height | json }},
"id": {{ li.image.id | json }},
{% comment %}li.image.metafield omitted{% endcomment %}
{% comment %}li.image.privateMetafield omitted{% endcomment %}
"width":{{ li.image.width | json }}
},
"merchantEditable": {{ li.merchantEditable | json }},
"name": {{ li.name | json }},
"nonFulfillableQuantity": {{ li.nonFulfillableQuantity | json }},
"originalTotalSet": {
"presentmentMoney" : {
"amount": {{ li.originalTotalSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.originalTotalSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.originalTotalSet.shopMoney.amount | json }},
"currencyCode": {{ li.originalTotalSet.shopMoney.currencyCode | json }}
}
},
"originalUnitPriceSet": {
"presentmentMoney" : {
"amount": {{ li.originalUnitPriceSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.originalUnitPriceSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.originalUnitPriceSet.shopMoney.amount | json }},
"currencyCode": {{ li.originalUnitPriceSet.shopMoney.currencyCode | json }}
}
},
"product": {
{% comment %}rest of Product omitted{% endcomment %}
"title": {{ li.product.title | json }}
},
"quantity": {{ li.quantity | json }},
"refundableQuantity": {{ li.refundableQuantity | json }},
"requiresShipping": {{ li.requiresShipping | json }},
"restockable": {{ li.restockable | json }},
"sellingPlan": {
"name": {{ li.sellingPlan.name | json }}
},
"sku": {{ li.sku | json }},
"taxLines": [
{% for tl in li.taxLines %}
{% if forloop.first != true %},{% endif %}
{
"priceSet": {
"presentmentMoney" : {
"amount": {{ tl.priceSet.presentmentMoney.amount | json }},
"currencyCode": {{ tl.priceSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ tl.priceSet.shopMoney.amount | json }},
"currencyCode": {{ tl.priceSet.shopMoney.currencyCode | json }}
}
},
"rate": {{ tl.rate | json }},
"ratePercentage": {{ tl.ratePercentage | json }},
"title": {{ tl.title | json }}
}
{% endfor %}
],
"taxable":{{ li.taxable | json }},
"title":{{ li.title | json }},
"totalDiscountSet": {
"presentmentMoney" : {
"amount": {{ li.totalDiscountSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.totalDiscountSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.totalDiscountSet.shopMoney.amount | json }},
"currencyCode": {{ li.totalDiscountSet.shopMoney.currencyCode | json }}
}
},
"unfulfilledDiscountedTotalSet": {
"presentmentMoney" : {
"amount": {{ li.unfulfilledDiscountedTotalSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.unfulfilledDiscountedTotalSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.unfulfilledDiscountedTotalSet.shopMoney.amount | json }},
"currencyCode": {{ li.unfulfilledDiscountedTotalSet.shopMoney.currencyCode | json }}
}
},
"unfulfilledOriginalTotalSet": {
"presentmentMoney" : {
"amount": {{ li.unfulfilledOriginalTotalSet.presentmentMoney.amount | json }},
"currencyCode": {{ li.unfulfilledOriginalTotalSet.presentmentMoney.currencyCode | json }}
},
"shopMoney": {
"amount": {{ li.unfulfilledOriginalTotalSet.shopMoney.amount | json }},
"currencyCode": {{ li.unfulfilledOriginalTotalSet.shopMoney.currencyCode | json }}
}
},
"unfulfilledQuantity": {{ li.unfulfilledQuantity | json }},
"variant": {
{% comment %}rest of variant omitted {% endcomment %}
"title": {{ li.variant.title | json }}
},
"variantTitle": {{ li.variantTitle | json }},
"vendor": {{ li.vendor | json }}
}
{% endfor %}
]
}