Magento Session Not Updating in Event Observer

I set the session variable via ajax request as on the check page

Mage::getSingleton('customer/session')->setMyValue($value_from_post_data);

The above is specified in the controller of the custom module.

I have an event observer that observes the checkout_onepage_controller_success_action here, when I access the session, I do not find the my_value session variable that I created.

Note: Session IDs are the same. No change in them. After the session value was set, I printed out all the session data for confirmation, setMyValue created my_value in the session.

So, the ajax request did its job. He set the variable. But the observer takes the old session data. Why is this give me work around

Is this a mistake in purple? Is there a way by which I can ask magento to update the session object. For example, something like

Mage::getModel('core/session')->pleaseMagentoRefreshSessionObject();

So, I get a new session object in memory.

+4
source share
2 answers

What you are describing sounds like a session recording lock . For some reason, somewhere Magento (or ZF / PHP) is closing the session. If you set up storage to save a session on the file system, it gets a write lock.

, , , . , , . , , , .

- . "/etc/local.xml" :

<session_save><![CDATA[files]]></session_save>

:

<session_save><![CDATA[db]]></session_save>

( "var/session" "var/cache" )

0

, .

1.) , . script, , session_save_path:

<?php
    if ( !is_writable(session_save_path()) ) {
        echo 'Whoops, the session save path at "'.session_save_path().'" is NOT writable!';
    } else {
        echo 'The session save path at "'.session_save_path().'" IS writable, look elsewhere!';
    }
?>

, , /. session.save_path = "/tmp" php.ini apache.

 

2.) - app/code/core/Mage/Core/Model/Session/Abstract/Varien.php. Magento.

 

3.) AJAX https:// http://. Web Inspector ( ) 302 . , .

 

4.) AJAX , Magento, isAjax:

jQuery.ajax({
    dataType: 'json',
    data: { 'isAjax': true }, // <-- set this value
    url: '//' + document.location.hostname + '/index.php/module/controller/method/',
    method: 'POST'
})
.done(function( json ) {
    var data = eval(json);
    jQuery('#div').html( data.content );
});

 

5.) : , AJAX. .

jQuery.ajax({
    dataType: 'json',
    data: { 'form_key': window.FORM_KEY, 'isAjax': true }, // <-- note the form_key
    url: '//' + document.location.hostname + '/index.php/module/controller/method/',
    method: 'POST'
})
.done(function( json ) {
    var data = eval(json);
    jQuery('#div').html( data.content );
});

javascript window.FORM_KEY Magento JS .


!

0

Source: https://habr.com/ru/post/1570425/


All Articles