custom/plugins/HyBuys/src/Controller/HelperController.php line 87

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace HyBuys\Main\Controller;
  3. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\ContainsFilter;
  4. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  5. use Shopware\Storefront\Controller\StorefrontController;
  6. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  7. use Shopware\Storefront\Page\Navigation\NavigationPageLoadedHook;
  8. use Shopware\Storefront\Page\Navigation\NavigationPageLoaderInterface;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Shopware\Core\Framework\Context;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  14. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  15. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  16. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  17. use Shopware\Storefront\Page\GenericPageLoader;
  18. /**
  19.  * @RouteScope (scopes={"storefront"})
  20.  */
  21. class HelperController extends StorefrontController
  22. {
  23.     private $categoryRepository;
  24.     private $productRepository;
  25.     protected $genericPageLoader;
  26.     private $mediaRepository;
  27.     protected NavigationPageLoaderInterface $navigationPageLoader;
  28.     public function __construct(
  29.         GenericPageLoader               $genericPageLoader,
  30.         SalesChannelRepositoryInterface $categoryRepository,
  31.         SalesChannelRepositoryInterface $productRepository,
  32.         EntityRepositoryInterface $mediaRepository,
  33.         NavigationPageLoaderInterface $navigationPageLoader
  34.     )
  35.     {
  36.         $this->categoryRepository $categoryRepository;
  37.         $this->productRepository $productRepository;
  38.         $this->genericPageLoader $genericPageLoader;
  39.         $this->mediaRepository $mediaRepository;
  40.         $this->navigationPageLoader $navigationPageLoader;
  41.     }
  42.     /**
  43.      * @param Request $request
  44.      * @param SalesChannelContext $salesChannelContext
  45.      *
  46.      * @RouteScope (scopes={"storefront"})
  47.      * @Route ("/brands", name="frontend.brands.list", methods={"GET"})
  48.      */
  49.     public function brandsList(Request $requestSalesChannelContext $salesChannelContextContext $con): Response
  50.     {
  51.         $this->productPriceRepository $this->container->get('product_manufacturer.repository');
  52.         $criteria = new Criteria();
  53.         $criteria->addAssociation('cover');
  54.         // $criteria->setLimit(1);
  55.         $criteria->addAssociation('options.group');
  56.         $brands $this->productPriceRepository->search($criteria$con);
  57.         $page $this->genericPageLoader->load($request$salesChannelContext);
  58.         if ($metaInformation $page->getMetaInformation()) {
  59.             $metaInformation->setMetaTitle($metaTitle ?? 'Brands list');
  60.             $page->setMetaInformation($metaInformation);
  61.         }
  62.         return $this->renderStorefront('@HyBuys/storefront/page/content/brands-list.html.twig', [
  63.             'brands' => $brands->getElements(),
  64.             'page' => $page
  65.         ]);
  66.     }
  67.     /**
  68.      * @param Request $request
  69.      * @param SalesChannelContext $salesChannelContext
  70.      *
  71.      * @RouteScope (scopes={"storefront"})
  72.      * @Route ("/ajax/get/brands", name="frontend.get.categorybrands", defaults={"csrf_protected"=false,"XmlHttpRequest"=true}, methods={"GET"})
  73.      */
  74.     public function getCategoryBrands(Request $requestSalesChannelContext $salesChannelContextContext $con): Response
  75.     {
  76.         // $productData = $this->categoryRepository->search(
  77.         //     (new Criteria())->addFilter(new EqualsFilter('id', 'fc8259221f4b4643b0f922b21c6a5e3f')),
  78.         //     $Context
  79.         // )->getElements();
  80.         $criteria = new Criteria();
  81.         $criteria->addFilter(new EqualsFilter('category.id'$request->query->get('category')));
  82.         $criteria->setLimit(1);
  83.         $category $this->categoryRepository->search($criteria$salesChannelContext)->first();
  84.         foreach ($category->customFields['custom_manuf_brand'] as $key => $value) {
  85.             $this->productPriceRepository $this->container->get('product_manufacturer.repository');
  86.             $criteria2 = new Criteria();
  87.             $criteria2->addFilter(new EqualsFilter('id'$value));
  88.             $thisbrand $this->productPriceRepository->search($criteria2$con)->first();
  89.             $criteria3 = new Criteria();
  90.             $criteria3->addFilter(new EqualsFilter('id'$thisbrand->mediaId));
  91.             $image $this->mediaRepository->search($criteria3$con)->first();
  92.             $brands[] = $image->url ?? " ";
  93.         }
  94.         return $this->json($brands);
  95.     }
  96.     /**
  97.      * @param Request $request
  98.      * @param SalesChannelContext $salesChannelContext
  99.      *
  100.      * @RouteScope (scopes={"storefront"})
  101.      * @Route ("/ex", name="frontend.say.xallo", methods={"GET"})
  102.      */
  103.     public function sayXallo(Request $requestSalesChannelContext $salesChannelContextContext $con): Response
  104.     {
  105.         $this->productPriceRepository $this->container->get('product.repository');
  106.         $criteria2 = new Criteria();
  107.         $criteria2->addFilter(new ContainsFilter('categoryTree''77b959cf66de4c1590c7f9b7da3982f3'));
  108.         $productPrice $this->productPriceRepository->search($criteria2$con);
  109. //        $page = $this->genericPageLoader->load('fc8259221f4b4643b0f922b21c6a5e3f', $salesChannelContext);
  110.         dd($productPrice);
  111.     }
  112.     /**
  113.      * @param Request $request
  114.      * @param SalesChannelContext $salesChannelContext
  115.      *
  116.      * @RouteScope (scopes={"storefront"})
  117.      * @Route ("/examplet", name="frontend.say.hello", methods={"GET"})
  118.      */
  119.     public function sayHello(Request $requestSalesChannelContext $salesChannelContextContext $con): Response
  120.     {
  121.         // $productData = $this->categoryRepository->search(
  122.         //     (new Criteria())->addFilter(new EqualsFilter('id', 'fc8259221f4b4643b0f922b21c6a5e3f')),
  123.         //     $Context
  124.         // )->getElements();
  125. //        $criteria = new Criteria();
  126. //        $criteria->addAssociation('cover');
  127. //        // $criteria->setLimit(1);
  128. //        $criteria->addAssociation('options.group');
  129. //        $categories = $this->categoryRepository->search($criteria, $salesChannelContext);
  130.         // using current class reference controller
  131.         $this->productPriceRepository $this->container->get('product_manufacturer.repository');
  132.         $criteria2 = new Criteria();
  133.         $criteria2->addFilter(new EqualsFilter('id''15946fd469a2402891eb9a3f0b473343'));
  134.         $productPrice $this->productPriceRepository->search($criteria2$con);
  135. //        $page = $this->genericPageLoader->load('fc8259221f4b4643b0f922b21c6a5e3f', $salesChannelContext);
  136.         dd($productPrice);
  137.         return $this->renderStorefront('@HyBuys/storefront/page/example.html.twig', [
  138.             'example' => 'Hello world2',
  139.             'page' => $page,
  140.             'categories' => $categories
  141.         ]);
  142.     }
  143.     /**
  144.      * @Route("/e", name="frontend.say.e", methods={"GET"})
  145.      */
  146.     public function sayE(Request $requestSalesChannelContext $salesChannelContextContext $con): Response
  147.     {
  148.         $criteria = new Criteria();
  149.         $criteria->addAssociation('cover');
  150.         // $criteria->setLimit(1);
  151.         $criteria->addAssociation('options.group');
  152.         $categories $this->categoryRepository->search($criteria$salesChannelContext);
  153.         dd($categories);
  154.         return $this->renderStorefront('@HyBuys/storefront/page/example.html.twig', [
  155.             'example' => 'Hello world'
  156.         ]);
  157.     }
  158. }