vendor/dvdw/platform-choice/src/System/SalesChannel/SalesChannel/EncodedTokenContextRoute.php line 52

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Dvdw\PlatformChoice\System\SalesChannel\SalesChannel;
  3. use Dvdw\PlatformChoice\Framework\Routing\StorefrontSubscriber;
  4. use Dvdw\PlatformChoice\Framework\Util\TokenEncoder;
  5. use Dvdw\PlatformChoice\System\SalesChannel\Struct\EncodedTokenExtension;
  6. use OpenApi\Annotations as OA;
  7. use Shopware\Core\Framework\Routing\Annotation\Since;
  8. use Shopware\Core\Framework\Util\Random;
  9. use Shopware\Core\System\SalesChannel\Context\SalesChannelContextPersister;
  10. use Shopware\Core\System\SalesChannel\SalesChannel\AbstractContextRoute;
  11. use Shopware\Core\System\SalesChannel\SalesChannel\ContextLoadRouteResponse;
  12. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. /**
  15.  * @Route(defaults={"_routeScope"={"store-api"}})
  16.  */
  17. class EncodedTokenContextRoute extends AbstractContextRoute
  18. {
  19.     private AbstractContextRoute $decorated;
  20.     public function __construct(
  21.         AbstractContextRoute $decorated
  22.     )
  23.     {
  24.         $this->decorated $decorated;
  25.     }
  26.     public function getDecorated(): AbstractContextRoute
  27.     {
  28.         return $this->decorated;
  29.     }
  30.     /**
  31.      * @Since("6.3.0.0")
  32.      * @OA\Get(
  33.      *      path="/context",
  34.      *      summary="Fetch the current context",
  35.      *      description="Fetches the current context. This includes for example the `customerGroup`, `currency`, `taxRules` and many more.",
  36.      *      operationId="readContext",
  37.      *      tags={"Store API","System & Context"},
  38.      *      @OA\Response(
  39.      *          response="200",
  40.      *          description="Returns the current context.",
  41.      *          @OA\JsonContent(ref="#/components/schemas/SalesChannelContext")
  42.      *     )
  43.      * )
  44.      * @Route("/store-api/context", name="store-api.context", methods={"GET"})
  45.      */
  46.     public function load(SalesChannelContext $context): ContextLoadRouteResponse
  47.     {
  48.         $encoded TokenEncoder::encodeToken($context->getToken());
  49.         $context->addExtension(EncodedTokenExtension::KEY, new EncodedTokenExtension($encoded));
  50.         return $this->getDecorated()->load($context);
  51.     }
  52. }