<?php
declare(strict_types=1);
namespace Bodymed\Webshop\StoreFront\Controller\Fragment;
use Shopware\Core\Checkout\Cart\Price\Struct\CartPrice;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Routing\Annotation\RouteScope;
use Shopware\Core\PlatformRequest;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Shopware\Storefront\Controller\StorefrontController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
/**
* @RouteScope(scopes={"storefront"})
*/
class VatInfoController extends StorefrontController
{
private RequestStack $requestStack;
public function __construct(RequestStack $requestStack)
{
$this->requestStack = $requestStack;
}
public function footer(): Response
{
$mainRequest = $this->requestStack->getMasterRequest();
$currentRequest = $this->requestStack->getCurrentRequest();
$salesChannelContext = $this->getSalesChannelContext($mainRequest);
$minimal = false;
if ($salesChannelContext) {
return $this->renderVatFooter($this->isVatIncluded($salesChannelContext->getContext()), $minimal);
}
throw new \InvalidArgumentException();
}
public function footerMinimal(): Response
{
$mainRequest = $this->requestStack->getMasterRequest();
$salesChannelContext = $this->getSalesChannelContext($mainRequest);
$minimal = true;
if ($salesChannelContext) {
return $this->renderVatFooter($this->isVatIncluded($salesChannelContext->getContext()), $minimal);
}
throw new \InvalidArgumentException();
}
private function renderVatFooter(bool $vatIncluded, bool $minimal): Response
{
return $this->render('@MadBodymedTheme/storefront/fragment/vat_info/footer.html.twig', [
'minimal' => $minimal,
'vatIncluded' => $vatIncluded,
]);
}
private function isVatIncluded(Context $context): bool
{
return CartPrice::TAX_STATE_GROSS === $context->getTaxState();
}
private function getSalesChannelContext(Request $request): ?SalesChannelContext
{
return $request->attributes->get(PlatformRequest::ATTRIBUTE_SALES_CHANNEL_CONTEXT_OBJECT);
}
}