You are here:  » Concatenate two xml nodes with a filter


Concatenate two xml nodes with a filter

Submitted by fabio on Fri, 2017-03-03 16:45 in

Hi David,

I have a couple of merchant that use more than 1 xml node to describe their product category.

I think I need a new filter that concatenate those before Category Hiearchy Mapping is applied, is that possible, and if so can you help me ?

Thanks !

Submitted by support on Sat, 2017-03-04 10:55

Hello Fabio,

If every record in the feed has all fields present, even if they are not all populated, you should be able to do this with a Text After filter, which supports %fieldname% placeholders to be swapped out with the values of other fields. For example, if your feed has these fields:

CATEGORY
SUBCATEGORY1
SUBCATEGORY2
SUBCATEGORY3

...then register the CATEGORY field as Category, and then add a Text After filter to the Category field containing:

" %SUBCATEGORY1% %SUBCATEGORY2% %SUBCATEGORY3%"

(without the quotes, but notice the leading SPACE otherwise there would be no space between CATEGORY and SUBCATEGORY1)

However, if it is the case that not all SUBCATEGORYx fields are present, then a small modification can be made to includes/filter.php to remove any un-replaced placeholders, and also clean up any double (or more) spaces that have occurred as a result of the replacements. To do this, look for the following code at line 13:

    return $text;

...and REPLACE with:

    $text = preg_replace("/%(.*)%/U","",$text);
    $text = preg_replace('/[ ]{2,}/',' ',$text);
    return $text;

Hope this helps!

Cheers,
David.
--
PriceTapestry.com