How Can We Help?

< All Topics

Using the Join Array Function | How to Guide

The join array selection radio button appears any time that you select a data source where the values are stored as an array.

This function has a number of powerful applications a few that we will explore in this article.

The easiest way to understand this option however is to look at a real-world example, but before we do this lets establish some basics of the function.

The Basics

So there are a few elements in your Shopify product database where the data is stored as an array. These include fields such as:

  • Tags
  • Product Images
  • Variant Option Names
  • Variant Option Values

Lets take a simple example and look at Product Tags

ProductProduct Tags *
White TrainersLeather, Mens, Sports, Clearance
Black ShoesWomens, Business Wear, Best Sellers, Leather

So lets now have a look how the Join Array functions behaves in respect of the main methods of populating data. With Feed Donkey builder there are two distinct routes populating a column.

  • Map Data – so we create a rule that tests data against a condition – and returns a static value or a variable on the basis of this. E.g.
Here we check the inventory number – and return an ‘in stock’ or ‘out of stock’ text value depending on this
  • Process Data – we return stored data from a field – either in its original form, or transformed in some way
Here we return the product title text but if its stored as ‘black shoes’, we transform to ‘Black Shoes’ (Proper Case)

So with this in mind there are two main methods of how we ‘handle’ data fields

  • to test against as a condition
  • to output in an original or transformed state

The Array Joiner function increases our ability to achieve what we require in both these cases – but especially in the case of conditional tests.

So before we get into the why’s and how’s – what is the change in behaviour that the Array Joiner results in?

A Simple Illustration

So we have some very simple product data here

ProductArray Data Field *
Widget ARed, Blue, Green
Widget BBlue, Red, Green
Widget CBlue, Green, Red

We want to test this data against a rule

Array Data Field MATCHES “Red”

We can see that every product in this data set meets this condition. When a match condition is tested against an array set stored against a SKU – in an ‘un-joined’ state each part of the array is tested individually & if a match occurs on one or more – the SKU is regarded as a positive match.

This test against Widget A looks something like:

“Red” = “Red” ✔️
“Blue” = “Red” ❌
“Green” = “Red” ❌
Overall result for Widget A – Array Data Field MATCHES “Red” ✔️

But what if we wanted to find a product where the data in the array is in a particular order, like CONTAINS “Red, Blue” ??

So we may expect a single product match, but if we repeat this test for the un-joined array data we get

“Red” ?= “Red, Blue” ❌
“Blue” ?= “Red, Blue” ❌
“Green” ?= “Red, Blue” ❌
Overall result for Widget A – Array Data Field CONTAINS “Red, Blue” ❌

This is where the Join Array function comes to the rescue. The logical test becomes:

“Red, Blue, Green” CONTAINS “Red, Blue” ✔️ Widget A passes the test ✔️

“Blue, Red, Green” CONTAINS “Red, Blue” ❌ Widget B fails the test ❌

“Blue, Green, Red” CONTAINS “Red, Blue” ❌ Widget C fails the test ❌

The three parts of the array data are joined into a string, before the conditional test is applied

The above example is a conditional test, but equally this gives you more control over ‘transformation’ processes when it comes to getting the right output, with array type data as the source.

Simple example again

Array Data Field LEFT, number of characters 2

this extracts the 2 characters leftmost in the string

for the array un-joined this would look like:

LEFT “Red” .. “Re”

LEFT “Blue” .. “Bl”

LEFT “Green” “Gr”

Output against the SKU (Widget A) has to then be joined as comma separated string (there is only one ‘cell’ to output into) .. “Re, Bl, Gr”

If you pre-join the array before the LEFT extract transform rule this becomes

LEFT “Red, Blue, Green” .. “Re” (Widget A)

LEFT “Blue, Red, Green” .. “Bl” (Widget B)

LEFT “Blue, Green, Red” .. “Bl” (Widget C)

So these are very theoretical illustrations of how the test/ transform rules are changed in behaviour by the Join Array option – lets move onto an actual use case.

A very common use case is the accurate extraction variant option values. This can be quite a tricky exercise when there is a lot of variability in how products have been set up. With the Join Array function however, this is fully in your control.

So variant options are a key attribute for the setup of products in the majority ecommerce stores of course. With Shopify you can define up to 3 dimensions in your variants.

For example take the classic T-Shirt product

You have the parent ‘products level’ item

Hellfire Club T-Shirt

