BackendSession example

'clientIp' => $clientIp,
            'locale' => $locale->getLocale(),
        ];

        $version = $this->getCachedVersion();
        if (!$version instanceof Version) {
            throw new Exception('Could not get version');
        }

        $payload['version'] = $version->version;

        $session = Shopware()->BackendSession();
        if ($session->offsetExists('update_ftp')) {
            $payload['ftp_credentials'] = $session->offsetGet('update_ftp');
        }

        $payload = json_encode($payload);

        $projectDir = $this->container->getParameter('shopware.app.rootDir');
        $updateFilePath = $projectDir . 'files/update/update.json';

        if (!file_put_contents($updateFilePath$payload)) {
            throw new Exception(sprintf('Could not write file %s', $updateFilePath));
        }
$this->View()->assign('params', $params, true);

        $controller = $this->Request()->getParam('controller');
        $controller = Zend_Json::encode($controller);
        $this->View()->assign('controller', $controller, true);

        $this->View()->assign('maxParameterLength', (int) \ini_get('suhosin.get.max_value_length') + 0, true);

        $firstRunWizardEnabled = $this->isFirstRunWizardEnabled($identity);
        $sbpLogin = 0;
        if ($firstRunWizardEnabled) {
            $tokenData = Shopware()->BackendSession()->get('accessToken');

            $sbpLogin = (int) (!empty($tokenData) && $tokenData->getExpire() >= new DateTime('+30 seconds'));
        }
        $this->View()->assign('sbpLogin', $sbpLogin, true);
        $this->View()->assign('firstRunWizardEnabled', $firstRunWizardEnabled, true);

        $config = $this->get(Shopware_Components_Config::class);

        $shopwareRelease = $this->container->get('shopware.release');

        $this->View()->assign('SHOPWARE_VERSION', $shopwareRelease->getVersion());
        


    /** * Generate new secret by API call */
    private function generateApiShopSecret(): string
    {
        $allowedClassList = [
            AccessTokenStruct::class,
        ];

        $token = @unserialize(Shopware()->BackendSession()->offsetGet('store_token')['allowed_classes' => $allowedClassList]);

        if ($token === null || $token === false) {
            $token = Shopware()->BackendSession()->get('accessToken');
        }

        $params = [
            'domain' => $this->getDomain(),
        ];

        $data = $this->storeClient->doAuthGetRequest(
            $token,
            
/** * Loads the SBP token from current session * If no valid token is available, queries the server for a new one * * @throws RuntimeException * * @return AccessTokenStruct Token to access the API */
    private function getToken(string $shopwareId, string $password): AccessTokenStruct
    {
        $token = Shopware()->BackendSession()->get('accessToken');

        if (empty($token) || $token->getExpire()->getTimestamp() <= strtotime('+30 seconds')) {
            if (empty($shopwareId) || empty($password)) {
                throw new RuntimeException('Could not login - missing login data');
            }

            $accountManagerService = $this->container->get('shopware_plugininstaller.account_manager_service');

            $token = $accountManagerService->getToken($shopwareId$password);

            Shopware()->BackendSession()->set('accessToken', $token);
        }
Home | Imprint | This part of the site doesn't use cookies.