I finally found a way to achieve this goal at least for my use case. Publish my solution here for anyone to use if required.
My Settings for XPath XML parser :
Context -> //product/list/Destination
Product id -> ../../id
List of ports -> DestinationName # This is a term reference field which well have multiple terms per product
Then mapped all required fields as normal.
I created a small module with hook_feeds_after_parse()
hook (I will use "My module").
My module has one .info
file and the .module
file.
function my_module_feeds_after_parse(FeedsSource $source, FeedsParserResult $result) {
$current_id = -1;
$cuurent_destination_list_final = '';
foreach($result->items as $key => $row) {
if($current_id !== $row['xpathparser:0']){
$cuurent_destination_list_final = '';
$current_id = $row['xpathparser:0'];
}
if($cuurent_destination_list_final === ''){
$cuurent_destination_list_final = $row['xpathparser:1'];
}else{
$cuurent_destination_list_final = $cuurent_destination_list_final . ',' . $row['xpathparser:1'];
}
$result->items[$key]['destination_list_final'] = $cuurent_destination_list_final;
}
}
What this module does is it creates a comma separated list of destinations.
Once we set $result->items[$key]['destination_list_final'] (This builds a comma separated list of terms) using this module, we can refer destination_list_final from Feeds Tamper (Refer this).
Install and enable Feeds Tamper PHP.
Add 3 pluggings to xpathparser:1 -> List of Destinations
- Execute php code (This come from above installed module) ->
return $item['destination_list_final'];
- Find replace - Use to remove double quotes (
"
)
- Explode - Use to explode the comma separated list we created from the custom module.
That's it. It worked for me.