Session example

session_write_close();

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        $session = $this->get('session');

        $session->template = $theme->getTemplate();
        $session->Admin = true;

        if (!$this->Request()->isXmlHttpRequest()) {
            $this->get('events')->notify('Shopware_Theme_Preview_Starts', [
                'session' => Shopware()->Session(),
                'shop' => $shop,
                'theme' => $theme,
            ]);

            $hash = $this->container->get(OptinServiceInterface::class)->add(OptinServiceInterface::TYPE_THEME_PREVIEW, 300, [
                'sessionName' => session_name(),
                'sessionValue' => $session->get('sessionId'),
            ]);

            $url = $this->Front()->ensureRouter()->assemble([
                'module' => 'frontend',
                
$productId = (int) $this->Request()->getParam('articleId');

        $repository = $this->get('models')->getRepository(Shop::class);
        $shop = $repository->getActiveById($shopId);

        if (!$shop instanceof Shop) {
            throw new Exception('Invalid shop provided.');
        }

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        Shopware()->Session()->set('Admin', true);

        $url = $this->Front()->ensureRouter()->assemble(
            [
                'module' => 'frontend',
                'controller' => 'detail',
                'sArticle' => $productId,
            ]
        );

        $this->Response()->headers->setCookie(new Cookie('shop', (string) $shopId, 0, $shop->getBasePath()));
        $this->redirect($url);
    }
$this->assertEquals('dev', $this->appVariable->getEnvironment());
    }

    /** * @runInSeparateProcess */
    public function testGetSession()
    {
        $request = $this->createMock(Request::class);
        $request->method('hasSession')->willReturn(true);
        $request->method('getSession')->willReturn($session = new Session());

        $this->setRequestStack($request);

        $this->assertEquals($session$this->appVariable->getSession());
    }

    public function testGetSessionWithNoRequest()
    {
        $this->setRequestStack(null);

        $this->assertNull($this->appVariable->getSession());
    }
if ($driver === 'MySQLi') {
                $driverName = MySQLiHandler::class;
            } elseif ($driver === 'Postgre') {
                $driverName = PostgreHandler::class;
            }
        }

        $driver = new $driverName($config, AppServices::request()->getIPAddress());
        $driver->setLogger($logger);

        $session = new Session($driver$config);
        $session->setLogger($logger);

        if (session_status() === PHP_SESSION_NONE) {
            $session->start();
        }

        return $session;
    }

    /** * The Factory for SiteURI. * * @return SiteURIFactory */
$record['extra']['request'] = [
                'uri' => $_SERVER['REQUEST_URI'],
                'method' => $_SERVER['REQUEST_METHOD'],
                'query' => $this->filterRequestUserData($_GET),
                'post' => $this->filterRequestUserData($_POST),
            ];
        } else {
            $record['extra']['request'] = 'Could not process request data';
        }

        if (Shopware()->Container()->initialized('shop')) {
            $record['extra']['session'] = Shopware()->Session();
            $record['extra']['shopId'] = Shopware()->Shop()->getId() ?: null;
            $record['extra']['shopName'] = Shopware()->Shop()->getName() ?: null;
        } else {
            $record['extra']['shop'] = 'No shop data available';
        }

        if (!empty($_SESSION) && \is_object($_SESSION['Shopware']['Auth'])) {
            $record['extra']['session'] = [
                'userId' => $_SESSION['Shopware']['Auth']->id,
                'roleId' => $_SESSION['Shopware']['Auth']->roleID,
            ];
        }

class SessionTest extends TestCase
{
    protected SessionStorageInterface $storage;
    protected SessionInterface $session;

    protected function setUp(): void
    {
        $this->storage = new MockArraySessionStorage();
        $this->session = new Session($this->storage, new AttributeBag()new FlashBag());
    }

    public function testStart()
    {
        $this->assertEquals('', $this->session->getId());
        $this->assertTrue($this->session->start());
        $this->assertNotEquals('', $this->session->getId());
    }

