Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Shopify Flow - tagging orders that meet mail cut-off time

Solved

Shopify Flow - tagging orders that meet mail cut-off time

drewzh
Excursionist
12 1 5

Hi,

 

We have a requirement to tag orders that meet the mail-cut-off time. This was easily achieved in the previous app that we used (Order Tagger). With Flow, it seems the process is a little restricted when it comes to dynamic values. I.e, when comparing dates, there's no way to compare against a set time etc.

 

The way we thought we could do it was doing something like this...

 

When order created ---> Assign new tag with the value of:

 

 

{% assign order_time = order.createdAt | date: "%s" %}
{% assign cutoff_time = order.createdAt | date: "%Y-%m-%d 10:00" | date: "%s" %}
{% assign weekday = order.createdAt | date: "%u" %}
{% if order_time > cutoff_time and weekday < 6 %}after-cutoff{% else %}same-day-dispatch{% endif %}

 

 

 

This logic checks out in my liquid sandbox, but with Flow, the value always resolves to 'same-day-dispatch' when an order is placed before 3 pm and when it's placed after, it seems to error instead. I'm a little confused.

 

Thanks,

Drew

Accepted Solution (1)

drewzh
Excursionist
12 1 5

This is an accepted solution.

Where there's a will, there's a way! At least I believe I've found a solution that doesn't use logical statements but instead uses a clever sequence of math and string filters.

 

Basically we just convert the order date/time to a integer and then subtract the cut-off time from that value using the same unit of measurement (i.e, subtract the hour+1 from the hour, or if you need minute precision, times the hours by 60 and add the additional minutes+1 and subtract against the same). We can then use the zero point as the logical switch. If it's a minus, then we know there's still time left and if it's a plus, we know the cut-off time is larger and we've gone less than 0. Once we have that understanding, we can normalise to 0 or 1 and then swap those out for actual string values with a replace filter to use in our tags directly.

 

Hope this helps someone. Actually, if someone has any other clever ways to shorten this, I would be very interested.

 

 

 

{{ order.createdAt | date: "%H" | minus: 14 | at_most: 1 | at_least: 0 | replace: '0', 'same-day-dispatch' | replace: '1', 'after-cutoff-order' }}

 

 

View solution in original post

Replies 4 (4)

paul_n
Shopify Staff
1429 156 330

Flow does not support all Liquid but a subset. It does not support assign and capture yet. I don't think you can yet do this in Flow.

 

 

Paul_N | Flow Product Manager @ Shopify
- Finding Flow useful? Leave us a review
- Need Flow help? Check out our help docs.
- Building for Flow? Check out Flow's dev docs.
drewzh
Excursionist
12 1 5

Thanks for your response. Ah, that's a shame. Also a shame that it isn't made clear in the documentation and I spent an entire evening trying to make it work. With that said, is there any other option that I could try? More outside of the box kind of ideas as time or date comparisons don't seem to be supported (at least in a way that is useful).

drewzh
Excursionist
12 1 5

This is an accepted solution.

Where there's a will, there's a way! At least I believe I've found a solution that doesn't use logical statements but instead uses a clever sequence of math and string filters.

 

Basically we just convert the order date/time to a integer and then subtract the cut-off time from that value using the same unit of measurement (i.e, subtract the hour+1 from the hour, or if you need minute precision, times the hours by 60 and add the additional minutes+1 and subtract against the same). We can then use the zero point as the logical switch. If it's a minus, then we know there's still time left and if it's a plus, we know the cut-off time is larger and we've gone less than 0. Once we have that understanding, we can normalise to 0 or 1 and then swap those out for actual string values with a replace filter to use in our tags directly.

 

Hope this helps someone. Actually, if someone has any other clever ways to shorten this, I would be very interested.

 

 

 

{{ order.createdAt | date: "%H" | minus: 14 | at_most: 1 | at_least: 0 | replace: '0', 'same-day-dispatch' | replace: '1', 'after-cutoff-order' }}

 

 

drewzh
Excursionist
12 1 5

How I'm using this particular logicHow I'm using this particular logic