I want to remove data from the “media” node when the image already exists in “shopify.images.nodes”. The idea is to match on the filename (for example 40785087-1.jpg). As you can see the Shopify url contains a version get parameter. So we should ignore that.
Does anyone have an idea how to fix this in Alumio? Thanks in advance!
For your information, since the “String: PCRE replace” mapper requires us to fill in the replacement text, you can put any character that is rarely used and replace it using “String: Replace” with an empty string to remove the character.
Loop into the media array by using “Node, transform nodes”. If you can’t find the entity transformer, it means that you are inside a “Data, transform nodes using mappers and conditions”. Then, you can use Execute entity transformers first, and then select “Node, transform nodes”, as shown below.
Within each object, create a new variable that holds the filename within the URL (originalSource) using the String: File basename mapper (point 1 in the picture below).
Since each object has the list of media file names that exist in Shopify (as a result of Step 3), you can now check whether the current media file name (file) exists in the existing list (existingMedia) using JMESPath function contains (point 2 in the picture below).
It will result in a boolean; true means the media exists in the Shopify product and needs to be removed from the media array, while false means it shouldn’t be removed.
All objects in the media now have a property exists: true/false. Leave the loop and use a Value Setter and JMESPath query to filter out the ones with exists: true.