Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Table doesn't import deeply nested data #464

Closed
jorenvanhee opened this issue Feb 6, 2019 · 14 comments
Closed

Table doesn't import deeply nested data #464

jorenvanhee opened this issue Feb 6, 2019 · 14 comments
Labels

Comments

@jorenvanhee
Copy link

jorenvanhee commented Feb 6, 2019

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
@xhuang9
Copy link

xhuang9 commented Mar 14, 2019

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
Copy link

Same issue over here. Any news @brandonkelly?

@paulweareframework
Copy link

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
Copy link

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

@paulweareframework
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

Yes

@paulweareframework
Copy link

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
Copy link

intelivitadeveloper commented Jul 13, 2020

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

@assertzero
Copy link

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

@weareframework
Copy link

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
Copy link
Member

This is resolved for the next v4 and v5 releases via #1268

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

10 participants