This may then be structured to have Color and Size variations (this being two dimensions)

If you have three sizes (Small, Medium, Large) and two colours (Black & White, Charcoal). This would then give you 6 variants nested under the one parent id.

Product Titleproduct idvariant idvariant name *variant value *
Hellfire Club T-Shirt101991Color, SizeBlack & White, S
Hellfire Club T-Shirt101992Color, SizeBlack & White, M
Hellfire Club T-Shirt101993Color, SizeBlack & White, L
Hellfire Club T-Shirt101994Color, SizeCharcoal, S
Hellfire Club T-Shirt101995Color, SizeCharcoal, M
Hellfire Club T-Shirt101996Color, SizeCharcoal, L

Stores can have have a number of variant configurations in the same product database though e.g. in the same store there could be another t-shirt like this

Product Titleproduct idvariant idvariant name *variant value *
Hawkins AV Club T-Shirt99811Size, ColorS, White
Hawkins AV Club T-Shirt99812Size, ColorM, White
Hawkins AV Club T-Shirt99813Size, ColorL, White
Hawkins AV Club T-Shirt99814Size, ColorS, Grey
Hawkins AV Club T-Shirt99815Size, ColorM, Grey
Hawkins AV Club T-Shirt99816Size, ColorL, Grey

This variability created issues with mapping where to extract the colour and size value from. The reason being the fact that these values are stored as an array and how logically you can test against these values.

So looking at the above as a real world scenario – you wish to create color field in you feed and therefore you need to extract just the color value part out of the ‘variant value’ data – how do you do this?

The method we use is to ‘split’ the variant option values – as separate variables. For example (here using a regular expression extract transformation):

With the example data this has the effect of:

Product Titlevariant value *${var_opt_value_1}${var_opt_value_2}
Hellfire Club T-ShirtBlack & White, SBlack & WhiteS
Hellfire Club T-ShirtBlack & White, MBlack & WhiteM
Hellfire Club T-ShirtBlack & White, LBlack & WhiteL
Hellfire Club T-ShirtCharcoal, SCharcoalS
Hellfire Club T-ShirtCharcoal, MCharcoalM
Hellfire Club T-ShirtCharcoal, LCharcoalL

Product Titlevariant value *${var_opt_value_1}${var_opt_value_2}
Hawkins AV Club T-ShirtS, WhiteSWhite
Hawkins AV Club T-ShirtM, WhiteMWhite
Hawkins AV Club T-ShirtL, WhiteLWhite
Hawkins AV Club T-ShirtS, GreySGrey
Hawkins AV Club T-ShirtM, GreyMGrey
Hawkins AV Club T-ShirtL, GreyLGrey

So back to the task in hand, in our feed we need to create a ‘color’ and ‘size’ column and populate it with the right data.

So if every product in our store with color and size variations is set up the same, like ‘Hellfire Club T-Shirt’, the extraction and display is very simple .. for ‘colour’ we use ${var_opt_value_1} variable and for ‘size’ we use ${var_opt_value_2}.

This one dimensional way – can work where the variant data structure is very consistent. But more normally we find differences… like in the example data.

So you can see if we applied the one dimensional technique to these two products – although Hellfire Club T-Shirt would be correct, Hawkins AV Club T-Shirt would be showing size data in the ‘color’ column and color data in the ‘size’.

We need to vary how we display this variables – according to the ‘order’ in which the variants are constructed. We determine this using the Variant Name field .. for Hellfire Club T-Shirt this is ‘Color, Size’ and for Hawkins AV Club T-Shirt – ‘Size, Color’.

A ‘Map’ rule can then be created to sort out where to display the right variables:

Crucially though, you can see that the Join Array is applied to the Variant Name data – before we test. Otherwise they would be tested as an array (each part of the array individually) and the above rule would not work correctly.

All Feed Donkey pre-built templates come with this mechanism pre-configured, but using a Regex match to make it even more flexible e.g.

The above is checking whether in the ‘1st position’ there is a variant name that ‘contains’ either Color, color, Colour or colour .. but not not only this it will match where the variant name is something like Gem Color (or gem color, Gem Colour, gem colour) and the ‘[Cc]olou?r’ can be anywhere in the string, so something like Colour of Item would create match also.

.. so we cope with a lot of data inconsistency and variability out of the box.

The team here at Feed Donkey are here to help further with any very bespoke requirements also – just reach out to us with what you need to acheive – there is more than likely a way around your problem.