Reputation: 13333
I am developing a module in Prestashop. I want to know how to logout user programmatically, and how can I redirect a user to custom url?
Upvotes: 0
Views: 3041
Reputation: 1234
You can use
$customer->logout();
Or
$customer->mylogout();
The first one is a complete logout, the second one will leave affiliate information in customer's cookies.
Both methods fire actionCustomerLogoutBefore
and actionCustomerLogoutAfter
hooks, so you can attach to them for your redirect.
Speaking of redirect - it depends on what page you want to redirect your customers to, if it's an internal page, you can use either:
$redirect_link = Context::getContext()->link->getPageLink(...); // or "getModuleLink", etc., see classes/Link.php for details.
Or
$redirect_link = $this->context->link->getPageLink(...);
You would then use either redirect
, redirectLink
or redirectAdmin
(probably the other two, as redirectAdmin only makes sense if you're in Back Office) of Tools
class to redirect to that link.
Upvotes: 3