Shopify Flow 中的變數
「變數」是執行工作流程時會以特定數值來取代的佔位符。這些變數會描述工作流程中所涉及之顧客、訂單及商品的屬性。舉例來說,訂單編號、訂單金額、顧客名稱等資訊都擁有對應的變數。
Flow 使用與 Shopify 佈景主題不同的 Liquid 版本,並可透過 GraphQL管理員 API 存取任何可用的變數。
多數變數都能從名稱得知其功能。舉例來說,顯示產品名稱的變數就是 {{ product.title }}
。當訊息送出後,此變數就會被訂購產品名稱取代:Large Coffee Mug
。
將變數新增至動作
您可以將變數新增至內含「新增變數」連結的任何文字欄位之中:點擊相關欄位下方的「新增變數」連結,然後從清單中選擇一個變數。
「新增變數」清單中的變數會經過篩選,僅向您顯示適用於您所選擇的觸發條件的變數。從清單中選擇變數之後,該變數會進行適當的格式化,然後新增至文字方塊之中。
Flow 支援幾乎所有 GraphQL 管理員 API 欄位。
Liquid 變數
如果您是具有撰寫 Liquid 程式碼經驗的開發人員,便可使用 Liquid 編寫變數,或編輯使用新增變數連結插入的變數。如須瞭解詳情,請參閱 GraphQL 管理員 API 參考資料。
條件與迭代標籤
您可以手動將 Liquid 變數標籤新增至您的工作流程訊息。您可以使用這些標籤,在訊息中包含更多的資訊。
舉例來說,您可以使用for loop
物件來迭代物件清單,例如某一筆訂單的商品項目。藉由這些標籤,您可以建立包含訂單詳細資訊的訊息(例如訂單中各個商品項目的商品標題、SKU、價格及數量),使您的收件者無須在 Shopify 管理介面查找這些資訊。
Flow 支援下列 Liquid 條件 (或控制流程) 標籤:
- if
- unless
- elsif/else
- case/when
- and/or (多項篩選條件)
Flow 也支援下列 Liquid 迭代標籤:
篩選
Flow 支援下列 Liquid 篩選條件:
篩選條件名稱 | 篩選條件類型 |
---|---|
abs | 數學 |
append | String |
at_least | 數學 |
at_most | 數學 |
capitalize | String |
ceil | 數學 |
concat | 陣列 |
date | 其他 |
default | 其他 |
divided_by | 數學 |
downcase | String |
escape | String |
第一 | 陣列 |
floor | 數學 |
join | 陣列 |
last | 陣列 |
lstrip | String |
地圖 | 陣列 |
minus | 數學 |
modulo | 數學 |
newline_to_br | String |
加 | 數學 |
prepend | String |
remove | String |
remove_first | String |
replace | String |
replace_first | String | reverse | 陣列 |
round | 數學 |
rstrip | String |
大小 | 陣列 |
slice | String |
排序 | 陣列 |
split | String |
strip | String |
strip_html | String |
strip_newlines | String |
times | 數學 |
truncate | String |
truncatewords | String |
uniq | 陣列 |
upcase | String |
url_encode | String |
哪裡 | 陣列 |
變數範例
舉例來說,您想要建立一個工作流程,在顧客的訂單花費超過 $500 美元時傳送電子郵件給員工。您使用訂單已建立觸發條件建立工作流程,將訂單總金額超過 $500 美元的條件設定為 true,接著使用「傳送內部電子郵件」動作。在「傳送內部電子郵件」動作的「訊息」區段中,您使用以下變數。
輸入 | 輸出 |
---|---|
請傳送個人感謝備註給 {{ order.customer.firstName }} {{ order.customer.lastName }} ({{ order.customer.email }}), 感謝對方訂購了 $ {{ order.totalPriceSet.shopMoney.amount }} 的商品。 | 請傳送個人感謝備註給 Jeanne (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 杜維達,Jeanne jeanne@example.com 請確認新的訂單狀態。謝謝! |
「For 迴圈」範例
收到訂單時,建議您傳送包含訂購商品的訊息。您可以使用重複執行程式碼 for loop
來完成此操作。支援變數的文字欄位也支援 for 迴圈和 for 迴圈物件。
舉例來說,您想要建立一個工作流程,回傳訂單中所有存貨單位 (SKU) 和數量的清單。在「傳送內部電子郵件」動作的「訊息」區段中,您使用以下變數。
輸入 | 輸出 |
---|---|
訂單摘要: {% for a in order.lineItems %} SKU: {{a.sku}} ({{a.quantity}}), {% endfor %} |
訂單摘要: 8987097979 (50) 8877778887 (3) 8889988898B (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 %}
]
}