custom/plugins/HyBuys/src/Controller/NavigationController.php line 59

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace HyBuys\Main\Controller;
  3. use Composer\EventDispatcher\EventSubscriberInterface;
  4. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  9. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  10. use Shopware\Core\Framework\Routing\Annotation\Since;
  11. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Shopware\Core\Framework\Context;
  14. use Shopware\Storefront\Controller\StorefrontController;
  15. use Shopware\Storefront\Framework\Cache\Annotation\HttpCache;
  16. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedHook;
  17. use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
  18. use Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoadedHook;
  19. use Shopware\Storefront\Pagelet\Menu\Offcanvas\MenuOffcanvasPageletLoaderInterface;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Symfony\Component\Routing\Annotation\Route;
  23. /**
  24.  * @Route(defaults={"_routeScope"={"storefront"}})
  25.  *
  26.  * @deprecated tag:v6.5.0 - reason:becomes-internal - Will be internal
  27.  */
  28. class NavigationController extends StorefrontController
  29. {
  30.     protected NavigationPageLoaderInterface $navigationPageLoader;
  31.     protected MenuOffcanvasPageletLoaderInterface $offcanvasLoader;
  32.     private $mediaRepository;
  33.     private $productRepository;
  34.     /**
  35.      * @internal
  36.      */
  37.     public function __construct(
  38.         NavigationPageLoaderInterface       $navigationPageLoader,
  39.         MenuOffcanvasPageletLoaderInterface $offcanvasLoader,
  40.         EntityRepositoryInterface           $mediaRepository,
  41.         SalesChannelRepositoryInterface     $productRepository
  42.     )
  43.     {
  44.         $this->navigationPageLoader $navigationPageLoader;
  45.         $this->offcanvasLoader $offcanvasLoader;
  46.         $this->mediaRepository $mediaRepository;
  47.         $this->productRepository $productRepository;
  48.     }
  49.     /**
  50.      * @Since("6.0.0.0")
  51.      * @HttpCache()
  52.      * @Route("/", name="frontend.home.page", options={"seo"="true"}, methods={"GET"})
  53.      */
  54.     public function home(Request $requestSalesChannelContext $contextContext $con): ?Response
  55.     {
  56.         $page $this->navigationPageLoader->load($request$context);
  57.         $this->hook(new NavigationPageLoadedHook($page$context));
  58.         $conex $context->getSalesChannel();
  59.         foreach ($conex->customFields["custom_homepage_popular_brands_select"] as $key => $value) {
  60.             $this->productPriceRepository $this->container->get('product_manufacturer.repository');
  61.             $criteria2 = new Criteria();
  62.             $criteria2->addFilter(new EqualsFilter('id'$value));
  63.             $thisbrand $this->productPriceRepository->search($criteria2$con)->first();
  64.             $criteria3 = new Criteria();
  65.             $criteria3->addFilter(new EqualsFilter('id'$thisbrand->mediaId));
  66.             $image $this->mediaRepository->search($criteria3$con)->first();
  67.             $brands[] = [
  68.                 "image" => $image->url ?? " ",
  69.                 "name" => $thisbrand->name
  70.             ];
  71.         }
  72. //        $this->productsNew = $this->container->get('product_category.repository');
  73.         $latest_products_criteria = new Criteria();
  74.         $latest_products_criteria->addFilter(new EqualsFilter('active'true));
  75.         $latest_products_criteria->addSorting(new FieldSorting('createdAt''DESC'));
  76.         $latest_products_criteria->setLimit(8);
  77.         $latest_products $this->productRepository->search(
  78.             $latest_products_criteria,
  79.             $context
  80.         );
  81.         $fashiion_products_criteria = new Criteria();
  82.         $fashiion_products_criteria->addFilter(
  83.             new EqualsFilter('active'true),
  84.             new EqualsFilter('customFields.custom_product_bestseller_'true)
  85.         );
  86.         $fashiion_products_criteria->addFilter(new EqualsAnyFilter('categoryTree', ['77b959cf66de4c1590c7f9b7da3982f3']));
  87.         $fashiion_products_criteria->addSorting(new FieldSorting('createdAt''DESC'));
  88.         $fashiion_products_criteria->setLimit(8);
  89.         $fashion_products $this->productRepository->search(
  90.             $fashiion_products_criteria,
  91.             $context
  92.         );
  93. //        dd($fashion_products);
  94.         $electronics_products_criteria = new Criteria();
  95.         $electronics_products_criteria->addFilter(
  96.             new EqualsFilter('active'true),
  97.             new EqualsFilter('customFields.custom_product_bestseller_'true)
  98.         );
  99.         $electronics_products_criteria->addFilter(new EqualsAnyFilter('categoryTree', ['251448b91bc742de85643f5fccd89051']));
  100.         $electronics_products_criteria->addSorting(new FieldSorting('createdAt''DESC'));
  101.         $electronics_products_criteria->setLimit(8);
  102.         $electronics_products $this->productRepository->search(
  103.             $electronics_products_criteria,
  104.             $context
  105.         );
  106.         $garden_products_criteria = new Criteria();
  107.         $garden_products_criteria->addFilter(
  108.             new EqualsFilter('active'true),
  109.             new EqualsFilter('customFields.custom_product_bestseller_'true)
  110.         );
  111.         $garden_products_criteria->addFilter(new EqualsAnyFilter('categoryTree', ['991094ecffc74d3282cc72cefcc0e015']));
  112.         $garden_products_criteria->addSorting(new FieldSorting('createdAt''DESC'));
  113.         $garden_products_criteria->setLimit(8);
  114.         $garden_products $this->productRepository->search(
  115.             $garden_products_criteria,
  116.             $context
  117.         );
  118.         $intros_products_criteria = new Criteria();
  119.         $intros_products_criteria->addFilter(
  120.             new EqualsFilter('active'true),
  121.             new EqualsFilter('customFields.custom_homepage_intro_product'true)
  122.         );
  123.         $intros_products_criteria->addSorting(new FieldSorting('createdAt''DESC'));
  124.         $intros_products_criteria->setLimit(5);
  125.         $intros_products $this->productRepository->search(
  126.             $intros_products_criteria,
  127.             $context
  128.         );
  129.         return $this->renderStorefront('@Storefront/storefront/page/content/home.html.twig', [
  130.             'page' => $page,
  131.             'brands' => $brands,
  132.             'latest_products' => $latest_products,
  133.             'fashion_products' => $fashion_products,
  134.             'electronics_products' => $electronics_products,
  135.             'garden_products' => $garden_products,
  136.             'intros_products' => $intros_products
  137.         ]);
  138.     }
  139.     /**
  140.      * @Since("6.3.3.0")
  141.      * @HttpCache()
  142.      * @Route("/navigation/{navigationId}", name="frontend.navigation.page", options={"seo"=true}, methods={"GET"})
  143.      */
  144.     public function index(SalesChannelContext $contextRequest $request): Response
  145.     {
  146.         $page $this->navigationPageLoader->load($request$context);
  147.         $this->hook(new NavigationPageLoadedHook($page$context));
  148.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  149.     }
  150.     /**
  151.      * @Since("6.0.0.0")
  152.      * @HttpCache()
  153.      * @Route("/widgets/menu/offcanvas", name="frontend.menu.offcanvas", methods={"GET"}, defaults={"XmlHttpRequest"=true})
  154.      */
  155.     public function offcanvas(Request $requestSalesChannelContext $context): Response
  156.     {
  157.         $page $this->offcanvasLoader->load($request$context);
  158.         $this->hook(new MenuOffcanvasPageletLoadedHook($page$context));
  159.         $response $this->renderStorefront(
  160.             '@Storefront/storefront/layout/navigation/offcanvas/navigation-pagelet.html.twig',
  161.             ['page' => $page]
  162.         );
  163.         $response->headers->set('x-robots-tag''noindex');
  164.         return $response;
  165.     }
  166. }