How to set up a trigger chain
Copy the link to the article
Copied

Informing customers about the status of their orders and parcels is critical for the success of your store. In this article we explain how to set up automatic notifications for customers; from sending a tracking number to controlling the pick-up of parcels from a pickup point, all via a trigger chain.

1. Sending a tracking number to a customer during the process of delivery registration.

Registration of delivery means sending a request to an integrated delivery service that is connected to the system and assigning a track number in the corresponding field of the order.

Let's create a trigger code that will send the communication you need to the customer:

First, we specify on which order change the trigger will be executed, namely, a change in the track number in the order, with an additional check that the new value of the track number is not empty, this is required to prevent cases of sending communications to a customer without a track number, for example, when canceling a request for delivery, the track number will be deleted from the order.

changeSet.hasChangedField("integration_delivery_data.track_number") and changeSet.newValue("integration_delivery_data.track_number") != null

This code is identical for all delivery services.

Note

If you are using a delivery service aggregator, the tracking number field may contain information about the internal number of the request in the aggregator, which may differ from the number of the shipment directly in the delivery service via which the aggregator sends.

If you want to differentiate between the sending of different communications for different types of delivery when changing the tracking number in the order, then the following condition must be added to the existing code:

order.deliveryType.code == "royal-mail"

Where instead of royal-mail - you must specify the symbolic code of the delivery type (courier service) for which the trigger should be executed.

In addition to the resulting code, you can add a condition that will prevent the trigger from re-launching. If one has already been launched, see "How to avoid the repetead execution of a trigger":

not last_run("1 days")

Ready code for this situation:

changeSet.hasChangedField("integration_delivery_data.track_number") and changeSet.newValue("integration_delivery_data.track_number") != null and order.deliveryType.code == "russian-post" and not last_run("1 days")

2 . Sending information about the transfer of the order to the courier

If orders are delivered by your own couriers, then you can set up an auto-notification system so that your customers know when their order has been transferred to the courier.

Let's make a trigger that will send the necessary information to the customer after the courier has been assigned in the order (via the corresponding courier delivery field).

changeSet.hasChangedField("integration_delivery_data.courier") and changeSet.newValue("integration_delivery_data.courier") != null

In addition to this code, it is necessary to add a check for the type of delivery set in the order, since the field integration_delivery_data.courier checked in the above-mentioned code is only available for the type of delivery that is integrated with "Courier delivery":

order.deliveryType.code == "courier"

Where instead of courier - you must specify the symbolic code of the delivery type (chosen courier service), which is integrated with the module of the courier service.

3 . Informing customers about the arrival of a parcel at the pickup point

An important part of the automation and control of pick-ups of orders from a pickup point is informing customers that their parcel is at the pick-up point.

As a rule, delivery services notify online stores about the arrival of a parcel at a pickup point using the delivery status. In order to implement the solution we need, you must first configure the correspondence of delivery statuses in the integration module of the delivery service for which you set up a trigger. You can read more about this process in the article "Delivery services".

To implement the solution, you need to create a trigger chain from the parent trigger, which will react to a change in the order status, which corresponds to the required delivery status. After the parent trigger is executed, a postponed trigger will be launched, which will send communication to the customer after the required time, if the delivery service has not changed the status of the order at the time the trigger is executed.

The parent trigger will contain the following code:

changeSet.hasChangedField("status") and changeSet.newValue("status").code == "delivered"

Checking for the required type of delivery with the following code:

order.deliveryType.code == "sdek"

In the trigger's action, we will select the communication template we need, containing information that the order has been delivered to the pick-up point.

This action will not change anything in the order; it is required to record the fact that the parent trigger which has no "real" action is executed.

The next step is to create a postponed trigger that will inform customers about the arrival of the parcel at the pickup point.

The trigger will be with the event "After the trigger for the order", in the "After trigger" field. Select the previously created parent trigger, and in the "After" field, specify the number of days after which the trigger will be executed and will send the communication to the customer, for example:

2 days

In the code of the postponed trigger, add a check that the status of the order on which the parent trigger is executed, has not changed yet, that is, within 2 days - the order was not picked up by the customer.

order.status.code == "delivered"

In the trigger action, we select the desired communication, with a reminder that the order has already arrived at the pick-up point.

If you need to send a reminder again, after some time, you can create another delayed trigger. Remember that, in the "After trigger" field, you must select the previously created postponed trigger.

4: Setting delivery costs

If the system records data about delivery costs, for example, payment for delivery, then setting the cost for each order manually can slow down the manager's work, and can lead to data input mistakes, such as incorrect deivery costs.

Let's create a trigger that will add the cost of the delivery as a separate cost for the order as soon as it is executed.

In the trigger code, we specify:

changeSet.hasChangedField("status") and changeSet.newValue("status").code == "complete"

In the trigger action, select "Add cost"

From the drop-down list, select a desired cost-item. In the "Amount" field, enter the following code:

order.deliveryNetCost

Fix the current date in the "Date" field using the code:

date("now")
Thank you for your feedback.
Was this article helpful?
No
  • Рекомендации не помогли
  • Нет ответа на мой вопрос
  • Текст трудно понять
  • Не нравится описанный функционал
Yes
Previous article
How to avoid the repeated execution of a trigger
This article describes the possible reasons for the repeated execution of a trigger for the same condition.
Next article
Working with products in triggers, validations and price types
Order details are an array of data, therefore, working with them is conducted using special filters created in PipeLanguage. In this article, we will analyse how to work with filters in price types, triggers and validation and in the context of products.
#}