Skip to main content

Hi, Klaviyo community! First-time poster, long-time fan of the platform. Running into a problem with some flow functionality that I’m hoping is just a case of me not thinking about the problem in the correct way. I’d appreciate any advice you might have to share!

Briefly, some background: This project is for an ecommerce company, and the flow is meant to be triggered for a customer when an order (containing a particular item that we pre-specify) enters the fulfillment stage.

We have a JSON data feed containing a list of items running a particular post-purchase promotion. We’ve previously tried setting up individual flows for each product, but this isn’t tenable due to how often the particulars of the promotion change from product to product. Ideally, we want to arrive at a single flow that matches the right messaging to the right product for our customers.

To achieve this, I’ve experimented with building a nested loop that runs through the items in a customer’s order - for each iteration, it also loops through the data feed. If a match is found between the order item’s SKU and a SKU within the data feed, I’d like to break the loop and make use of the data feed’s data for things like the name of the product, the promotion’s name, etc.

I’ve had no trouble creating the two loops in isolate, but as I attempt to combine them to make everything work, I’m afraid I’m running into some issues stemming from my lack of familiarity with the nuances of Django. I’ll provide the code I’m attempting to use to test below.

After doing some reading, there appears to be two issues that I suspect are the main culprits of the syntax errors I’m getting:

  • It doesn’t seem to be the case that Django can assign a value to a discrete variable
  • There doesn’t appear to be a “break” command to exit a loop (or at least, not one that I’ve come across or a methodology behind it that I’m familiar with)

Here’s the code I’ve been trying variations of - if you have any thoughts as to what I might be able to try to achieve this, I’d greatly appreciate your guidance! Apologies if any of this is obvious; I’ve searched around for answers but haven’t found anything concrete yet to try.

 

{% for orderItem in event.Items %}

    {% assign matchFound = false %}

    {% assign matchingData = nil %}

    {% for feedItem in feeds.ReviewRebateFeed %}

        {% if orderItem.SKU == feedItem.Item %}

            {% assign matchFound = true %}

            {% assign matchingData = feedItem %}

            {% break %}

        {% endif %}

    {% endfor %}

    {% if matchFound %}

        <strong>MATCH FOUND!</strong><br>

        Product Ordered: {{ matchingData.itemName }}<br>

        Product SKU: {{ matchingData.item }}<br>

        {% break %}

    {% endif %}

{% endfor %}

Hi there @jameslabove

 

Thanks for sharing your question with us! Happy to help! 

 

So you will need to contact your developer or a Klaviyo partner to work out how to custom code this for it to act as you want, but I am going to bring this to the tempalte team to see if they can give more insight into what is and isn’t possible when we get this granular! 

 

Thank you for participating in the Community!

-Taylor 


Hi @Taylor Tarpley, and thank you for the reply! Totally understand about this not necessarily being a venue for being provided code examples - if the team had any general thoughts about a different approach I could take (or even confirmation that what I’m attempting isn’t tenable), that would be a huge help in and of itself. I’m exploring alternate approaches in the meantime. Thanks again!


Reply