How can I determine the name of the variant option in the Shopify order export?

The Shopify API only provides the values of the variant options in the fields option1, option2, and option3 where the ordering of the options could vary per product (e.g. option1 might be the Color option for one but the Size for another).

In EZ Exporter, we can figure out the name of the option by searching the list of all available options for what the position should be for each one using the Calculated Fields feature.

For example, you may be using the following options:

  • Color
  • Size
  • Material

The Shopify API's options field will store the data like this:

[
   {
      "name":"Size",
      "position":1,
      "values":[
         "Small",
         "Medium"
      ]
   },
   {
      "name":"Color",
      "position":2,
      "values":[
         "Red",
         "Blue"
      ]
   },
   {
      "name":"Material",
      "position":3,
      "values":[
         "Leather",
         "Cotton"
      ]
   }
]

The key to figuring out which option is which is by matching up the position value. For example, a variant's option1 maps to position 1 in the product options.

To do this, we can use a Calculated Field formula like this:

{{ line_items.variant.option1 }} if search_attributes({{ line_items.product.options }}, "Color", result_key="position") == 1 else {{ line_items.variant.option2 }} if search_attributes({{ line_items.product.options }}, "Color", result_key="position") == 2 else {{ line_items.variant.option3 }} if search_attributes({{ line_items.product.options }}, "Color", result_key="position") == 3 else ""

The above will pull the value of the Color option.

We can then repeat the formula for the other options and just replacing the option name "Color" with the other option names.

Retrieve the Size option:

{{ line_items.variant.option1 }} if search_attributes({{ line_items.product.options }}, "Size", result_key="position") == 1 else {{ line_items.variant.option2 }} if search_attributes({{ line_items.product.options }}, "Size", result_key="position") == 2 else {{ line_items.variant.option3 }} if search_attributes({{ line_items.product.options }}, "Size", result_key="position") == 3 else ""

Retrieve the Material option:

{{ line_items.variant.option1 }} if search_attributes({{ line_items.product.options }}, "Material", result_key="position") == 1 else {{ line_items.variant.option2 }} if search_attributes({{ line_items.product.options }}, "Material", result_key="position") == 2 else {{ line_items.variant.option3 }} if search_attributes({{ line_items.product.options }}, "Material", result_key="position") == 3 else ""

Export Shopify variant options by name with EZ Exporter

The output will look something like this:

EZ Exporter - Export Line Item Variant Options


Related Articles:


App: EZ Exporter

Tags: advanced features, calculated fields, variants