custom/static-plugins/NdStl/src/Storefront/Controller/LookController.php line 66

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Nd\Stl\Storefront\Controller;
  3. use Nd\Stl\Storefront\Page\Look\LookPageLoader;
  4. use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotCollection;
  5. use Shopware\Core\Content\Cms\Aggregate\CmsSlot\CmsSlotEntity;
  6. use Shopware\Core\Content\Cms\DataResolver\CmsSlotsDataResolver;
  7. use Shopware\Core\Content\Cms\DataResolver\ResolverContext\ResolverContext;
  8. use Shopware\Core\Content\Product\SalesChannel\Detail\ProductConfiguratorLoader;
  9. use Shopware\Core\Framework\DataAbstractionLayer\EntityRepositoryInterface;
  10. use Shopware\Core\Framework\DataAbstractionLayer\Search\Aggregation\Metric\CountAggregation;
  11. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  12. use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
  13. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  14. use Shopware\Core\Framework\Struct\ArrayStruct;
  15. use Shopware\Core\Framework\Uuid\Exception\InvalidUuidException;
  16. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  17. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  18. use Shopware\Storefront\Controller\StorefrontController;
  19. use Shopware\Storefront\Page\GenericPageLoaderInterface;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  23. use Symfony\Component\Routing\Annotation\Route;
  24. /**
  25.  * @RouteScope(scopes={"storefront"})
  26.  */
  27. class LookController extends StorefrontController
  28. {
  29.     private EntityRepositoryInterface $lookRepository;
  30.     private LookPageLoader $lookPageLoader;
  31.     private GenericPageLoaderInterface $genericLoader;
  32.     private CmsSlotsDataResolver $cmsSlotsDataResolver;
  33.     public function __construct(GenericPageLoaderInterface $genericLoaderLookPageLoader $lookPageLoaderEntityRepositoryInterface $lookRepository,
  34.                                 CmsSlotsDataResolver       $cmsSlotsDataResolver)
  35.     {
  36.         $this->lookPageLoader $lookPageLoader;
  37.         $this->lookRepository $lookRepository;
  38.         $this->genericLoader $genericLoader;
  39.         $this->cmsSlotsDataResolver $cmsSlotsDataResolver;
  40.     }
  41.     /**
  42.      * @Route("/look/{lookId}", name="frontend.look.detail", methods={"GET"})
  43.      */
  44.     public function lookDetail(Request $requestSalesChannelContext $context): Response
  45.     {
  46.         $lookId $request->attributes->get('lookId');
  47.         if (!$lookId) {
  48.             return $this->renderStorefront('@Storefront/storefront/page/look/detail/not-found.html.twig', []);
  49.         }
  50.         $page $this->lookPageLoader->load($request$context);
  51.         $criteria = new Criteria([$lookId]);
  52.         try {
  53.             $look $this->lookRepository->search($criteria$context->getContext())->first();
  54.         } catch (InvalidUuidException $exception) {
  55.             return $this->renderStorefront('@Storefront/storefront/page/manufacturer/detail/not-found.html.twig', ['page' => $page]);
  56.         }
  57.         return $this->renderStorefront('@Storefront/storefront/page/content/index.html.twig', ['page' => $page]);
  58.     }
  59.     /**
  60.      * @Route("/nd/look", name="frontend.look.overview", methods={"GET"}, defaults={"XmlHttpRequest"=true})
  61.      */
  62.     public function lookOverview(Request $requestSalesChannelContext $context): Response
  63.     {
  64.         $request->query->set('isFromAjax'true);
  65.         $resolverContext = new ResolverContext($context$request);
  66.         $slot = new CmsSlotEntity();
  67.         $slot->setUniqueIdentifier('id');
  68.         $slot->setType('shop-the-look-overview');
  69.         $slot->setSlot("slot");
  70.         $slots = new CmsSlotCollection([$slot]);
  71.         $slots $this->cmsSlotsDataResolver->resolve($slots$resolverContext);
  72.         $slot $slots->first();
  73.         return $this->renderStorefront('@Storefront/storefront/element/cms-element-shop-the-look-overview.html.twig', [
  74.             'element' => $slot
  75.         ]);
  76. //        $criteria = new Criteria();
  77. //        $criteria->addAssociation("cover");
  78. //        $gender = $request->get('gender');
  79. //        if ($gender) {
  80. //            $criteria->addFilter(new EqualsFilter("genderFilter", $gender));
  81. //        }
  82. //        $looksCount = 8;
  83. //        $page = $request->get('page');
  84. //        if (!$page || !is_numeric($page)) {
  85. //            $page = 1;
  86. //        }
  87. //        $page = (int)$page - 1;
  88. //
  89. //        $currentpage = $request->get('page');
  90. //        if (!$currentpage || !is_numeric($currentpage)) {
  91. //            $currentpage = 1;
  92. //        }
  93. //
  94. //        $criteria->setOffset($looksCount * $page);
  95. //        $criteria->setLimit($looksCount);
  96. //        $criteria->addSorting(new FieldSorting('createdAt', 'desc'));
  97. //
  98. //        $criteria->addAggregation(
  99. //            new CountAggregation('count-looks', 'id')
  100. //        );
  101. //        $looks = $this->lookRepository->search($criteria, $context->getContext());
  102. //        $totalLooks = $looks->getAggregations()->get('count-looks')->getCount();
  103. //        $pages = (int)ceil($totalLooks / 8);
  104. //        $page = $this->genericLoader->load($request, $context);
  105. //
  106. //
  107. //        if (!$looks || $looks->count() == 0) {
  108. //            return $this->renderStorefront('@Storefront/storefront/page/look/empty.html.twig', [
  109. //                'looks' => null,
  110. //                'page' => $page,
  111. //                'totalLooks' => 0,
  112. //                'pages' => $pages,
  113. //                'currentpage' => $currentpage
  114. //            ]);
  115. //        }
  116. //
  117. //        return $this->renderStorefront('@Storefront/storefront/element/cms-element-shop-the-look-overview.html.twig', [
  118. //            'looks' => $looks,
  119. //            'page' => $page,
  120. //            'totalLooks' => $totalLooks,
  121. //            'pages' => $pages,
  122. //            'currentpage' => $currentpage
  123. //        ]);
  124.     }
  125. }