我有多个订阅 ProductListingResultEvent 的工作订阅者类,它们添加一个数组作为结果的扩展。
代码看起来像这样:
$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);
这是正确的方法吗?我是否总是必须实例化一个新的结构来添加数据作为扩展?