<?php declare(strict_types=1);
namespace Acris\Faq\Storefront\Page\FaqDetail;
use Acris\Faq\Components\Faq\FaqService;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Page\GenericPageLoaderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
class FaqDetailPageLoader
{
private EventDispatcherInterface $eventDispatcher;
private GenericPageLoaderInterface $genericPageLoader;
private FaqService $faqService;
public function __construct(
EventDispatcherInterface $eventDispatcher,
GenericPageLoaderInterface $genericPageLoader,
FaqService $faqService
)
{
$this->eventDispatcher = $eventDispatcher;
$this->genericPageLoader = $genericPageLoader;
$this->faqService = $faqService;
}
public function load(string $faqId, Request $request, SalesChannelContext $salesChannelContext): FaqDetailPage
{
$page = $this->genericPageLoader->load($request, $salesChannelContext);
$page = FaqDetailPage::createFrom($page);
$faq = $this->faqService->getFaqById($faqId, $salesChannelContext, $request);
// load cmsPages
//$faq = $this->faqService->getFaqById($faqId, $salesChannelContext, $request);
$page->setFaq($faq);
$this->eventDispatcher->dispatch(
new FaqDetailPageLoadedEvent($page, $salesChannelContext, $request)
);
return $page;
}
}