How do I calculate the total price of all line item gift cards purchased in the Shopify order?

The Shopify order data contains a line item attribute called gift_card which identifies whether a line item is a gift card or not.

With EZ Exporter, you can calculate the total value of all purchased gift cards in the order using the formula below in the Calculated Fields section of the Data Settings:

get_total([float(a) * float(b) for a, b in [i.split(",") for i in load_json_data(join_lists(to_list(search_attributes({{ line_items }}, True, search_key="gift_card", result_key="price", default=0, return_all_results=True, results_separator=",")), to_list(search_attributes({{ line_items }}, True, search_key="gift_card", result_key="quantity", default=0, return_all_results=True, results_separator=",")), return_raw_results=True, value_separator=","))]])

This is very complex but this is basically what it does:

  1. Filter the raw line items API data and pull out only line items where the gift_card attribute is "True".
  2. Create 2 lists/arrays: one for the unit prices and another for the quantities.
  3. Multiply the 2 arrays together based on position (i.e. unit price x quantity per line item, this is important as it's possible an order contains multiple gift cards with different amounts).
  4. Add them all up.

Related Articles:


App: EZ Exporter

Tags: advanced features, shopify orders, gift card