0

I'm using Magento 1.4.1.1.

The following contains a useful URL when run in "template/catalog/product/view.phtml".

$this->helper('core/url')->getCurrentUrl();

When I try to get the same URL by running the following from "Mage_Customer_AccountController". I don't get the same URL.

Mage::helper('core/url')->getCurrentUrl();

Is there anyway I could save the URL value from "template/catalog/product/view.phtml" and be able to use that variable in "Mage_Customer_AccountController" methods ?

Don't hesitate to provide code snippets as I'm new in Magento.

Thanks

3
  • Which view.phtml file are you referring to? What's the difference between the URLs? Mar 10, 2015 at 11:37
  • the getCurrentUrl method returns the URL you are on, the one you see in your browser. Since the template/catalog/product/view.phtml file means your on a product (could be any url) and Mage_Customer_AccountController means your on the url customer/.... these 2 won't return the same URL as they aren't the same page Mar 10, 2015 at 14:03
  • I have couples of website pages that need customers to login. After beeing logged in, I'm trying to get customers back to the URL adress before loging success. That URL adress seems to be only visible from "template/catalog/product/view.phtml". But I need to use that URL adress from the file "Mage_Customer_AccountController". I could I do that ?
    – jolyqr
    Mar 10, 2015 at 14:04

2 Answers 2

0

The following code lines allowed me to set a variable from "theme_lpf/template/catalog/product/view.phtml"

$session = Mage::getSingleton("core/session");
$session->setData("urlBeforeLoginSuccess", $this->helper('core/url')->getCurrentUrl()); 

and use it from a new module "ModuleUrlBackAfterLogin/controllers/AccountController.php" as follows.

$session = Mage::getSingleton("core/session");
$urlBeforeLoginSuccess = $session->getData("urlBeforeLoginSuccess");
0

You can simply set a referer URL.

When you create your login form, use this code to generate the URL (untested):

<form method="post" action="<?php echo $this->getUrl('customer/account/loginPost', array('referer' => Mage::helper('core/url')->urlEncode(Mage::helper('core/url')->getCurrentUrl()) ?>">
[...]

This will result in:

[your-domain]/customer/account/loginPost/referer/[base64-encoded-current-domain]

As you are using the normal customer account controller, it should be enough to set the configuration value in the backend to enable this referer.

Also, from your question I assume that you are about to change the account controller file's contents - don't do this! Magento is a very flexible system where you actually never need to change core files. You can achieve everything you want by simply programming an extension.

Your Answer

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

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