craftcms / feed-me

Craft CMS plugin for importing entry data from XML, RSS or ATOM feeds—routine task or on-demand.
Other
287 stars 140 forks source link

Table doesn't import deeply nested data #464

Closed jorenvanhee closed 1 year ago

jorenvanhee commented 5 years ago

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

xhuang9 commented 5 years ago

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

internetztube commented 4 years ago

Same issue over here. Any news @brandonkelly?

paulweareframework commented 4 years ago

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

internetztube commented 4 years ago

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

paulweareframework commented 4 years ago

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!

internetztube commented 4 years ago

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

paulweareframework commented 4 years ago

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 commented 4 years ago

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?

internetztube commented 4 years ago

Yes

paulweareframework commented 4 years ago

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

intelivitadeveloper commented 4 years ago

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

assertzero commented 2 years ago

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

weareframework commented 2 years ago

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

angrybrad commented 1 year ago

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