| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Redirecting a customer to a custom page after login, depending on parameter | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
Redirecting a customer to a custom page after login, depending on parameter
I would like to redirect customers after login to custom url according to a parameter.
Now, I can do custom redirection, as follows. In /XLite/Module/VendorID/ModuleID/Controller/Customer/Login.php Code:
However, the following code doesn't work. Code:
the customer doesn't get redirected to cart.php?target=mypage, instead the customer gets redirected to cart.php (?target=main is implicit). What am I doing here this time? Of course, I could write another class, say mylogin.php so that the customer can log in to cart.php?target=mylogin to get redirected to cart.php?target=mypage, but this is not elegant or economic. Furthermore, in the module I am currently working with, there are only two pages to redirect, but in another module in my project, there are more pages and I would rather not write one class for each page to redirect... Would anyone have an idea?
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#2
|
|||||||||
|
|||||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
First make sure this function is fit when someone logs in.
Then dump the Request so you can see what's being passed on. Then make sure that - $this->performLogin() - is not doing the redirect - in that case your code below will not run.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#3
|
|||||||
|
|||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
Quote:
As to my impossible debugging, putting the dump function within the controller, anywhere during the login process simply makes logging impossible. I also tried to write a viewer class XLite/Module/VendorID/ModuleID/View/Login.php Code:
in case) echo $dump isn't really in a good place, but the function getAllowedTargets gets always hit whenever the class is called, so I should get the result of dump if not visible on the page, at least in the html source code somewhere. The twig file isn't called, and probably viewer class. So what am I doing wrong again?
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#4
|
|||||||||
|
|||||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
Forget about \Doctrine\Common\Util\Debug::dump - it works but it is not pretty and messes up with the code. And you can't use "echo" unless you use "exit" after it as the execution continues after the echo and it is lost.
Install Symfony Dumper component - https://symfony.com/doc/current/components/var_dumper.html - I would install it globally for your working environment that way you can use it every time for every project. Then you can use Code:
to dump the request without interrupting the execution. You can also use Code:
which will dump the variable and exit. You can also use it within assigns as the dump function returns whatever you are dumping Code:
$request will be assigned the value of Request and value will be dumped, that way you get to see what Request holds without stopping the normal execution of the process. You can also use it in twig files...
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
#5
|
|||||||
|
|||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
Thank you very much, this tool is really awesome! So here is what seems to be happening.
The function loginBody() (or the doActionLogin() which calls this function) is called when a customer goes to page cart.php?target=login¶m=myparam, and click the "Sign in" button. So the instance moves to cart.php?target=login&action=login, and "param" is lost. There is "fromURL" which is in the instance that I could use if I don't find anything better, but I would like to use directly the value of "param". Obvious thing to do is to get it from the viewer class, but somehow I can't call a viewer class for the target "login". Decorating the class /View/Login.php only modifies admin pages, even if I change the zone in ListChild declaration. And, in any case I will want to change the content of the page cart.php?target=login sooner or later. Any advice on how to call the viewer class for this page?
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#6
|
|||||||||
|
|||||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
You will have to declare your param in order to use it. Look at XLite\Controller\Customer\Login how params are listed then follow back the class path how they are declared. And used.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#7
|
|||||||
|
|||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
How the params are treated look extremely confusing to me (somehow the values of the array end up becoming keys going through some functions), but, does this really solve my problem? I can declare param like
Code:
and if I try to set the array directly like Code:
PHP Fatal error: Constant expression contains invalid operations And, of course, if I play with $params etc. within my function loginBody(), then I will have the same problem as before...
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#8
|
|||||||||
|
|||||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
Try not to use 'param' as keyword as this may be "reserved" word in XC
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#9
|
|||||||
|
|||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
Changing the parameter name didn't help. I managed to place $this->getAllParams
in the main body of the class (using __construct), but it still picks up the parameters for login action, not the ones for arriving the login form page. I ended up with the following code. Code:
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#10
|
|||||||||
|
|||||||||
Re: Redirecting a customer to a custom page after login, depending on parameter
If it is not working you are doing something wrong or in the wrong place. You need to follow the stock code and find where customer gets redirected. At login if customer already has cart the redirection is to the cart page otherwise to the page from which login was called. If it is new customer and this is "register" the redirection is to the account page.
Check the handleRequest() method as this is going to be where the request is being redirected to one place or another then just follow the code. Your parameter is not stripped form the url it is just that the redirects are hardcoded to specific page and existing url params are not passed on to the redirected url.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
|||
X-Cart forums © 2001-2020
|