craftcms / feed-me

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

Multiple SuperTable field values inside Matrix will result in 1 item #1419

Closed ruudvdboom closed 3 months ago

ruudvdboom commented 3 months ago

Description

When importing multiple values for a Supertable field inside a matrix field. The result will end up with 1 item instead of multiple.

Example import json

[
    {
        "title": "Test",
        "slug": "test",
        "layers": [
            {
                "employees_items": [
                    {
                        "employee_titel": "Item 1",
                        "employee_id": 100
                    },
                    {
                        "employee_titel": "Item 2",
                        "employee_id": 200
                    }
                ]
            }
        ]
    }
]

Steps to reproduce

  1. Create field "Layers" (matrix field)
  2. Inside "Layers" create a supertable field employeeItems. With the fields employeeTitle and employeeId.
  3. Create the field mapping
  4. Multiple items are expected, but only the last one is imported (also viewable with the debug link)

Possible solution?

On line 72 of SuperTable.php:

$blockIndex = Hash::get($nodePathSegments, 1);

The $blockIndex will get the ID from the matrix layer not the supertable field. So the same key is created for every item. Hence, only the last item is imported.

Change the second param, so the correct keys are created.

$blockIndex = Hash::get($nodePathSegments, 3);

This seems to work, but I'm not sure if this creates other problems.

Additional info

olivierbon commented 3 months ago

Dupe of #470