I think that you don't need the API route. First of all, API is for admin(back office app) purposes and is not for a storefront.
You need to move
all the http-client
codes to fetch data
to some own service. Then you can inject that new service via container to your subscriber and call something like $this->externalApiService->getData()
in your onFooterPageLoaded()
method.
To add some data (extend footer data) you need to add extension to pagelet e.g.
$event->getPagelet()->addExtension('my_data', $data);
Then you need to extend your twig template and access your data by
page.footer.extensions.my_data
To add array data as an extension you have to define a dummy Struct class
<?php
namespace MyPluginStruct;
use ShopwareCoreFrameworkStructStruct;
class ApiDataStruct extends Struct
{
/**
* @var array
*/
protected $data;
/**
* @return array
*/
public function getData(): array
{
return $this->data;
}
/**
* @param array $data
*/
public function setData(array $data): void
{
$this->data = $data;
}
}
and then in subscriber create an instance of that object
$data = new ApiDataStruct();
$data->setData($this->externalApiService->getData());
$event->getPagelet()->addExtension('my_data', $data);
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…