    public function testIsStarted()
    {
        
public function sGetPremiums()
    {
        $context = $this->contextService->getContext();

        $sql = 'SELECT id, esdarticle FROM s_order_basket WHERE sessionID=? AND modus=0 ORDER BY esdarticle DESC';

        $checkForEsdOnly = $this->connection->fetchAllAssociative(
            $sql,
            [Shopware()->Session()->get('sessionId')]
        );

        foreach ($checkForEsdOnly as $esdCheck) {
            if ($esdCheck['esdarticle']) {
                $esdOnly = true;
            } else {
                $esdOnly = false;
            }
        }
        if (!empty($esdOnly)) {
            return [];
        }
return $arguments->getReturn();
    }

    /** * Event listener function of the Shopware_Modules_Articles_SetLastArticle event. * This event is fired after a user visit an article detail page. * This listener function is used to increment the counter value of * the s_articles_similar_shown_ro table. */
    public function beforeSetLastArticle(Enlight_Event_EventArgs $arguments)
    {
        if (Shopware()->Session()->get('Bot') || !$this->isSimilarShownActivated()) {
            return $arguments->getReturn();
        }

        $articleId = $arguments->getArticle();

        $sql = 'SELECT COUNT(id) FROM s_emarketing_lastarticles WHERE sessionID = :sessionId AND articleID = :articleId';

        $alreadyViewed = Shopware()->Db()->fetchOne($sql[
            
if (isset($location)) {
            $this->redirect($location['code' => 301]);

            return;
        }

        // Load the right template         if (!empty($blogArticleData['template'])) {
            $this->View()->loadTemplate('frontend/blog/' . $blogArticleData['template']);
        }

        $this->View()->assign('userLoggedIn', !empty(Shopware()->Session()->get('sUserId')));
        if (!empty(Shopware()->Session()->get('sUserId')) && empty($this->Request()->get('name'))
            && $this->Request()->getParam('__cache') === null) {
            $customerData = Shopware()->Modules()->Admin()->sGetUserData();
            if (\is_array($customerData)) {
                $this->View()->assign('sFormData', [
                    'eMail' => $customerData['additional']['user']['email'],
                    'name' => $customerData['billingaddress']['firstname'] . ' ' . $customerData['billingaddress']['lastname'],
                ]);
            }
        }

        
private ?\Closure $usageReporter;

    public function __construct(RequestStack $requestStack, SessionStorageFactoryInterface $storageFactory, callable $usageReporter = null)
    {
        $this->requestStack = $requestStack;
        $this->storageFactory = $storageFactory;
        $this->usageReporter = null === $usageReporter ? null : $usageReporter(...);
    }

    public function createSession(): SessionInterface
    {
        return new Session($this->storageFactory->createStorage($this->requestStack->getMainRequest()), null, null, $this->usageReporter);
    }
}
/** * Tests the reset token used only from query string. */
  public function testPasswordResetToken() {
    /** @var \Symfony\Component\HttpFoundation\Request $request */
    $request = $this->container->get('request_stack')->getCurrentRequest();

    // @todo: Replace with $request->getSession() as soon as the session is     // present in KernelTestBase.     // see: https://www.drupal.org/node/2484991     $session = new Session();
    $request->setSession($session);

    $token = 'VALID_TOKEN';
    $session->set('pass_reset_1', $token);

    // Set token in query string.     $request->query->set('pass-reset-token', $token);
    $form = $this->buildAccountForm('default');
    // User shouldn't see current password field.     $this->assertFalse($form['account']['current_pass']['#access']);

    
EOT;

        return $this->db->fetchRow($sql['orderId' => $orderId]);
    }

    /** * @return Enlight_Components_Session_Namespace */
    private function getSession()
    {
        if ($this->session == null) {
            $this->session = Shopware()->Session();
        }

        return $this->session;
    }

    /** * @return int */
    private function getPaymentId()
    {
        if (!empty($this->sUserData['additional']['payment']['id'])) {
            
$userId$sessionId,
            ]);
        }
    }

    /** * @return bool */
    public function shouldRefreshLog(Enlight_Controller_Request_Request $request)
    {
        if ($request->getClientIp() === null
            || !empty(Shopware()->Session()->get('Bot'))
        ) {
            return false;
        }
        if (!empty($this->Config()->get('blockIp'))
            && strpos($this->Config()->get('blockIp')$request->getClientIp()) !== false
        ) {
            return false;
        }

        return true;
    }

    
public function testHasSession()
    {
        $request = new Request();

        $this->assertFalse($request->hasSession());
        $this->assertFalse($request->hasSession(true));

        $request->setSessionFactory(function D) {});
        $this->assertTrue($request->hasSession());
        $this->assertFalse($request->hasSession(true));

        $request->setSession(new Session(new MockArraySessionStorage()));
        $this->assertTrue($request->hasSession());
        $this->assertTrue($request->hasSession(true));
    }

    public function testGetSession()
    {
        $request = new Request();

        $request->setSession(new Session(new MockArraySessionStorage()));
        $this->assertTrue($request->hasSession());

        
if ($shop === null) {
            throw new ModelNotFoundException(Shop::class$mailing['languageID']);
        }

        $this->Request()
            ->setHttpHost((string) $shop->getHost())
            ->setBasePath($shop->getBasePath())
            ->setBaseUrl($shop->getBasePath());

        $this->get(ShopRegistrationServiceInterface::class)->registerShop($shop);

        Shopware()->Session()->set('sUserGroup', $mailing['customergroup']);
        $sql = 'SELECT * FROM s_core_customergroups WHERE groupkey=?';
        Shopware()->Session()->set('sUserGroupData', Shopware()->Db()->fetchRow($sql[$mailing['customergroup']]));

        Shopware()->Container()->get(RouterInterface::class)->setGlobalParam('module', 'frontend');
        Shopware()->Config()->offsetSet('DontAttachSession', true);
        Shopware()->Container()->get(ContextServiceInterface::class)->initializeShopContext();

        return $mailing;
    }

    /** * @deprecated in 5.6, will be private in 5.8 * * Init template method * * Initializes the template using the mailing data. * * @param array $mailing * * @return Enlight_Template_Manager */
Home | Imprint | This part of the site doesn't use cookies.