Customer Session Delay












1















I have a .phtml file that loops through dropdowns. There are 6 dropdowns belonging to two different groups (so 3 dropdowns per group).



I set a session on button click:



if ($this->getRequest()->getParam(self::USERBIKE)) {
$block = $this->layoutFactory->create()->createBlock('VendorModuleBlockGarage');
if ($block->getGarageCollection()->getFirstItem()->getCustomerId()) {
$block->getCoreSession()->setUserBike(1);
}
}


Which I then use to check in the dropdown .phtml file:



if ($session->getUserBike() == 1) {
$useUserBike = true;
# etc.
}


However, nothing seems to happen.



I added some logging to check each dropdown to see what was going on:



$writer = new ZendLogWriterStream(BP. '/var/log/logfile.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

# log each dropdown ID
$logger->info('OUTSIDE: '. $block->getDropdown()->getDropdownId());

# log Session value per dropdown
$logger->info('OUTSIDE USER BIKE SESH: '. $session->getUserBike());

if ($session->getUserBike() == 1) {
$useUserBike = true;
$userBike = $blockGarage->getGarageCollection()->getFirstItem();

# log cur dropdown ID
$logger->info('CURDROPDOWNID: '. $block->getDropdown()->getDropdownId());

# log cur dropdown group ID
$logger->info('CURFINDERID: '. $block->getDropdown()->getFinderId());

if ($block->getDropdown()->getFinderId() == 1) {
switch($block->getDropdown()->getDropdownId())
{
case 1: $compareTo = $userBike->getMakeId(); break;
case 2: $compareTo = $userBike->getModelId(); break;
case 3: $compareTo = $userBike->getYearId(); break;
default: $compareTo = 0; break;
}
}

# log compareTo value
$logger->info(isset($compareTo) ? $compareTo : 'empty str');
$logger->info('======================================'); # visibility break
}


The output of my logfile:




2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 1

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 2

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 3

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 4

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 4

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 5

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 5

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 6

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 6

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================




As you can see, The session doesn't have a value 'til the 4th dropdown. Why is this happening? What am I doing wrong?



Edit:



Minified Block Controller Session Code:



class Garage extends Tempalte
{
protected $customerSession;

public function __construct(
MagentoCustomerModelSession $customerSession
)
{
$this->customerSession = $customerSession;
}

public function getCustomerSession()
{
return $this->customerSession;
}
}









share|improve this question

























  • Post your block coreSession function code

    – Prashant Valanda
    2 days ago


















1















I have a .phtml file that loops through dropdowns. There are 6 dropdowns belonging to two different groups (so 3 dropdowns per group).



I set a session on button click:



if ($this->getRequest()->getParam(self::USERBIKE)) {
$block = $this->layoutFactory->create()->createBlock('VendorModuleBlockGarage');
if ($block->getGarageCollection()->getFirstItem()->getCustomerId()) {
$block->getCoreSession()->setUserBike(1);
}
}


Which I then use to check in the dropdown .phtml file:



if ($session->getUserBike() == 1) {
$useUserBike = true;
# etc.
}


However, nothing seems to happen.



I added some logging to check each dropdown to see what was going on:



$writer = new ZendLogWriterStream(BP. '/var/log/logfile.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

# log each dropdown ID
$logger->info('OUTSIDE: '. $block->getDropdown()->getDropdownId());

# log Session value per dropdown
$logger->info('OUTSIDE USER BIKE SESH: '. $session->getUserBike());

if ($session->getUserBike() == 1) {
$useUserBike = true;
$userBike = $blockGarage->getGarageCollection()->getFirstItem();

# log cur dropdown ID
$logger->info('CURDROPDOWNID: '. $block->getDropdown()->getDropdownId());

# log cur dropdown group ID
$logger->info('CURFINDERID: '. $block->getDropdown()->getFinderId());

if ($block->getDropdown()->getFinderId() == 1) {
switch($block->getDropdown()->getDropdownId())
{
case 1: $compareTo = $userBike->getMakeId(); break;
case 2: $compareTo = $userBike->getModelId(); break;
case 3: $compareTo = $userBike->getYearId(); break;
default: $compareTo = 0; break;
}
}

# log compareTo value
$logger->info(isset($compareTo) ? $compareTo : 'empty str');
$logger->info('======================================'); # visibility break
}


The output of my logfile:




2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 1

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 2

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 3

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 4

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 4

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 5

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 5

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 6

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 6

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================




As you can see, The session doesn't have a value 'til the 4th dropdown. Why is this happening? What am I doing wrong?



Edit:



Minified Block Controller Session Code:



class Garage extends Tempalte
{
protected $customerSession;

public function __construct(
MagentoCustomerModelSession $customerSession
)
{
$this->customerSession = $customerSession;
}

public function getCustomerSession()
{
return $this->customerSession;
}
}









share|improve this question

























  • Post your block coreSession function code

    – Prashant Valanda
    2 days ago
















1












1








1








I have a .phtml file that loops through dropdowns. There are 6 dropdowns belonging to two different groups (so 3 dropdowns per group).



I set a session on button click:



if ($this->getRequest()->getParam(self::USERBIKE)) {
$block = $this->layoutFactory->create()->createBlock('VendorModuleBlockGarage');
if ($block->getGarageCollection()->getFirstItem()->getCustomerId()) {
$block->getCoreSession()->setUserBike(1);
}
}


Which I then use to check in the dropdown .phtml file:



if ($session->getUserBike() == 1) {
$useUserBike = true;
# etc.
}


However, nothing seems to happen.



I added some logging to check each dropdown to see what was going on:



$writer = new ZendLogWriterStream(BP. '/var/log/logfile.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

# log each dropdown ID
$logger->info('OUTSIDE: '. $block->getDropdown()->getDropdownId());

# log Session value per dropdown
$logger->info('OUTSIDE USER BIKE SESH: '. $session->getUserBike());

if ($session->getUserBike() == 1) {
$useUserBike = true;
$userBike = $blockGarage->getGarageCollection()->getFirstItem();

# log cur dropdown ID
$logger->info('CURDROPDOWNID: '. $block->getDropdown()->getDropdownId());

# log cur dropdown group ID
$logger->info('CURFINDERID: '. $block->getDropdown()->getFinderId());

if ($block->getDropdown()->getFinderId() == 1) {
switch($block->getDropdown()->getDropdownId())
{
case 1: $compareTo = $userBike->getMakeId(); break;
case 2: $compareTo = $userBike->getModelId(); break;
case 3: $compareTo = $userBike->getYearId(); break;
default: $compareTo = 0; break;
}
}

# log compareTo value
$logger->info(isset($compareTo) ? $compareTo : 'empty str');
$logger->info('======================================'); # visibility break
}


The output of my logfile:




2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 1

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 2

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 3

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 4

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 4

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 5

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 5

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 6

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 6

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================




As you can see, The session doesn't have a value 'til the 4th dropdown. Why is this happening? What am I doing wrong?



Edit:



Minified Block Controller Session Code:



class Garage extends Tempalte
{
protected $customerSession;

public function __construct(
MagentoCustomerModelSession $customerSession
)
{
$this->customerSession = $customerSession;
}

public function getCustomerSession()
{
return $this->customerSession;
}
}









share|improve this question
















I have a .phtml file that loops through dropdowns. There are 6 dropdowns belonging to two different groups (so 3 dropdowns per group).



I set a session on button click:



if ($this->getRequest()->getParam(self::USERBIKE)) {
$block = $this->layoutFactory->create()->createBlock('VendorModuleBlockGarage');
if ($block->getGarageCollection()->getFirstItem()->getCustomerId()) {
$block->getCoreSession()->setUserBike(1);
}
}


Which I then use to check in the dropdown .phtml file:



if ($session->getUserBike() == 1) {
$useUserBike = true;
# etc.
}


However, nothing seems to happen.



I added some logging to check each dropdown to see what was going on:



$writer = new ZendLogWriterStream(BP. '/var/log/logfile.log');
$logger = new ZendLogLogger();
$logger->addWriter($writer);

# log each dropdown ID
$logger->info('OUTSIDE: '. $block->getDropdown()->getDropdownId());

# log Session value per dropdown
$logger->info('OUTSIDE USER BIKE SESH: '. $session->getUserBike());

if ($session->getUserBike() == 1) {
$useUserBike = true;
$userBike = $blockGarage->getGarageCollection()->getFirstItem();

# log cur dropdown ID
$logger->info('CURDROPDOWNID: '. $block->getDropdown()->getDropdownId());

# log cur dropdown group ID
$logger->info('CURFINDERID: '. $block->getDropdown()->getFinderId());

if ($block->getDropdown()->getFinderId() == 1) {
switch($block->getDropdown()->getDropdownId())
{
case 1: $compareTo = $userBike->getMakeId(); break;
case 2: $compareTo = $userBike->getModelId(); break;
case 3: $compareTo = $userBike->getYearId(); break;
default: $compareTo = 0; break;
}
}

# log compareTo value
$logger->info(isset($compareTo) ? $compareTo : 'empty str');
$logger->info('======================================'); # visibility break
}


The output of my logfile:




2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 1

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 2

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 3

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH:

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 4

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 4

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 5

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 5

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE: 6

2019-01-09T16:33:47+00:00 INFO (6): OUTSIDE USER BIKE SESH: 1

2019-01-09T16:33:47+00:00 INFO (6): CURDROPDOWNID: 6

2019-01-09T16:33:47+00:00 INFO (6): CURFINDERID: 2

2019-01-09T16:33:47+00:00 INFO (6): empty str

2019-01-09T16:33:47+00:00 INFO (6): ======================================




As you can see, The session doesn't have a value 'til the 4th dropdown. Why is this happening? What am I doing wrong?



Edit:



Minified Block Controller Session Code:



class Garage extends Tempalte
{
protected $customerSession;

public function __construct(
MagentoCustomerModelSession $customerSession
)
{
$this->customerSession = $customerSession;
}

public function getCustomerSession()
{
return $this->customerSession;
}
}






magento2 session customer-session






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago







treyBake

















asked 2 days ago









treyBaketreyBake

287116




287116













  • Post your block coreSession function code

    – Prashant Valanda
    2 days ago





















  • Post your block coreSession function code

    – Prashant Valanda
    2 days ago



















Post your block coreSession function code

– Prashant Valanda
2 days ago







Post your block coreSession function code

– Prashant Valanda
2 days ago












1 Answer
1






active

oldest

votes


















1














Change your block code as below.



class Garage extends Tempalte
{
protected $customerSessionFactory;

public function __construct(
MagentoCustomerModelSessionFactory $customerSession
)
{
$this->customerSessionFactory= $customerSessionFactory;
}

public function getCustomerSession()
{
return $this->customerSessionFactory->create();
}
}





share|improve this answer























    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257283%2fcustomer-session-delay%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Change your block code as below.



    class Garage extends Tempalte
    {
    protected $customerSessionFactory;

    public function __construct(
    MagentoCustomerModelSessionFactory $customerSession
    )
    {
    $this->customerSessionFactory= $customerSessionFactory;
    }

    public function getCustomerSession()
    {
    return $this->customerSessionFactory->create();
    }
    }





    share|improve this answer




























      1














      Change your block code as below.



      class Garage extends Tempalte
      {
      protected $customerSessionFactory;

      public function __construct(
      MagentoCustomerModelSessionFactory $customerSession
      )
      {
      $this->customerSessionFactory= $customerSessionFactory;
      }

      public function getCustomerSession()
      {
      return $this->customerSessionFactory->create();
      }
      }





      share|improve this answer


























        1












        1








        1







        Change your block code as below.



        class Garage extends Tempalte
        {
        protected $customerSessionFactory;

        public function __construct(
        MagentoCustomerModelSessionFactory $customerSession
        )
        {
        $this->customerSessionFactory= $customerSessionFactory;
        }

        public function getCustomerSession()
        {
        return $this->customerSessionFactory->create();
        }
        }





        share|improve this answer













        Change your block code as below.



        class Garage extends Tempalte
        {
        protected $customerSessionFactory;

        public function __construct(
        MagentoCustomerModelSessionFactory $customerSession
        )
        {
        $this->customerSessionFactory= $customerSessionFactory;
        }

        public function getCustomerSession()
        {
        return $this->customerSessionFactory->create();
        }
        }






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 2 days ago









        Prashant ValandaPrashant Valanda

        9,54412353




        9,54412353






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f257283%2fcustomer-session-delay%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            An IMO inspired problem

            Management

            Investment