feed-me icon indicating copy to clipboard operation
feed-me copied to clipboard

Table doesn't import deeply nested data

Open jorenvanhee opened this issue 6 years ago • 13 comments

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

  1. Add a content type with a table and supertable field (columns key and value for instance)
  2. Try to import data from both snippets

Additional info

  • Plugin version: 3.1.3
  • Craft version: 3.1.8

jorenvanhee avatar Feb 06 '19 10:02 jorenvanhee

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

xhuang9 avatar Mar 14 '19 02:03 xhuang9

Same issue over here. Any news @brandonkelly?

internetztube avatar Dec 10 '19 14:12 internetztube

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

paulweareframework avatar May 27 '20 19:05 paulweareframework

I replaced the table with a matrix field. That worked well with very little adoption in the template.

internetztube avatar May 27 '20 19:05 internetztube

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!

paulweareframework avatar May 27 '20 19:05 paulweareframework

A few months ago I also dug through the code. I was able to isolate the issue but wasn’t able to fix it.

internetztube avatar May 27 '20 19:05 internetztube

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

paulweareframework avatar May 27 '20 19:05 paulweareframework

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?

paulweareframework avatar May 27 '20 19:05 paulweareframework

Yes

internetztube avatar May 27 '20 19:05 internetztube

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 Screenshot 2020-05-28 at 11 39 43

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 avatar May 28 '20 10:05 paulweareframework

@paulweareframework Thank you Tried your solution and its working fine with table field. Can you please submit a PR?

intelivitadeveloper avatar Jul 13 '20 13:07 intelivitadeveloper

Is this ever going to get fixed? We ran into this problem for one of our sites.

assertzero avatar Mar 07 '22 13:03 assertzero

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 Screenshot 2020-05-28 at 11 39 43

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

weareframework avatar Mar 11 '22 10:03 weareframework

This is resolved for the next v4 and v5 releases via https://github.com/craftcms/feed-me/pull/1268

angrybrad avatar Apr 06 '23 00:04 angrybrad