0

On my site i have several pages which set a core session variable as so:

Mage::getSingleton('core/session')->setSellYourArtCheck(1);

If i want to access this anywhere i can successfully do:

Mage::getSingleton('core/session')->getSellYourArtCheck();

But i now need to access this session variable in my custom module but it is showing as empty/null when i try and access it as above.

My Observer.php code for my module:

<?php
class Custom_RegisterArtist_Model_Observer
{
    public function registerArtist(Varien_Event_Observer $observer)
    {
        // other code....

        $is_artist = Mage::getSingleton('core/session')->getSellYourArtCheck();
        if($is_artist == 1)
        {
            $customer->setData('group_id', 4);
        }

        // other code....
     }
}

My $is_artist variable is always empty/null within my module but is fine on any of my pages

12
  • session is not working on custom moduls?
    – Amit Bera
    Commented Oct 6, 2014 at 11:54
  • no, its fine everywhere else (php/phtml pages etc) just not in this module
    – odd_duck
    Commented Oct 6, 2014 at 11:56
  • i guess that you session variable is set properly...Note that :Session variable value is not set until page refersh
    – Amit Bera
    Commented Oct 6, 2014 at 11:59
  • The session variable is definitely set probably beforehand as before i get the module i can access it. My module is called on the customer_save_before event
    – odd_duck
    Commented Oct 6, 2014 at 12:16
  • hi try use customer/session...it may be help you
    – Amit Bera
    Commented Oct 6, 2014 at 12:18

1 Answer 1

1

My guess is that your custom session variable is not set when registerArtist() is called. Also remember that a session is not shared among different browsers, users, and computers. Where are you setting it 1, when are you setting it to null, and when does the observer registerArtist fired? If you don't have the order right for these, you won't have the value you're looking for, especially because in some instances, you're setting the variable to null.

One way to check if you're core session variables are set at all is to try ->getSellYourArtCheck(2) instead of ->getSellYourArtCheck(). Do you get 2 instead of null?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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