1

I am working on custom module for catalog session.I have set the custom value with key in catalog session.If i get from another page with that session then the value is not coming.(its working fine in local server). In test.php i have written this code

 use Magento\Framework\App\Bootstrap;
    require_once '../app/bootstrap.php';
    //error_reporting(0);
    $bootstrap = Bootstrap::create(BP, $_SERVER);
    $objectManager = $bootstrap->getObjectManager();
    $appState = $objectManager->get("Magento\Framework\App\State")->setAreaCode('frontend');
    $catalogSession = $objectManager->get('Magento\Catalog\Model\Session');
    $catalogSession->setData('admin_view',3455);

In getData.php i have written below code

 use Magento\Framework\App\Bootstrap;
        require_once '../app/bootstrap.php';
        //error_reporting(0);
        $bootstrap = Bootstrap::create(BP, $_SERVER);
        $objectManager = $bootstrap->getObjectManager();
        $appState = $objectManager->get("Magento\Framework\App\State")->setAreaCode('frontend');
        $catalogSession = $objectManager->get('Magento\Catalog\Model\Session');
        echo $value = $catalogSession->getData('admin_view');//result should be 3455.locally its working,but in server it is not working.
1

I also faced the same issue.

The value which we set in the catalog session are can't able to get in many files and pages. Better you can try with customer session (Magento\Customer\Model\Session).

0
    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $coreSession = $objectManager->get('Magento\Framework\Session\SessionManagerInterface'); 
    $coreSession->start();
    // Set Session
    $coreSession->setData('key', 'value');
    $coreSession->getData('key', 'value');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.