custom/static-plugins/NdStl/src/Storefront/Page/Look/LookPageLoader.php line 49

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nd\Stl\Storefront\Page\Look;
  3. use Nd\Stl\Core\Content\Look\AbstractLookRoute;
  4. use Nd\Stl\Core\Content\Look\Exception\LookNotFoundException;
  5. use Nd\Stl\Core\Content\Look\LookEntity;
  6. use Shopware\Core\Content\Category\SalesChannel\AbstractCategoryRoute;
  7. use Shopware\Core\Content\Cms\Exception\PageNotFoundException;
  8. use Shopware\Core\Content\Seo\SeoUrlPlaceholderHandlerInterface;
  9. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  10. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  11. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  12. use Symfony\Component\HttpFoundation\Request;
  13. /**
  14.  * @Decoratable()
  15.  */
  16. class LookPageLoader implements LookPageLoaderInterface
  17. {
  18.     /**
  19.      * @var GenericPageLoaderInterface
  20.      */
  21.     private $genericLoader;
  22.     /**
  23.      * @var AbstractCategoryRoute
  24.      */
  25.     private $cmsPageRoute;
  26.     /**
  27.      * @var SeoUrlPlaceholderHandlerInterface
  28.      */
  29.     private $seoUrlReplacer;
  30.     /**
  31.      * @internal
  32.      */
  33.     public function __construct(
  34.         GenericPageLoaderInterface $genericLoader,
  35.         AbstractLookRoute $cmsPageRoute,
  36.         SeoUrlPlaceholderHandlerInterface $seoUrlReplacer
  37.     ) {
  38.         $this->genericLoader $genericLoader;
  39.         $this->cmsPageRoute $cmsPageRoute;
  40.         $this->seoUrlReplacer $seoUrlReplacer;
  41.     }
  42.     public function load(Request $requestSalesChannelContext $context): LookPage
  43.     {
  44.         $page $this->genericLoader->load($request$context);
  45.         $page LookPage::createFrom($page);
  46.         $lookId $request->get('lookId');
  47.         if(!$lookId){
  48.             throw new LookNotFoundException($lookId);
  49.         }
  50.         $look $this->cmsPageRoute
  51.             ->load($lookId$request$context)
  52.             ->getLook();
  53. //        if (!$look->isActive()) {
  54. //            throw new LookNotFoundException($look->getId());
  55. //        }
  56.         $this->loadMetaData($look$page$context->getSalesChannel());
  57.         if (empty($look->getCmsPage())) {
  58.             throw new PageNotFoundException($lookId);
  59.         }
  60.         $page->setCmsPage($look->getCmsPage());
  61.         if ($page->getMetaInformation()) {
  62.             $canonical $this->seoUrlReplacer->generate('frontend.look.detail', ['lookId' => $lookId]);
  63.             $page->getMetaInformation()->assign(['canonical' => $canonical]);
  64.         }
  65.         return $page;
  66.     }
  67.     private function loadMetaData(LookEntity $lookLookPage $pageSalesChannelEntity $salesChannel): void
  68.     {
  69.         $metaInformation $page->getMetaInformation();
  70.         if ($metaInformation === null) {
  71.             return;
  72.         }
  73.         $metaDescription $look->getTranslation('metaDescription');
  74.         $metaInformation->setMetaDescription((string) $metaDescription);
  75.         $metaTitle $look->getTranslation('metaTitle');
  76.         $metaInformation->setMetaTitle((string) $metaTitle);
  77.         $keywords  =$look->getTranslation('keywords');
  78.         $metaInformation->setMetaKeywords((string) $keywords);
  79.     }
  80. }