diff --git a/src/Controller/Router.php b/src/Controller/Router.php index b4c51a0..ac25c4a 100644 --- a/src/Controller/Router.php +++ b/src/Controller/Router.php @@ -1,5 +1,4 @@ scopeConfig = $scopeConfig; $this->themeProvider = $themeProvider; $this->validationManager = $validationManager; @@ -186,6 +199,8 @@ public function __construct( $this->storeId = $this->storeManager->getStore()->getId(); $this->tokenizerParameter = $tokenizerParameter; $this->sliderResolver = $sliderResolver; + $this->pageRepository = $pageRepository; + $this->pageByIdentifier = $getPageByIdentifier; parent::__construct( $actionList, @@ -313,9 +328,14 @@ protected function setResponseHomePage(ActionInterface $action) try { $page = $this->getCmsPageFromGraphqlArea(null, $homePageIdentifier); + if (!isset($page['cmsPage'])) { + $action->setType('PWA_ROUTER'); + return; + } + $action->setType(self::PAGE_TYPE_CMS_PAGE); - $action->setId($page['page_id'] ?? ''); - $action->setCmsPage($page); + $action->setId($page['cmsPage']['page_id'] ?? ''); + $action->setCmsPage($page['cmsPage']); $action->setSlider($this->getSliderInformation($page['content'] ?? '')); } catch (\Throwable $th) { $action->setType('PWA_ROUTER'); @@ -351,10 +371,15 @@ protected function getSliderInformation($content) protected function setResponseCmsPage($id, ActionInterface $action) { try { - $page = $this->getCmsPageFromGraphqlArea((int) $id); + $page = $this->getCmsPageFromGraphqlArea((int)$id); + + if (!isset($page['cmsPage'])) { + $this->setNotFound($action); + return; + } - $action->setId($page['page_id'] ?? ''); - $action->setCmsPage($page); + $action->setId($page['cmsPage']['page_id'] ?? ''); + $action->setCmsPage($page['cmsPage']); $action->setSlider($this->getSliderInformation($page['content'] ?? '')); } catch (\Throwable $th) { $this->setNotFound($action); @@ -444,19 +469,23 @@ protected function getCmsPageFromGraphqlArea(int $id = null, string $identifier $pageProvider = $objectManager->create(PageProvider::class); $page = null; + $result = []; if ($id) { - $page = $pageProvider->getDataByPageId($id, (int)$this->storeId); + $page = $this->pageRepository->getById($id); } if ($identifier) { - $page = $pageProvider->getDataByPageIdentifier($identifier, (int)$this->storeId); + $page = $this->pageByIdentifier->execute($identifier, (int)$this->storeId); } + $result['cmsPage'] = $pageProvider->convertPageData($page); + $result['content'] = $page->getContent(); + // vvv reset config area back to initial $objectManager->configure($configLoader->load($currentConfigArea)); - return $page; + return $result; } catch (\Exception $e) { return null; } @@ -631,3 +660,4 @@ protected function _checkShouldBeSecure(RequestInterface $request, $path = '') } } } +