Variablen in Shopify Flow
Variablen sind Platzhalter, die bei der Ausführung eines Workflows durch einen Wert ersetzt werden. Durch diese Variablen werden die Eigenschaften der von deinen Workflows betroffenen Kunden, Bestellungen und Produkten beschrieben. Beispielsweise gibt es Variablen für die Bestellnummer, den Preis der Bestellung, den Namen des Kunden usw.
Flow verwendet eine andere Liquid-Version als Shopify-Themes und kann auf jede der Variablen zugreifen, die über die GraphQL-Admin-API verfügbar sind.
Die Bezeichnungen der meisten Variablen sind selbsterklärend. Beispielsweise heißt die Variable, durch die der Produktname angegeben wird, {{ product.title }}
. Wenn die Nachricht versendet wird, steht anstelle der Variablen der Name des bestellten Produkts: Large Coffee Mug
.
Variablen zu Aktionen hinzufügen
Du kannst Variablen zu jedem Textfeld hinzufügen, das den Link Variable hinzufügen enthält. Klicke unter dem entsprechenden Feld auf den Link Variable hinzufügen und wähle eine Variable aus der Liste aus.
Die in der Liste Variable hinzufügen aufgeführten Variablen sind so gefiltert, dass dir nur die Variablen angezeigt werden, die für den ausgewählten Auslöser verwendet werden können. Wenn du eine Variable aus der Liste gewählt hast, wird diese korrekt formatiert und dem Textfeld hinzugefügt.
Flow unterstützt fast alle GraphQL Admin-API-Felder.
Liquid-Variablen
Wenn du ein Entwickler mit Erfahrung im Schreiben von Liquid-Code bist, kannst du Liquid verwenden, um deine Variablen zu schreiben oder Variablen zu bearbeiten, die du über den Link Variable hinzufügen einfügst. Weitere Informationen findest du in der Referenz für die GraphQL-Admin-API.
Tags für Bedingungen und Iterationen
Du kannst Liquid-Variablen-Tags zu deinen Workflow-Nachrichten hinzufügen. Mit diesen Tags kannst du zusätzliche Informationen in deine Nachrichten aufnehmen.
Du kannst beispielsweise ein for loop
-Objekt verwenden, um eine Liste von Objekten zu durchlaufen, z. B. Einzelartikel für eine Bestellung. Mit diesen Tags kannst du Nachrichten erstellen, die Informationen wie Produkttitel, SKU, Preis und Menge für jeden Einzelartikel in einer Bestellung enthalten – so erspare es Empfängern, diese Informationen in deinem Shopify-Adminbereich nachschlagen zu müssen.
Flow unterstützt die folgenden bedingten (oder Kontrollfluss-)Tags von Liquid:
- if
- unless
- elsif/else
- case/when
- und/oder (mehrere Bedingungen)
Flow unterstützt auch die folgenden Iterationstags von Liquid:
Filter
Flow unterstützt die folgenden Liquid-Filter:
Filtername | Filtertyp |
---|---|
abs | Math |
append | String |
at_least | Math |
at_most | Math |
capitalize | String |
ceil | Math |
concat | Array |
date | Additional |
Standard | Additional |
divided_by | Math |
downcase | String |
escape | String |
zuerst | Array |
floor | Math |
join | Array |
last | Array |
lstrip | String |
map | Array |
minus | Math |
modulo | Math |
newline_to_br | String |
plus | Math |
prepend | String |
Entfernen | String |
remove_first | String |
replace | String |
replace_first | String | reverse | Array |
round | Math |
rstrip | String |
Größe | Array |
slice | String |
sortieren | Array |
split | String |
strip | String |
strip_html | String |
strip_newlines | String |
times | Math |
truncate | String |
truncatewords | String |
uniq | Array |
upcase | String |
url_encode | String |
wo | Array |
Beispiele für Variablen
Du möchtest beispielsweise einen Workflow erstellen, um eine E-Mail an einen Mitarbeiter zu senden, wenn ein Kunde mehr als 500 USD für eine Bestellung ausgibt. Du erstellst einen Workflow mithilfe des Triggers Bestellung erstellt, legst eine Bedingung fest, die wahr ist, wenn die Bestellsumme über 500 USD liegt, und verwendest die Aktion Interne E-Mail senden. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen.
Eingabe | Ausgabe |
---|---|
Bitte sende eine persönliche Dankesmitteilung an {{ order.customer.firstName }} {{ order.customer.lastName }}({{ order.customer.email }}) für die Bestellung in Höhe von {{ order.totalPriceSet.shopMoney.amount }}. | Bitte sende eine persönliche Dankesmitteilung an Jeanne Dupont (jeanne@example.com) für die Bestellung in Höhe von 763,42 USD. |
Du entscheidest, dass du einen Mitarbeiter informieren musst, wenn das Produktinventar gering ausfällt und eine Bestellung für mehr Lagerbestand aufgegeben werden muss. Du erstellst einen Workflow, der mit dem Trigger Inventarmenge geändert startet, und legst eine Bedingung, die wahr ist, fest, wenn die vorherige Inventarmenge kleiner oder gleich 10 ist. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen.
Eingabe | Ausgabe |
---|---|
Bitte bestelle "{{ product.title }}" nach. Sende eine E-Mail an inhaber@shop.de, um zu bestätigen, dass sie die Bestellung erhalten haben. | Bitte bestelle "High Waist Leggings – Schwarz" nach. Sende eine E-Mail an inhaber@shop.de, um zu bestätigen, dass sie die Bestellung erhalten haben. |
Du möchtest Bestellungen mit einer hohen Risikostufe stornieren, aber möchtest lieber, dass deine Mitarbeiter die Bestellung manuell stornieren. Du erstellst einen Workflow, der mit dem Trigger Bestellung erstellt startet, und legst eine Bedingung fest, die wahr ist, wenn die Risikostufe der Bestellung gleich hoch ist. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen.
Eingabe | Ausgabe |
---|---|
Unser Shopify-Shop hat eine Bestellung mit hohem Betrugsrisiko erhalten. Wir möchten diese Bestellung sofort stornieren, bevor sie an die Produktion gesendet wird: {{ order.name }} {{ order.billingAddress.lastName }}, {{ order.billingAddress.firstName }} {{ order.email }} Bitte bestätigen Sie den neuen Bestellstatus. Danke! |
Unser Shopify-Shop hat eine Bestellung mit hohem Betrugsrisiko erhalten. Wir möchten diese Bestellung sofort stornieren, bevor sie an die Produktion gesendet wird: #1001 Dupont, Jeanne jeanne@beispiel.de Bitte bestätigen Sie den neuen Bestellstatus. Danke! |
Beispiele für eine For-Schleife
Wenn eine Bestellung eingegangen ist, kann es hilfreich sein, eine Nachricht mit den bestellten Produkten zu versenden. Dies kannst du mithilfe von for loop
tun, um wiederholt einen Codeblock auszuführen. Textfelder, die Variablen unterstützen, unterstützen auch for-Schleifen und das forloop-Objekt.
Du möchtest beispielsweise einen Workflow erstellen, der eine Liste aller SKUs und Mengen in einer Bestellung zurückgibt. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen.
Eingabe | Ausgabe |
---|---|
Bestellübersicht: {% for a in order.lineItems %} SKU: {{a.sku}} ( {{a.quantity}} ), {% endfor %} |
Bestellübersicht: 8987097979 (50) 8877778887 (3) 888998898B (1) |
Du entscheidest dich, der E-Mail weitere Informationen hinzuzufügen, einschließlich Produktname, Artikelnummer (SKU), Preis pro Artikel und Versandinformationen des Kunden. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen.
Eingabe | Ausgabe |
---|---|
Bestellübersicht: {% for a in order.lineItems %} Produkt: {{a.title}} SKU: {{a.sku}} Preis (pro Einheit): {{a.originalUnitPriceSet.shopMoney.amount}} USD Anzahl: {{a.quantity}} {% endfor %} |
Bestellübersicht: Produkt: High Waist Leggings – Schwarz SKU: 8987097979 Preis (pro Einheit): 8,49 USD Menge: 5 Produkt: Sportsocken – Blau SKU: 8889988B Preis (pro Einheit): 5,61 USD Menge: 2 |
Du musst verkaufte Artikel verfolgen, die von einem bestimmten Anbieter bereitgestellt werden. Im Abschnitt Nachricht der Aktion Interne E-Mail senden verwendest du die folgenden Variablen und schließt ein if
im Objekt for loop
ein.
Eingabe | Ausgabe |
---|---|
Verkauftes Acme-Produkt: {% for x in order.lineItems %} {% if x.vendor == 'acme-vendor' %} Produktname: {{x.title}} SKU: {{x.sku}} {% endif %} {% endfor %} |
Verkauftes Acme-Produkt: Produktname: High Waist Leggings – Schwarz SKU: 8987097979 |
Komplexe Datenobjekte in Shopify Flow
Shopify Flow unterstützt aus den folgenden Gründen nicht die Ausgabe von Arrays und Objekten:
- Das Ausgeben von nicht erforderlichen Daten ist für die GraphQL-API veraltet. Möglicherweise werden zu große Abfragen erstellt, die dazu führen, dass dein Workflow fehlschlägt.
- Bei der Einführung neuer Funktionen werden neue API-Felder hinzugefügt, die Probleme bei deinem Workflow verursachen können.
Wenn zu viele Daten automatisch gesendet werden, schlägt der Workflow fehl. Anstatt Arrays und Objekte direkt aufzurufen, solltest du Schleifen für Arrays verwenden und nur die gewünschten Felder einschließen.
Anstatt beispielsweise {{ order.lineItems }}
direkt aufzurufen, verwende das folgende Format zum Aufrufen bestimmter Felder. Diese Beispiele umfassen alle Felder, die beim direkten Aufruf des Arrays oder Objekts eingeschlossen werden würden. Kopiere die erforderlichen Felder und füge sie ein.
{% 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 %}
]
}