I have multiple working subscriber classes subscribing to ProductListingResultEvent, that add an array as extension to the result.
The code looks something like this:
$myExampleArray = [
['key' => 'foobar', 'val1' => 'bar', 'val2' => 'foobarfoo'],
['key' => 'barfoo', 'val1' => 'foo', 'val2' => 'barfoobar']
];
$myStructCollection = new StructCollection();
foreach ($myExampleArray as $myExampleElement)
{
$myStructCollection->set($myExampleElement['key'], $myExampleElement);
}
$event->getResult()->addExtension('myExampleExtension', $myStructCollection);
Is that the right way to do it? Do I always have to instanciate a new Struct to add data as an extension?