Redirect – Session is Changed After Redirect in Magento

customer-sessionredirectsession

I am basically trying to implement following thing. I have 2 parts in my app – one is magento for billing and another one is CMS which uses magento as biling gateway

CMS renders a page with hidden form where some encoded data is send with POST request to Magento.
Something like this:

<form id="order-form" method="post" action="magentourl/proceed">
    <input type="hidden" name="order_data" value="{{ encryptedOrderData }}" />
</form>
<script type="text/javascript">
    var form = document.getElementById('order-form');
    form.submit();
</script>

Magento receives data and saves it to session. After that I am making redirect and I can't access my data. Session id is somehow changed between URLs but what is the reason for that I don't understand.

public function proceedAction()
    {

        $encodedOrderJson = $this->getRequest()->getParam('order_data');


        Mage::getSingleton('core/session', array('name' => 'frontend'))->setEncodedOrderJson($encodedOrderJson);
        $this->_redirect('*/*/login');
    }

    public function loginAction()
    {

        $encodedOrderJson = Mage::getSingleton('core/session', array('name' => 'frontend'))->setSessionId()->getEncodedOrderJson();
    }

The problem is that in login action I have different session, and thus I can't access my data.

Where redirect from proceed to login is done SID parameter is added. While is doesn't help a lot.

Best Answer

There are several sessions used in Magento for various reasons. I recommend trying the customer/session instead of core/session if you are trying to retrieve the data from a logged in user:

  $session = Mage::getSingleton( 'customer/session' );
Related Topic