src/StoreFront/Controller/Fragment/VatInfoController.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Bodymed\Webshop\StoreFront\Controller\Fragment;
  4. use Shopware\Core\Checkout\Cart\Price\Struct\CartPrice;
  5. use Shopware\Core\Framework\Context;
  6. use Shopware\Core\Framework\Routing\Annotation\RouteScope;
  7. use Shopware\Core\PlatformRequest;
  8. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  9. use Shopware\Storefront\Controller\StorefrontController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\RequestStack;
  12. use Symfony\Component\HttpFoundation\Response;
  13. /**
  14.  * @RouteScope(scopes={"storefront"})
  15.  */
  16. class VatInfoController extends StorefrontController
  17. {
  18.     private RequestStack $requestStack;
  19.     public function __construct(RequestStack $requestStack)
  20.     {
  21.         $this->requestStack $requestStack;
  22.     }
  23.     public function footer(): Response
  24.     {
  25.         $mainRequest $this->requestStack->getMasterRequest();
  26.         $currentRequest $this->requestStack->getCurrentRequest();
  27.         $salesChannelContext $this->getSalesChannelContext($mainRequest);
  28.         $minimal false;
  29.         if ($salesChannelContext) {
  30.             return $this->renderVatFooter($this->isVatIncluded($salesChannelContext->getContext()), $minimal);
  31.         }
  32.         throw new \InvalidArgumentException();
  33.     }
  34.     public function footerMinimal(): Response
  35.     {
  36.         $mainRequest $this->requestStack->getMasterRequest();
  37.         $salesChannelContext $this->getSalesChannelContext($mainRequest);
  38.         $minimal true;
  39.         if ($salesChannelContext) {
  40.             return $this->renderVatFooter($this->isVatIncluded($salesChannelContext->getContext()), $minimal);
  41.         }
  42.         throw new \InvalidArgumentException();
  43.     }
  44.     private function renderVatFooter(bool $vatIncludedbool $minimal): Response
  45.     {
  46.         return $this->render('@MadBodymedTheme/storefront/fragment/vat_info/footer.html.twig', [
  47.             'minimal' => $minimal,
  48.             'vatIncluded' => $vatIncluded,
  49.         ]);
  50.     }
  51.     private function isVatIncluded(Context $context): bool
  52.     {
  53.         return CartPrice::TAX_STATE_GROSS === $context->getTaxState();
  54.     }
  55.     private function getSalesChannelContext(Request $request): ?SalesChannelContext
  56.     {
  57.         return $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
  58.     }
  59. }