<?php declare(strict_types=1);
namespace Dvdw\PlatformChoice\System\SalesChannel\SalesChannel;
use Dvdw\PlatformChoice\Framework\Routing\StorefrontSubscriber;
use Dvdw\PlatformChoice\Framework\Util\TokenEncoder;
use Dvdw\PlatformChoice\System\SalesChannel\Struct\EncodedTokenExtension;
use OpenApi\Annotations as OA;
use Shopware\Core\Framework\Routing\Annotation\Since;
use Shopware\Core\Framework\Util\Random;
use Shopware\Core\System\SalesChannel\Context\SalesChannelContextPersister;
use Shopware\Core\System\SalesChannel\SalesChannel\AbstractContextRoute;
use Shopware\Core\System\SalesChannel\SalesChannel\ContextLoadRouteResponse;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
use Symfony\Component\Routing\Annotation\Route;
/**
* @Route(defaults={"_routeScope"={"store-api"}})
*/
class EncodedTokenContextRoute extends AbstractContextRoute
{
private AbstractContextRoute $decorated;
public function __construct(
AbstractContextRoute $decorated
)
{
$this->decorated = $decorated;
}
public function getDecorated(): AbstractContextRoute
{
return $this->decorated;
}
/**
* @Since("6.3.0.0")
* @OA\Get(
* path="/context",
* summary="Fetch the current context",
* description="Fetches the current context. This includes for example the `customerGroup`, `currency`, `taxRules` and many more.",
* operationId="readContext",
* tags={"Store API","System & Context"},
* @OA\Response(
* response="200",
* description="Returns the current context.",
* @OA\JsonContent(ref="#/components/schemas/SalesChannelContext")
* )
* )
* @Route("/store-api/context", name="store-api.context", methods={"GET"})
*/
public function load(SalesChannelContext $context): ContextLoadRouteResponse
{
$encoded = TokenEncoder::encodeToken($context->getToken());
$context->addExtension(EncodedTokenExtension::KEY, new EncodedTokenExtension($encoded));
return $this->getDecorated()->load($context);
}
}