Variabelen in Shopify Flow
Variabelen zijn tijdelijke aanduidingen die worden vervangen door waarden wanneer een workflow wordt uitgevoerd. Deze variabelen beschrijven de kenmerken van de klanten, bestellingen en producten waarop je workflows van toepassing zijn. Er zijn bijvoorbeeld variabelen voor het bestelnummer, de prijs van de bestelling, de naam van de klant, enzovoort.
De namen van de meeste variabelen spreken voor zich. De variabele waarmee de naam van het product wordt weergegeven, is bijvoorbeeld {{ product.title }}
. Wanneer het bericht wordt verzonden, wordt deze variabele vervangen door de naam van het bestelde product: Large Coffee Mug
.
Variabelen aan acties toevoegen
Je kunt variabelen toevoegen aan elk tekstveld dat de link Variabele toevoegen bevat. Klik op de link Variabele toevoegen onder het relevante veld en kies vervolgens een variabele uit de lijst.
De variabelen in de lijst Variabele toevoegen worden gefilterd, zodat je alleen de variabelen ziet die van toepassing zijn op de trigger die je hebt gekozen. Nadat je een variabele in de lijst hebt gekozen, wordt deze op de juiste manier opgemaakt en aan het tekstvak toegevoegd.
Flow ondersteunt bijna alle GraphQL-admin-API-velden.
Liquid-variabelen
Als je een ontwikkelaar bent die ervaring heeft met het schrijven van Shopify Liquid-code, kun je Liquid gebruiken om je variabelen te schrijven of variabelen te bewerken die je toevoegt met behulp van de link Variabele toevoegen. Raadpleeg de taalreferentie voor Liquid-templates voor meer informatie.
Voorwaardelijke tags en iteratietags
Je kunt variabele Liquid-tags handmatig toevoegen aan je workflowberichten. Gebruik deze tags om meer informatie in je berichten op te nemen.
Je kunt bijvoorbeeld een for loop
-object gebruiken om iteratief door een lijst met objecten te gaan, zoals orderregels voor een bestelling. Met deze tags kun je berichten maken die details bevatten, zoals producttitel, SKU, prijs en hoeveelheid voor elke orderregel in een bestelling, en voorkomen dat je ontvangers deze informatie moeten opzoeken in je Shopify-beheercentrum.
Flow ondersteunt alle voorwaardelijke Shopify Liquid-tags (die de flow regelen):
https://shopify.dev/api/liquid/tags/control-flow-tags#if
- if
- unless
- else/elsif
- case/when
- and/or (meerdere voorwaarden)
Flow ondersteunt ook alle Shopify Liquid-iteratietags:
Filters
Flow ondersteunt de volgende Shopify Liquid-filters:
Filternaam | Filtertype |
---|---|
abs | Math |
append | String |
at_least | Math |
at_most | Math |
capitalize | String |
ceil | Math |
concat | Array |
date | Additional |
default | Additional |
divided_by | Math |
downcase | String |
escape | String |
eerst | Array |
floor | Math |
join | Array |
last | Array |
lstrip | String |
kaart | Array |
minus | Math |
modulo | Math |
newline_to_br | String |
plus | Math |
prepend | String |
remove | String |
remove_first | String |
replace | String |
replace_first | String | reverse | Array |
round | Math |
rstrip | String |
grootte | Array |
slice | String |
sorteren | Array |
split | String |
strip | String |
strip_html | String |
strip_newlines | String |
times | Math |
truncate | String |
truncatewords | String |
uniq | Array |
upcase | String |
url_encode | String |
waar | Array |
Variabele voorbeelden
Je wilt bijvoorbeeld een workflow maken om een e-mail naar een medewerker te sturen wanneer een klant meer dan USD 500 aan een bestelling besteedt. Je maakt een workflow met behulp van de trigger Bestelling aangemaakt, stel een voorwaarde in die waar is als het totaal van de bestelling hoger is dan USD 500 en gebruik de actie E-mail verzenden. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen.
Invoer | Uitvoer |
---|---|
Stuur een persoonlijk bedankje naar {{ order.customer.firstName }} {{ order.customer.lastName }}({{ order.customer.email }}) voor het plaatsen van een bestelling voor USD {{ order.totalPriceSet.shopMoney.amount }}. | Stuur een persoonlijk bedankje naar Jeanne Dupont (jeanne@example.com) voor het plaatsen van een bestelling voor USD 763,42. |
Je besluit dat je een medewerker moet informeren wanneer de productvoorraad laag is en een bestelling moet worden geplaatst voor meer voorraad. Je maakt een workflow die begint met de trigger Voorraadaantallen gewijzigd en je stelt een voorwaarde in die waar is als de voorraadhoeveelheid voorafgaand kleiner is dan of gelijk is aan 10. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen.
Invoer | Uitvoer |
---|---|
Bestel {{ product.title }} opnieuw. Stuur een owner@store.com om te verifiëren dat ze de inkooporder hebben ontvangen. | Bestel zwarte leggings met een hoge taille opnieuw. Stuur een owner@example.com om te verifiëren dat ze de inkooporder hebben ontvangen. |
Je wilt bestellingen met een hoog risiconiveau annuleren, maar je geeft er de voorkeur aan dat je medewerkers de bestelling handmatig annuleren. Je maakt een workflow die begint met de trigger Bestelling aangemaakt en stelt een voorwaarde in die waar is als het risiconiveau van de bestelling gelijk is aan hoog. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen.
Invoer | Uitvoer |
---|---|
Onze Shopify-winkel heeft een bestelling ontvangen met een hoog frauderisico. We willen deze bestelling meteen annuleren, voordat deze naar de productie wordt verzonden: {{ order.name }} {{ order.billingAddress.lastName }}, {{ order.billingAddress.firstName }} {{ order.email }} Bevestig de nieuwe bestelstatus. Bedankt! |
Onze Shopify-winkel heeft een bestelling ontvangen met een hoog frauderisico. We willen deze bestelling meteen annuleren, voordat deze naar de productie wordt verzonden: #1001 Dupont, Jeanne jeanne@example.com Bevestig de nieuwe bestelstatus. Bedankt! |
Voorbeelden van een 'for loop'
Wanneer een bestelling wordt ontvangen, kan het handig zijn om een bericht met de bestelde producten te verzenden. Je kunt dit doen door een for loop
gebruiken, die herhaaldelijk een codeblok uitvoeren. Tekstvelden die variabelen ondersteunen, ondersteunen ook for loops en het forloop-object.
Je wilt bijvoorbeeld een workflow maken waarin een lijst met alle SKU's en hoeveelheden in een bestelling wordt geretourneerd. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen.
Invoer | Uitvoer |
---|---|
Besteloverzicht: {% for a in order.lineItems %} SKU: {{a.sku}} ({{a.quantity}}), {% endfor %} |
Besteloverzicht: 8987097979 (50) 8877778887 (3) 888998898B (1) |
Je besluit om meer informatie aan de e-mail toe te voegen, inclusief de productnaam, SKU's, prijs per artikel en de verzendgegevens van de klant. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen.
Invoer | Uitvoer |
---|---|
Besteloverzicht: {% for a in order.lineItems %} Product: {{a.title}} SKU: {{a.sku}} Prijs (per eenheid): $ {{a.originalUnitPriceSet.shopMoney.amount}} Aantal: {{a.quantity}} {% endfor %} |
Besteloverzicht: Product: zwarte legging met hoge taille SKU: 8987097979 Prijs (per eenheid): USD 8,49 Aantal: 5 Product: blauwe sportsokken SKU: 888998898B Prijs (per eenheid): USD 5,61 Aantal: 2 |
Je moet artikelen volgen die worden verkocht door een specifieke leverancier. In de sectie Bericht van de actie E-mail verzenden, gebruik je de volgende variabelen en voeg je een if
-overzicht toe in je for loop
.
Invoer | Uitvoer |
---|---|
Acme-product verkocht: {% for x in order.lineItems %} {% if x.vendor == 'acme-vendor' %} Productnaam: {{x.title}} SKU: {{x.sku}} {% endif %} {% endfor %} |
Acme-product verkocht: Productnaam: zwarte legging met hoge taille SKU: 8987097979 |
Complexe gegevensobjecten in Shopify Flow
Shopify Flow ondersteunt het uitvoeren van matrixen en objecten niet om de volgende redenen:
- Het uitvoeren van niet-vereiste gegevens is afgeschaft voor de GraphQL-API en kan leiden tot grote queryformaten die je workflow doen mislukken.
- Wanneer er nieuwe functies worden geïntroduceerd, worden er nieuwe API-velden toegevoegd die je workflow kunnen onderbreken.
Als er te veel gegevens automatisch worden verzonden, mislukt de workflow. Herhaal matrixen en voeg alleen de door jou gewenste velden toe in plaats van matrixen en objecten rechtstreeks aan te roepen.
Gebruik bijvoorbeeld de volgende indeling om specifieke velden aan te roepen in plaats van {{ order.lineItems }}
aan te roepen. Deze voorbeelden omvatten alle velden die zouden worden opgenomen door de matrix of het object rechtstreeks aan te roepen. Kopieer en plak de velden die je nodig hebt.
{% 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 %}
]
}