Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Support Matrix + Super Table nested importing #470

Closed
engram-design opened this issue Feb 10, 2019 · 9 comments
Closed

Support Matrix + Super Table nested importing #470

engram-design opened this issue Feb 10, 2019 · 9 comments

Comments

@engram-design
Copy link
Contributor

No description provided.

@keyurshah
Copy link

i was using feedme to import into a super table inside a matrix and it only imported the first row of each supertable in a matrix block.

wondering what the best workaround would be until this is working. thanks!

@amityweb
Copy link

Is there a solution for this? We wont be able to use super table inside a matrix if we can import into it.

At the moment it creates a separate matrix entry with a ingle super table row in each, instead of one matrix entry and multiple super table rows.

Thanks

@amityweb
Copy link

amityweb commented Jul 8, 2019

The problem is because the $parsedValue array only contains one super table row to import. Super Table like Matrix takes arrays like:

[new1] => Array
(
    [type] => 3
    [order] => 1
    [enabled] => 1
    [fields] => Array
        (
            [accordionTitle] => My first accordion title here
            [accordionBody] => My first text here
        )

)

[new2] => Array
(
    [type] => 3
    [order] => 1
    [enabled] => 1
    [fields] => Array
        (
            [accordionTitle] => My second accordion title here
            [accordionBody] => My second text here
        )

)

But actually only the first or last one is returned, so there is only one new array, not all of them.

So I aded this dirty hack to get it working. I just create a new parsedValue array with all the rows like above. This would not be the clean solution needed, but its got it working for me in case anyone else needs a quick solution:

Replace this line 113 in vendor/craft/feed-me/src/fields/Matrix.php:
$parsedValue = $this->_parseSubField($nodePaths, $subFieldHandle, $subFieldInfo);

With this code

foreach($nodePaths AS $nodePathKey => $nodePathVal)
{
	// Get the node number
	$pathArray = explode("/", $nodePathKey);
	$nodeNumber = $pathArray[count($pathArray)-2];
	$nodePathsArray[$nodeNumber][$nodePathKey] = $nodePathVal;
}

$i=1;
$parsedValue = array();	
foreach($nodePathsArray AS $nodePathsArrayKey => $nodePathsArrayValue)
{
	$parsedValueTemp = $this->_parseSubField($nodePathsArrayValue, $subFieldHandle, $subFieldInfo);
	$parsedValue["new".$i] = reset($parsedValueTemp);
	$i++;
}

@farezramilo
Copy link

@amityweb Your code worked great! I just needed to place $nodePathsArray = []; above the first foreach to accommodate scenarios with multiple nested matrices because the contents eventually get mixed in that array.

@GaryReckard
Copy link

This fix also worked for me. Thanks a lot @amityweb!

Is this a FeedMe bug? Or is there another way to format my JSON to get this to work? I love that it's working now... but I'm not too keen on hacking a plugin like this...

@amityweb
Copy link

amityweb commented Dec 6, 2019

Not necessarily a bug, I dont think its supported yet. In fact you can see Brandon added the enhancement label, so its on their list to do I hope. Shouldn't take too long now I've highlighted the issue to be honest. More elegant code will probably be used though :)

I don't like hacking either but lucky for me its a one off import on site migration from WP to Craft. So now its done I don't need anymore, so I didnt mind hacking it to get it to work. In fact I had to, we had way too much content for me to copy and paste and not use Feedme.

GaryReckard added a commit to happycog/feed-me-supertable-fix that referenced this issue Dec 6, 2019
@ghost
Copy link

ghost commented Jun 2, 2020

Anyone has got this working on Craft 3.4.16? I have the same problem and even though I replace the line pointed above, it does not change the way it is imported. i.e. I keep getting multiple Super Table blocks for each row rather than one Super Table block with multiple rows in them.
feedme-log-after-matrixfix

blockContainer above in the image is the Matrix field which holds the Super Table field mediaReleases.

@tekstrand
Copy link

About to try using the code above for our data import. Would love to see this prioritized into the actual codebase!

@therealpecus
Copy link

therealpecus commented May 14, 2021

The problem is because the $parsedValue array only contains one super table row to import. Super Table like Matrix takes arrays like:
[...]
So I aded this dirty hack to get it working. I just create a new parsedValue array with all the rows like above. This would not be the clean solution needed, but its got it working for me in case anyone else needs a quick solution:
[...]

We've hit an edge case and I'm looking for support/help/insight.
We have a matrix field with 2 block types:

  • one (variantWithHotspots) includes a supertable
  • the other (variantSimple) doesn't

apart from this, fields in each block are identical

When importing, an image belonging to variantSimple block is assigned to the other block, and is eventually skipped.
To clarify, an image from the variantSimple block type is assigned to the variantWithHotspot block and the block entry for variantSimple is skipped. So if we have an array of 1 variantWithHotspotand 2 variantSimple, we end up with:

  • 1 variantWithHotspot (using fields from the first variantSimple block)
  • 1 variantSimple

We're already resetting $nodePathsArray = []; per @farezramilo suggestion. Honestly, I haven't digged into the code, if anyone has a tip it's very welcome

@craftcms craftcms locked and limited conversation to collaborators Aug 13, 2021

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

8 participants