I'm loading parts of the page via AJAX whose content includes a customer login link:
Mage::helper('customer')->getLoginUrl()
Clicking the link gets the user to the login page and returns back to the HTTP referrer. Now that's the problem. Since the link is inside the content of an AJAX request the return/referer URL will be http://www.domain.com/ajaxhelper/ajax/custom_ajax/
How do I get the current URL outside the AJAX content? So when I load http://www.domain.com/ajaxhelper/ajax/custom_ajax/ via AJAX from http://www.domain.com/category-a.html I'd like to return http://www.domain.com/category-a.html instead of http://www.domain.com/ajaxhelper/ajax/custom_ajax/
Already tried this:
$session = Mage::getSingleton('customer/session');
$session->setBeforeAuthUrl(Mage::helper('core/url')->getCurrentUrl());
Mage::helper('customer')->getLoginUrl();
but as said Mage::helper('core/url')->getCurrentUrl() returns the url of the AJAX helper instead of the page invoking the AJAX request.
$ref = (!empty(Mage::app()->getRequest()->getServer('HTTP_REFERER'))) ? Mage::app()->getRequest()->getServer('HTTP_REFERER') : Mage::helper('core/url')->getHomeUrl();. Another (more reliable) approach would be to just pass the current URL to the AJAX request as string, but using the HTTP referer is okay for me here. :) – oschloebe Aug 29 '13 at 08:08catalog/product/view.phtmldoesn't work as the Magento registry basically just sets global variables for the current request. Because the AJAX request is another request, the registry key will be empty inside the AJAX code. Just to let anyone know who tries it this way, too, and fails. :) – oschloebe Aug 29 '13 at 08:13