How Can We Help?
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
Product | Product Tags * |
White Trainers | Leather, Mens, Sports, Clearance |
Black Shoes | Womens, 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.
- Process Data – we return stored data from a field – either in its original form, or transformed in some way
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
Product | Array Data Field * |
Widget A | Red, Blue, Green |
Widget B | Blue, Red, Green |
Widget C | Blue, 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:
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
This is where the Join Array function comes to the rescue. The logical test becomes:
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
for the array un-joined this would look like:
If you pre-join the array before the LEFT extract transform rule this becomes
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 Title | product id | variant id | variant name * | variant value * |
Hellfire Club T-Shirt | 101 | 991 | Color, Size | Black & White, S |
Hellfire Club T-Shirt | 101 | 992 | Color, Size | Black & White, M |
Hellfire Club T-Shirt | 101 | 993 | Color, Size | Black & White, L |
Hellfire Club T-Shirt | 101 | 994 | Color, Size | Charcoal, S |
Hellfire Club T-Shirt | 101 | 995 | Color, Size | Charcoal, M |
Hellfire Club T-Shirt | 101 | 996 | Color, Size | Charcoal, 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 Title | product id | variant id | variant name * | variant value * |
Hawkins AV Club T-Shirt | 99 | 811 | Size, Color | S, White |
Hawkins AV Club T-Shirt | 99 | 812 | Size, Color | M, White |
Hawkins AV Club T-Shirt | 99 | 813 | Size, Color | L, White |
Hawkins AV Club T-Shirt | 99 | 814 | Size, Color | S, Grey |
Hawkins AV Club T-Shirt | 99 | 815 | Size, Color | M, Grey |
Hawkins AV Club T-Shirt | 99 | 816 | Size, Color | L, 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 Title | variant value * | ${var_opt_value_1} | ${var_opt_value_2} |
Hellfire Club T-Shirt | Black & White, S | Black & White | S |
Hellfire Club T-Shirt | Black & White, M | Black & White | M |
Hellfire Club T-Shirt | Black & White, L | Black & White | L |
Hellfire Club T-Shirt | Charcoal, S | Charcoal | S |
Hellfire Club T-Shirt | Charcoal, M | Charcoal | M |
Hellfire Club T-Shirt | Charcoal, L | Charcoal | L |
Product Title | variant value * | ${var_opt_value_1} | ${var_opt_value_2} |
Hawkins AV Club T-Shirt | S, White | S | White |
Hawkins AV Club T-Shirt | M, White | M | White |
Hawkins AV Club T-Shirt | L, White | L | White |
Hawkins AV Club T-Shirt | S, Grey | S | Grey |
Hawkins AV Club T-Shirt | M, Grey | M | Grey |
Hawkins AV Club T-Shirt | L, Grey | L | Grey |
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.