Flow Builder - Example flows

In this article, we will explain various uses of the Flow Builder using some sample flows.


Tag new customers

In this example, new customers are to receive a tag indicating which country they come from.
For this purpose, the trigger Checkout / Customer / Register is selected because it is triggered as soon as a customer registers. Then it is gradually checked whether the customer comes from the USA, Austria or Switzerland, and, if necessary, a corresponding tag is added to the customer. 
No tag is assigned if the customer does not come from one of these countries.

Item orderable only once per customer

In this example, a selected article is to be orderable only once for the customer. 
For this, a rule must first be created in the Rule Builder that detects whether the item in question is in the shopping cart when the order is placed. This would look like the following:
Item in cart > is one of > desired item.
Next, in the Flow Builder, you add a condition to the existing "Order placed" flow, selecting the rule you created above. In case the condition is met, you store the action "Assign tag" and assign a tag with any name to the customer.
Now every customer who buys this item will be assigned the tag. With the extension Dynamic Access you can hide the article for customers with this with further rules from the Rule Builder. Without extension it would be possible to disable the shipping method when customers with this tag add the item to the cart again.


Send documents automatically

In this example, the invoice is to be sent automatically with the confirmation mail. To do this, you use the trigger Checkout / Order / Placed. This trigger is activated as soon as an order is placed in your shop.
First, you must create the document that is to be sent automatically. In this example, you first select generate document as the action and then select invoice as the document type. 
This document will be attached to the automatic notification in the next step. Below the action generate document, add another action send email and select default as the recipient so that the customer receives the email. For the email template, select order confirmation to send an order confirmation and select the desired document to be attached to the email. 


Notify the warehouse of a paid order

In this example, you send a mail to the warehouse as soon as an order has been paid for so the warehouse can dispatch the goods. The first step is to select State enter / Order transaction / State / Paid as the trigger state. This trigger is triggered as soon as the payment status changes to paid
Next, you decide whether the warehouse should also receive the customer's invoice and/or delivery note. In this case, you first select create document as the action and select the corresponding document. In our example, you send an invoice and therefore select invoice. As a subsequent action, you select Send email so that an email will be sent to the warehouse.

In the Send email action configuration, select custom recipient as the recipient. This allows you to specify an individual email address to which the email will be sent. Then enter the email address of the warehouse or the responsible employee. You can select any template as the email template or create one yourself for this standard email. In our example, we send the default template for Enter payment state: Paid. Finally, you select which document is to be sent. In our example, the invoice is sent along. However, you can also select several documents (e.g. invoice and delivery note) to be sent along.

Please note that it is essential that the documents that are to be sent along were automatically generated in the previous step.

Notification to an external platform (Slack)

In this example, we will show you how to send notifications to an external platform such as Slack using Flowbuilder. For this example, you need the extension Flow Builder Professional for Shopware 6, which includes the action Webhook.

To do this, first, create a new workflow in Slack. You can find all information about the workflows in Slack and how to find the Workflow Builder here
In the Workflow Builder, you first create a new workflow. Every workflow needs a trigger and at least one action, which is called a step in Slack. You select webhook as the trigger, as we will use this in the Shopware Flow Builder.

URL of the web request (1): The target address needed for the webhook in Shopware Flowbuilder is displayed here. You should always save this address. This address is not yet displayed when you call up the trigger for the first time. It will only be displayed once you have completed and published the workflow.

Variables (2): It doesn't matter how you name the variables. In this example, however, we use the following:

  • orderURL: Here, we will insert the URL to the order.
  • orderPositions: Here, we will insert a listing of all positions from the order.
  • orderNumber: Here, we will insert the order number of the order.
  • orderCustomerAdress: Here, we will insert the customer address.

HTTP sample text (3): We will need this sample text later in Shopware Flowbuilder to transfer the variables with the webhook. You should therefore also save this text.

Next, you add a step to the workflow that should be executed as soon as the trigger takes effect. In our example, we choose the send message step to send a user or Slack group a message with the new order.

Send this message to (1): Select the users or the Slack group to which the message should be sent.

Message text (2): Here you can design the message text. Click on Insert a variable at the bottom right to add your previously created variants. In our example, we insert a heading and have the content of the variables displayed, which we will later fill with the order content in Shopware Flowbuilder.

In Shopware Flow Builder
In the Shopware Flow Builder, you can either edit the existing flow for incoming orders or create a new one and select Checkout / Order / Placed as the trigger. If, for example, you only want to create the Slack message for orders that have already been paid for, you can also select State Enter / Order Transaction / State / Paid as the trigger.  
If you do not want to specify any further conditions for creating a Slack message, select Call URL (Webhook) as the action.

Method (1): Choose the POST method here, as we want to transmit information to Slack.
URL (2): Enter the target URL here. This was created in the Slack configuration under the item URL of the web request.
Parameters (3): Since Slack expects the parameters in the body, you can still leave the parameters empty here.

In the Body tab, select the BodyType: Raw and copy the HTTP example from Slack into the code.

 "orderURL": "Sample text",
 "orderPositions": "Sample text", 
 "orderNumber": "Sample text", 
 "orderCustomerAdress": "Sample text" 

You now replace the content of the variables with Shopware variables that you also know from the email templates. For our example, the code would look like this:

 "orderURL": "http://doku1.test.shopware.in/admin#/sw/order/detail/{{ order.id }}",  
 "orderPositions": "  
 {% for lineItem in order.LineItems %}   
 {{ lineItem.payload.productNumber }} - {{ lineItem.label }}         
 {% endfor %}",    
 "orderNumber": "{{ order.orderNumber }}",    
 "orderCustomerAdress": "{% set billingAddress = order.addresses.get(order.billingAddressId) %} 
 {{ billingAddress.company }}  
 {{ billingAddress.firstName }} {{ billingAddress.lastName }}  
 {{ billingAddress.street }}  
 {{ billingAddress.zipcode }} {{ billingAddress.city }}  
 {{ billingAddress.country.translated.name }}" 
After saving this configuration, the workflow should be correctly integrated. As soon as an order is received in your shop, a corresponding message is automatically generated in Slack.

Was this article helpful?