custom/static-plugins/NdFashion/src/Storefront/Controller/ManufacturerController.php line 48

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nd\Fashion\Storefront\Controller;
  3. use Nd\Fashion\Page\Manufacturer\ProductManufacturerPageLoader;
  4. use Shopware\Core\Content\Product\SalesChannel\Detail\ProductConfiguratorLoader;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\Struct\ArrayStruct;
  8. use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
  9. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  10. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  11. use Shopware\Storefront\Controller\StorefrontController;
  12. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\HttpFoundation\Response;
  15. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  16. use Symfony\Component\Routing\Annotation\Route;
  17. /**
  18.  * @RouteScope(scopes={"storefront"})
  19.  */
  20. class ManufacturerController extends StorefrontController
  21. {
  22.     private SalesChannelRepositoryInterface $productRepository;
  23.     private EntityRepositoryInterface $productManufacturerRepository;
  24.     private ProductManufacturerPageLoader $productManufacturerPageLoader;
  25.     private ProductConfiguratorLoader $configuratorLoader;
  26.     public function __constructProductManufacturerPageLoader $productManufacturerPageLoaderEntityRepositoryInterface $productManufacturerRepository,
  27.                                  SalesChannelRepositoryInterface $productRepositoryProductConfiguratorLoader $configuratorLoader)
  28.     {
  29.         $this->productManufacturerPageLoader $productManufacturerPageLoader;
  30.         $this->productRepository $productRepository;
  31.         $this->productManufacturerRepository $productManufacturerRepository;
  32.         $this->configuratorLoader $configuratorLoader;
  33.     }
  34.     /**
  35.      * @Route("/productManufacturer/{productManufacturerId}", name="frontend.productManufacturer.detail", methods={"GET"}, defaults={"XmlHttpRequest"=true})
  36.      */
  37.     public function productManufacturerDetail(Request $requestSalesChannelContext $context): Response
  38.     {
  39.         $productManufacturerId $request->attributes->get('productManufacturerId');
  40. //        if (!$productManufacturerId) {
  41. //            return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/not-found.html.twig', []);
  42. //        }
  43.         $page $this->productManufacturerPageLoader->load($request$context);
  44. //        dump($page);
  45. //
  46. //        die();
  47. //
  48.         $criteria = new Criteria([$productManufacturerId]);
  49. //        $criteria->getAssociation("cmsPage");
  50. //        $criteria->addAssociation("media");
  51. //        $criteria->addAssociation("products");
  52. ////        $criteria->addAssociation("products.product.cover");
  53. ////        $criteria->getAssociation("products.product.configuratorSettings.option");
  54. //        $criteria->getAssociation("cover");
  55.         try {
  56.             $productManufacturer $this->productManufacturerRepository->search($criteria$context->getContext())->first();
  57.         } catch (InvalidUuidException $exception) {
  58.             return $this->renderStorefront('@NdFashion/storefront/page/manufacturer/detail/not-found.html.twig', ['page' => $page]);
  59.         }
  60. //        foreach($productManufacturer->products as $productManufacturerProduct) {
  61. //            $struct = new ArrayStruct();
  62. //            $criteria = new Criteria([$productManufacturerProduct->productId]);
  63. //            $criteria->addAssociation("configuratorSettings.option");
  64. //            $product = $this->productRepository->search($criteria, $context)->first();
  65. //            $productManufacturerProduct->setProduct($product);
  66. //            $struct->set("configuratorSettings", [$this->configuratorLoader->load($product, $context)]);
  67. //            $product->addExtension("configuratorSettings", $struct);
  68. //        }
  69.         if($page->getHeader() && $page->getHeader()->getNavigation()) {
  70.             $activeNavigation $page->getHeader()->getNavigation()->getActive();
  71.             $activeNavigation->setName($productManufacturer->getName());
  72.             $metaInformation $page->getMetaInformation();
  73.             $metaInformation->setMetaTitle($productManufacturer->getName() . "  online kopen | Voorwinden");
  74.             $metaInformation->setMetaDescription($productManufacturer->getName() . " ✔️Meer dan 200 merken online✔️Ontvang spaarpunten ✔️Gratis verzending v.a. €50✔️Gratis Personal Shopper ✔️Shop voor het hele gezin");
  75.         }
  76.         //page.header.navigation.active.name
  77.         return $this->renderStorefront('@NdFashion/storefront/page/content/category-detail.html.twig', ['page' => $page]);
  78. //        if (!$productManufacturer) {
  79. //            return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/not-found.html.twig', ['page' => $page]);
  80. //        }
  81. //        return $this->renderStorefront('@NdCoef/storefront/page/productManufacturer/detail/index.html.twig', [
  82. //            'productManufacturer' => $productManufacturer,
  83. //            'page' => $page
  84. //        ]);
  85.     }
  86. }