Note that there are some explanatory texts on larger screens.

plurals
  1. POMagento losing messages after redirect
    primarykey
    data
    text
    <p>I have problem with magento messages. I am building custom module which in theory should be able to restrict access to some parts of the store. I have created an observer which hook into <code>controller_action_predispatch</code> event and checks if current request can be accessed by the user. If the action cannot be accessed the observer redirects user and sets the error info. I want to set the redirect url to the page the customer is coming from in order to avoid clicking through entire shop. I am looking at the <code>HTTP_REFERER</code> and use it if it is set, otherwise I redirect customer to homepage. The problem is that in the later case (homepage redirect) everything works great but when I set url based on the referer I do not see error message in message box. </p> <p>The code from the observer (<code>$name</code> variable is a string):</p> <pre><code>Mage::getSingleton('core/session')-&gt;addError('Acces to '.$name.' section is denied'); $url = Mage::helper('core/http')-&gt;getHttpReferer() ? Mage::helper('core/http')-&gt;getHttpReferer() : Mage::getUrl(); Mage::app()-&gt;getResponse()-&gt;setRedirect($url); </code></pre> <p>What I found interesting is that if I do any change in the observer file and save it, then the next request which fails and gets redirected to referer url shows the error information but any subsequent loses the messages.</p> <p>I was thinking that the problem is in the full url and my local instalation (I am using .local domain) but so I tried adding</p> <pre><code>$url = str_replace(Mage::getBaseUrl(), '/', $url); </code></pre> <p>but this did not helped.</p> <p>I also tried redirect using php <code>header()</code> function without any result as well.</p> <p>All cache is disabled. The workflow which triggers the problem is as follows:</p> <ol> <li>I'm going to any accessible page (for example /customer/account) </li> <li>Click on cart link (cart for this account is disabled) </li> <li>Return to /customer/account and the error message is displayed </li> <li>Click on cart link again </li> <li>Return to /customer/account but no error message</li> </ol> <p>Any hint on where to look will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload