feed-me
feed-me copied to clipboard
Table doesn't import deeply nested data
Description
Importing deeply nested data into a table or supertable field does not work.
This works:
[
{
"title": "Test1",
"level0": {
"items": [
{
"value": "value1",
"key": "key1"
},
{
"value": "value2",
"key": "key2"
}
]
}
}
]
This doesn't:
[
{
"title": "Test1",
"level0": {
"level1": {
"items": [
{
"key": "key1",
"value": "value1"
},
{
"key": "key2",
"value": "value2"
}
]
}
}
}
]
Steps to reproduce
- Add a content type with a table and supertable field (columns key and value for instance)
- Try to import data from both snippets
Additional info
- Plugin version: 3.1.3
- Craft version: 3.1.8
I have the same issue here. Mine is I couldn't feed a Json format data into a table field of commerce variant.
Here is my test data.
[
{
"title": "Test Product Title",
"variants": [
{
"SKU": "1101060-14",
"stock": "199",
"price": "10",
"table": [
{
"size": "355mL",
"price": "1"
},
{
"size": "6 x 355mL",
"price": "1"
},
{
"size": "",
"price": "1"
}
]
},
{
"SKU": "1101060-16",
"stock": "121",
"price": "10",
"table": [
{
"size": "355mL",
"price": "1",
},
{
"size": "6 x 355mL",
"price": "1",
},
{
"size": "",
"price": "1",
}
]
},
{
"SKU": "1101060-20",
"stock": "6",
"price": "10",
"table": [
{
"size": "355mL",
"price": "1"
},
{
"size": "6 x 355mL",
"price": "1"
},
{
"size": "",
"price": "1"
}
]
}
]
}
]
Feed Me version: 3.1.15 Feed Me Pro vesion: 3.0.4 Craft Commere Version: 2.1.2 Craft Version: 3.1.17.2
Same issue over here. Any news @brandonkelly?
Same issue with product variant table feeds being ignored. Have tried a multitude of data setup combos but always gets ignored.
I thought it might be Hash::get($fieldInfo, 'field') within craft\feedme\services\Process
But it is not unless go further into seeing how it keeps processing and matching up fields.
So I thought its lines 345-348 with the foreach loop of:
// Then, do the same for custom fields. Again, this should be done after populating the element attributes
foreach ($feed['fieldMapping'] as $fieldHandle => $fieldInfo) {
Of course I am probably completely wrong as Im just starting to look through but yeh it comes back empty
If i find a quick fix I'll post later
I replaced the table with a matrix field. That worked well with very little adoption in the template.
That I might do then! But Im in the middle of stepping through it all so will update if I find a resolution. Otherwise admit defeat and go matrix!
A few months ago I also dug through the code. I was able to isolate the issue but wasn’t able to fix it.
Oh it sounds like then I am doomed to the same fate. Part of me thinks its what I got to and maybe the field not being recursive to check for the table field?
Or the format of the table data nested just doesn't get picked up in variants array
Oh hang on, its the CommerceProduct class itself in elements. I've got to the ComplexFields and their is a check for matrix field.
Did you get similar, wondering if just mush in a check for table?
Yes
So I got it working for me, however it is not a fully tested use case! This of course gave me successful output and imported
So withing the file craft\feedme\elements\CommerceProduct go to the method private function _parseVariants($event) and scroll down to about line 262 to where they loop through the feed data and try to match it up with the variantMapping:
$isMatrixField = (Hash::get($fieldInfo, 'field') === 'craft\fields\Matrix');
if ($isMatrixField) {
$complexFields[$variantIndex][$fieldHandle]['info'] = $fieldInfo;
$complexFields[$variantIndex][$fieldHandle]['data'][$nodePath] = $value;
continue;
}
So below this matrixField being added to complexFields, check for table field and do same using these lines:
$isTableField = (Hash::get($fieldInfo, 'field') === 'craft\fields\Table');
if($isTableField === true) {
$complexFields[$variantIndex][$fieldHandle]['info'] = $fieldInfo;
$complexFields[$variantIndex][$fieldHandle]['data'][$nodePath] = $value;
continue;
}
I ran my import and it all worked as shown in screengrab attached
I hope this helps anyone else and I would submit a PR but its not fully tested for all use cases and do not wish to waste the teams time in case my solution is not fully correct!
thank you all
@paulweareframework Thank you Tried your solution and its working fine with table field. Can you please submit a PR?
Is this ever going to get fixed? We ran into this problem for one of our sites.
Is this ever going to get fixed? We ran into this problem for one of our sites.
Did you try the fix above within the file?
So I got it working for me, however it is not a fully tested use case! This of course gave me successful output and imported
So withing the file craft\feedme\elements\CommerceProduct go to the method private function _parseVariants($event) and scroll down to about line 262 to where they loop through the feed data and try to match it up with the variantMapping:
$isMatrixField = (Hash::get($fieldInfo, 'field') === 'craft\fields\Matrix'); if ($isMatrixField) { $complexFields[$variantIndex][$fieldHandle]['info'] = $fieldInfo; $complexFields[$variantIndex][$fieldHandle]['data'][$nodePath] = $value; continue; }
So below this matrixField being added to complexFields, check for table field and do same using these lines:
$isTableField = (Hash::get($fieldInfo, 'field') === 'craft\fields\Table'); if($isTableField === true) { $complexFields[$variantIndex][$fieldHandle]['info'] = $fieldInfo; $complexFields[$variantIndex][$fieldHandle]['data'][$nodePath] = $value; continue; }
I ran my import and it all worked as shown in screengrab attached
I hope this helps anyone else and I would submit a PR but its not fully tested for all use cases and do not wish to waste the teams time in case my solution is not fully correct!
thank you all
This is resolved for the next v4 and v5 releases via https://github.com/craftcms/feed-me/pull/1268