1
votes

I'm new to coding, but I decided to try and dig in to liquid because my company is looking to increase our automation, and an automation App we use in Shopify (Shopify Flow) accepts liquid commands to print messages (in this case to the spreadsheet row.) I know it's a template language, not a programming language, but I figured I would start small. Basically Flow can be set to create a new row on a google spreadsheet if a trigger action takes place. The problem is, the premade templates for printing the message of the email are only shown for the related trigger action, meaning if I set the trigger to "Order Paid" I only see printable variables under the "order" object.

I want to get the SKU and line item qty, so I think I need to run a for loop to get the {{product.variant_sku}}

for all of the items in the cart / order. Here's what I'm putting into the API: {% for product in cart.items %} {{ product.variant_sku }} {% endfor %}

Whenever I try to save this code to the workflow, I get an error stating "Your workflow can't be saved. Fix any errors and try again."

Am I missing a reference of some sort? I would think the API knows which page I'm referencing based on the trigger action. When I ran that code through the Liquid Sandbox from Jumpseller it did not return any errors. Am I just not providing it enough data? Or might my request be getting blocked for some reason? Any help is appreciated. Thanks.

****Edit: I've been messing around trying different troubleshooting methods, and stumbled onto something I probably should have mentioned: I'm using this in a test-account environment, so there is no live webpage that this app can refer to. I'm thinking this may actually be my issue, since even if I only work out of the drop-down menus, I cannot save the "Flow" if there is anything in the message related to Order (even the ID).

1
product.variant_sku is not a valid variableHymnZzy

1 Answers

1
votes

Shopify cart and order has line_item that is structured differently than products. This is what you need.

{% for item in cart.line_items %}
  {{ item.sku }}
{% endfor %}

More details - https://shopify.dev/docs/themes/liquid/reference/objects/line_item#line_item-sku

Edit: The above doesn't work for Shopify Flow. Check below part

Shopify Flow reference for order and product variables are different compared to theme variables. Below should work

{% for item in order.lineItems %}
  {{ item.sku }}
{% endfor %}

More details - https://help.shopify.com/en/manual/shopify-plus/flow/create-workflow/variables