custom/static-plugins/NdFashion/src/Page/Manufacturer/ProductManufacturerPageLoader.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nd\Fashion\Page\Manufacturer;
  3. use Nd\Fashion\Extension\Content\Product\Aggregate\ProductManufacturer\ProductPageExtension\ProductPageExtension;
  4. use Nd\Fashion\Extension\Content\Product\Aggregate\ProductManufacturer\ProductPageExtension\ProductPageExtensionEntity;
  5. use Nd\Fashion\Page\Manufacturer\Exception\ProductManufacturerNotFoundException;
  6. use Nd\Fashion\Service\ProductManufacturerUrlService;
  7. use Shopware\Core\Content\Category\CategoryEntity;
  8. use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
  9. use Shopware\Core\Content\Category\SalesChannel\AbstractCategoryRoute;
  10. use Shopware\Core\Content\Product\Aggregate\ProductManufacturer\ProductManufacturerEntity;
  11. use Shopware\Core\Content\Seo\SeoUrlPlaceholderHandlerInterface;
  12. use Shopware\Core\System\Annotation\Concept\ExtensionPattern\Decoratable;
  13. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  14. use Shopware\Core\System\SalesChannel\SalesChannelEntity;
  15. use Shopware\Storefront\Framework\Routing\RequestTransformer;
  16. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  17. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  18. use Symfony\Component\HttpFoundation\Request;
  19. /**
  20.  * @Decoratable()
  21.  */
  22. class ProductManufacturerPageLoader implements ProductManufacturerPageLoaderInterface
  23. {
  24.     private GenericPageLoaderInterface $genericLoader;
  25.     private $cmsPageRoute;
  26.     private SeoUrlPlaceholderHandlerInterface $seoUrlReplacer;
  27.     private ProductManufacturerUrlService $productManufacturerUrlService;
  28.     /**
  29.      * @internal
  30.      */
  31.     public function __construct(
  32.         GenericPageLoaderInterface $genericLoader,
  33.         AbstractProductManufacturerRoute $cmsPageRoute,
  34.         SeoUrlPlaceholderHandlerInterface $seoUrlReplacer,
  35.         ProductManufacturerUrlService $productManufacturerUrlService
  36.     ) {
  37.         $this->genericLoader $genericLoader;
  38.         $this->cmsPageRoute $cmsPageRoute;
  39.         $this->seoUrlReplacer $seoUrlReplacer;
  40.         $this->productManufacturerUrlService $productManufacturerUrlService;
  41.     }
  42.     public function load(Request $requestSalesChannelContext $context): ProductManufacturerPage
  43.     {
  44.         $page $this->genericLoader->load($request$context);
  45.         $page ProductManufacturerPage::createFrom($page);
  46.         $productManufacturerId $request->get('productManufacturerId');
  47.         if(!$productManufacturerId){
  48.             throw new ProductManufacturerNotFoundException($productManufacturerId);
  49.         }
  50.         $page->setProductManufacturerId($productManufacturerId);
  51.         $productManufacturer $this->cmsPageRoute
  52.             ->load($productManufacturerId$request$context)
  53.             ->getProductManufacturer();
  54.         if ( $productManufacturer->getExtension('productPageExtension')->getCmsPageType() == "none" ) {
  55.             throw new ProductManufacturerNotFoundException($productManufacturer->getId());
  56.         }
  57.         if($productManufacturer->getExtension('productPageExtension')->getCmsPageType() == "general") {
  58.             header("Location: "$this->productManufacturerUrlService->retrieveGeneralListingUrl($productManufacturer$context));
  59.             die();
  60.         }
  61.         if ($productManufacturer->getExtension('productPageExtension')->getCmsPage()) {
  62.             $this->loadMetaData($productManufacturer->getExtension('productPageExtension'), $page$context->getSalesChannel());
  63.             $page->setCmsPage($productManufacturer->getExtension('productPageExtension')->getCmsPage());
  64.         }else{
  65.             header("Location: "$this->productManufacturerUrlService->retrieveGeneralListingUrl($productManufacturer$context));
  66.             die();
  67.         }
  68.         if ($page->getMetaInformation()) {
  69.             $canonical $this->seoUrlReplacer->generate('frontend.productManufacturer.detail', ['productManufacturerId' => $productManufacturerId]);
  70.             $page->getMetaInformation()->assign(['canonical' => $canonical]);
  71.         }
  72.         return $page;
  73.     }
  74.     private function loadMetaData(ProductPageExtensionEntity $productPageExtensionProductManufacturerPage $pageSalesChannelEntity $salesChannel): void
  75.     {
  76.         $metaInformation $page->getMetaInformation();
  77.         if ($metaInformation === null) {
  78.             return;
  79.         }
  80.         $metaDescription $productPageExtension->getTranslation('metaDescription');
  81.         $metaInformation->setMetaDescription((string) $metaDescription);
  82.         $metaTitle $productPageExtension->getTranslation('metaTitle');
  83.         $metaInformation->setMetaTitle((string) $metaTitle);
  84.         $keywords  =$productPageExtension->getTranslation('keywords');
  85.         $metaInformation->setMetaKeywords((string) $keywords);
  86.     }
  87. }