Search code examples
rubyshopifyshopify-api

Shopify Help Returning Line Item Properties


I am having an issue retrieving the line tem properties of an order. The problem is that the code I am using is not displaying anything. I am able to get the order line items, but the properties of the line item (like if I have a form field name properties[SomeText] or properties[Color])

Here is a simplified version of what I am using:

{% for item in order.line_items %}
Sku: {{item.item.sku}}
Product Title: {{item.title}}
    {% for prop in item.properties %}
    Properties: {{ prop.first }} = {{ prop.last }}
    {% endfor %}
{% endfor %}

In the example above, the values for Sku and Product Title are working, but I am not getting any values returned for the Properties. I know they exist because they show when I go an view an order.

So, I'm not sure what I've done incorrectly. Any help will be greatly appreciated.


Solution

  • After looking at the Order's raw XML, I noticed that instead of using prop.first and prop.last, I changed it to prop.name and prop.value and it works.

    {% for item in order.line_items %}
    Sku: {{item.item.sku}}
    Product Title: {{item.title}}
        {% for prop in item.properties %}
        Properties: {{ prop.name }} = {{ prop.value }}
        {% endfor %}
    {% endfor %}