<?php
declare(strict_types=1);
/**
* @copyright 2020 Crehler Sp. z o. o.
* @link https://crehler.com/
* @support support@crehler.com
*
* @author Mateusz FlasiĆski
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Crehler\Catalog\Service\CatalogReader\Page\CatalogPage;
use Crehler\Catalog\Controller\StoreApi\AbstractCatalogPageRoute;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Page\GenericPageLoaderInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\HttpFoundation\Request;
class CatalogPageLoader implements CatalogPageInterface
{
protected GenericPageLoaderInterface $genericLoader;
protected EventDispatcherInterface $eventDispatcher;
protected AbstractCatalogPageRoute $catalogPageRoute;
public function __construct(GenericPageLoaderInterface $genericLoader, EventDispatcherInterface $eventDispatcher, AbstractCatalogPageRoute $catalogPageRoute)
{
$this->genericLoader = $genericLoader;
$this->eventDispatcher = $eventDispatcher;
$this->catalogPageRoute = $catalogPageRoute;
}
public function load(Request $request, SalesChannelContext $context): CatalogPage
{
$page = $this->genericLoader->load($request, $context);
$page = CatalogPage::createFrom($page);
$catalogPage = $this->catalogPageRoute->load($request, $context)->getPage();
$page->setCatalog($catalogPage->getCatalog());
$page->setCatalogPageEntity($catalogPage->getCatalogPageEntity());
$page->setCatalogProductsIds($catalogPage->getCatalogProductsIds());
$page->setCatalogPages($catalogPage->getCatalogPages());
$this->eventDispatcher->dispatch(
new CatalogPageLoadedEvent($page, $context, $request)
);
// TODO add meta information
return $page;
}
}