vendor/crehler/fast-navigation/src/Controller/FastNavigationController.php line 55

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Crehler\FastNavigation\Controller;
  3. use Shopware\Core\Content\Category\Exception\CategoryNotFoundException;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\DataAbstractionLayer\Exception\InconsistentCriteriaIdsException;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Core\Framework\DataAbstractionLayer\Search\EntitySearchResult;
  8. use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting;
  9. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  10. use Shopware\Core\Framework\Routing\Exception\MissingRequestParameterException;
  11. use Shopware\Core\System\SalesChannel\Entity\SalesChannelRepositoryInterface;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Shopware\Storefront\Controller\StorefrontController;
  14. use Shopware\Storefront\Page\Checkout\Offcanvas\OffcanvasCartPageLoader;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Symfony\Component\Routing\Annotation\Route;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. /**
  20.  * @RouteScope(scopes={"storefront"})
  21.  */
  22. class FastNavigationController extends StorefrontController
  23. {
  24.     /**
  25.      * @var OffcanvasCartPageLoader
  26.      */
  27.     private $offcanvasCartPageLoader;
  28.     /**
  29.      * @var SalesChannelRepositoryInterface
  30.      */
  31.     private $productRepository;
  32.     /**
  33.      * FastNavigationController constructor.
  34.      * @param OffcanvasCartPageLoader $offcanvasCartPageLoader
  35.      */
  36.     public function __construct(OffcanvasCartPageLoader $offcanvasCartPageLoaderSalesChannelRepositoryInterface $productRepository)
  37.     {
  38.         $this->offcanvasCartPageLoader $offcanvasCartPageLoader;
  39.         $this->productRepository $productRepository;
  40.     }
  41.     /**
  42.      * @Route("/widgets/fastnavigation/basket-info", name="frontend.fastnavigation.basket_info", methods={"GET"}, defaults={"XmlHttpRequest"=true})
  43.      *
  44.      * @param Request $request
  45.      * @param SalesChannelContext $context
  46.      * @return JsonResponse
  47.      */
  48.     public function basketInfo(Request $requestSalesChannelContext $context): Response
  49.     {
  50.         try {
  51.             $basketInfo $this->offcanvasCartPageLoader->load($request$context);
  52.         } catch (CategoryNotFoundException $e) {
  53.         } catch (InconsistentCriteriaIdsException $e) {
  54.         } catch (MissingRequestParameterException $e) {
  55.         }
  56.         $totalPrice $basketInfo->getCart()->getPrice()->getTotalPrice();
  57.         $cartCount $basketInfo->getCart()->getLineItems()->count();
  58.         return $this->renderStorefront(
  59.             '@FastNavigation/storefront/element/widget-fast-navigation-basket.html.twig',
  60.             [ 'totalPrice' => $totalPrice'cartCount' => $cartCount ]
  61.         );
  62.     }
  63. }