Magento 2 newsletter subscription redirection to custom pageNewsletter subscription validation messages are not displaying on front endNewsletter subscription - send additional emailCannot subscribe email newsletter to second storeview: email already existsHow can I insert JavaScript into the home page upon newsletter subscription confirmation?Magento Custom Newsletter SubscriptionTrigger newsletter success subscription message without refreshHow to add a custom success message to Magento newsletter form?Checkout page - Check if guest is already subscribed to NewsletterHow to customize message in Newsletter subscribe if user already subscribedRemove added to cart message in Magento 2
Why do games have consumables?
Why does nature favour the Laplacian?
Pre-plastic human skin alternative
Minor Revision with suggestion of an alternative proof by reviewer
A Paper Record is What I Hamper
Apply MapThread to all but one variable
How to pronounce 'c++' in Spanish
"You've called the wrong number" or "You called the wrong number"
"The cow" OR "a cow" OR "cows" in this context
How to stop co-workers from teasing me because I know Russian?
Why must Chinese maps be obfuscated?
Elements other than carbon that can form many different compounds by bonding to themselves?
How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?
How to denote matrix elements succinctly?
Multiple options vs single option UI
How to have a sharp product image?
Is there really no use for MD5 anymore?
Can an Area of Effect spell cast outside a Prismatic Wall extend inside it?
What happened to Captain America in Endgame?
How come there are so many candidates for the 2020 Democratic party presidential nomination?
What is causing the white spot to appear in some of my pictures
A strange hotel
How did Captain America manage to do this?
acheter à, to mean both "from" and "for"?
Magento 2 newsletter subscription redirection to custom page
Newsletter subscription validation messages are not displaying on front endNewsletter subscription - send additional emailCannot subscribe email newsletter to second storeview: email already existsHow can I insert JavaScript into the home page upon newsletter subscription confirmation?Magento Custom Newsletter SubscriptionTrigger newsletter success subscription message without refreshHow to add a custom success message to Magento newsletter form?Checkout page - Check if guest is already subscribed to NewsletterHow to customize message in Newsletter subscribe if user already subscribedRemove added to cart message in Magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
Default behavior:
When I subscribed to newsletter then it displayed the success message in the same page itself.
What I want is:
When the customer or guest user subscribe to the newsletter I want them to be redirected to a custom page(cms page).In other words, I just want to display a separate thank you page after clicking "submit" button.
So, how can I achieve this?
Magento 2.2.6
magento2 newsletter redirection
add a comment |
Default behavior:
When I subscribed to newsletter then it displayed the success message in the same page itself.
What I want is:
When the customer or guest user subscribe to the newsletter I want them to be redirected to a custom page(cms page).In other words, I just want to display a separate thank you page after clicking "submit" button.
So, how can I achieve this?
Magento 2.2.6
magento2 newsletter redirection
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15
add a comment |
Default behavior:
When I subscribed to newsletter then it displayed the success message in the same page itself.
What I want is:
When the customer or guest user subscribe to the newsletter I want them to be redirected to a custom page(cms page).In other words, I just want to display a separate thank you page after clicking "submit" button.
So, how can I achieve this?
Magento 2.2.6
magento2 newsletter redirection
Default behavior:
When I subscribed to newsletter then it displayed the success message in the same page itself.
What I want is:
When the customer or guest user subscribe to the newsletter I want them to be redirected to a custom page(cms page).In other words, I just want to display a separate thank you page after clicking "submit" button.
So, how can I achieve this?
Magento 2.2.6
magento2 newsletter redirection
magento2 newsletter redirection
edited Oct 15 '18 at 9:51
Evince Development
1,092319
1,092319
asked Oct 15 '18 at 7:31
Chintan KaneriyaChintan Kaneriya
375214
375214
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15
add a comment |
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15
add a comment |
3 Answers
3
active
oldest
votes
Create a module with name STech_Subscription and create the files like below steps:
Step 1:
Create registration.php under:
app/code/STech/Subscription/registration.php
with below content:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Subscription',
__DIR__
);
Step 2:
Create module.xml under:
app/code/STech/Subscription/etc/module.xml
with below content:
Step 3:
Create di.xml under:
app/code/STech/Subscription/etc/frontend/di.xml
with below content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoNewsletterControllerSubscriberNewAction" type="STechSubscriptionControllerSubscriberNewAction" />
</config>
Step 4:
Create NewAction.php under:
app/code/STech/Subscription/Controller/Subscriber/NewAction.php
with below content:
<?php
namespace STechSubscriptionControllerSubscriber;
use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
use MagentoCustomerModelSession;
use MagentoCustomerModelUrl as CustomerUrl;
use MagentoFrameworkAppActionContext;
use MagentoStoreModelStoreManagerInterface;
use MagentoNewsletterModelSubscriberFactory;
class NewAction extends MagentoNewsletterControllerSubscriberNewAction
protected $customerAccountManagement;
protected $_urlInterface;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
MagentoFrameworkUrlInterface $urlInterface
)
$this->_urlInterface = $urlInterface;
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement);
public function execute()
if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email'))
$email = (string)$this->getRequest()->getPost('email');
try
$this->validateEmailFormat($email);
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
$subscriber = $this->_subscriberFactory->create()->loadByEmail($email);
if ($subscriber->getId()
&& $subscriber->getSubscriberStatus() == MagentoNewsletterModelSubscriber::STATUS_SUBSCRIBED
)
throw new MagentoFrameworkExceptionLocalizedException(
__('This email address is already subscribed.')
);
$status = $this->_subscriberFactory->create()->subscribe($email);
if ($status == MagentoNewsletterModelSubscriber::STATUS_NOT_ACTIVE)
$this->messageManager->addSuccess(__('The confirmation request has been sent.'));
else
$this->messageManager->addSuccess(__('Thank you for your subscription.'));
catch (MagentoFrameworkExceptionLocalizedException $e)
$this->messageManager->addException(
$e,
__('There was a problem with the subscription: %1', $e->getMessage())
);
catch (Exception $e)
$this->messageManager->addException($e, __('Something went wrong with the subscription.'));
$this->getResponse()->setRedirect($this->_urlInterface->getUrl('custom-thankyou')); // Edit tith your custom url
add a comment |
If you don't need to change the subscribe functionality and only want to redirect to a different page, you can simply do this by writing a custom plugin (interceptor).
The steps are mentioned below:
Step 1: Create a file app/code/Stack/NewsletterRedirect/registration.php and write below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Stack_NewsletterRedirect',
__DIR__
);
Step 2: Create the module.xml under app/code/Stack/NewsletterRedirect/etc folder and write below code in it:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Stack_NewsletterRedirect" setup_version="0.1.0"/>
</config>
Step 3: Define the plugin for MagentoNewsletterControllerSubscriberNewAction in the app/code/Stack/NewsletterRedirect/etc/frontend/di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoNewsletterControllerSubscriberNewAction">
<plugin name="redirect_after_newslettter" type="StackNewsletterRedirectPluginSubscriberRedirect"/>
</type>
</config>
Step 4: Write the following code in the plugin file (app/code/Stack/NewsletterRedirect/Plugin/Subscriber/Redirect.php):
<?php
namespace StackNewsletterRedirectPluginSubscriber;
use MagentoFrameworkAppResponseHttp as responseHttp;
use MagentoFrameworkUrlInterface;
class Redirect
public function __construct(
responseHttp $response, UrlInterface $url
)
$this->response = $response;
$this->_url = $url;
public function afterExecute(MagentoNewsletterControllerSubscriberNewAction $subject, $result)
$url = $this->_url->getUrl('contact/index/index');
$this->response->setRedirect($url);
return $result;
Note: You can change contact/index/index
to any other page URL.
Note: Don't forget to run the following commands after creating above files:
php bin/magento setup:upgrade
php bin/magento cache:clean
Please let me know if it works for you.
add a comment |
Sukumar's solution worked for me. In step 2 the code for the file module.xml is not showing, but you can see it here:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Subscription" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f246450%2fmagento-2-newsletter-subscription-redirection-to-custom-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Create a module with name STech_Subscription and create the files like below steps:
Step 1:
Create registration.php under:
app/code/STech/Subscription/registration.php
with below content:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Subscription',
__DIR__
);
Step 2:
Create module.xml under:
app/code/STech/Subscription/etc/module.xml
with below content:
Step 3:
Create di.xml under:
app/code/STech/Subscription/etc/frontend/di.xml
with below content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoNewsletterControllerSubscriberNewAction" type="STechSubscriptionControllerSubscriberNewAction" />
</config>
Step 4:
Create NewAction.php under:
app/code/STech/Subscription/Controller/Subscriber/NewAction.php
with below content:
<?php
namespace STechSubscriptionControllerSubscriber;
use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
use MagentoCustomerModelSession;
use MagentoCustomerModelUrl as CustomerUrl;
use MagentoFrameworkAppActionContext;
use MagentoStoreModelStoreManagerInterface;
use MagentoNewsletterModelSubscriberFactory;
class NewAction extends MagentoNewsletterControllerSubscriberNewAction
protected $customerAccountManagement;
protected $_urlInterface;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
MagentoFrameworkUrlInterface $urlInterface
)
$this->_urlInterface = $urlInterface;
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement);
public function execute()
if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email'))
$email = (string)$this->getRequest()->getPost('email');
try
$this->validateEmailFormat($email);
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
$subscriber = $this->_subscriberFactory->create()->loadByEmail($email);
if ($subscriber->getId()
&& $subscriber->getSubscriberStatus() == MagentoNewsletterModelSubscriber::STATUS_SUBSCRIBED
)
throw new MagentoFrameworkExceptionLocalizedException(
__('This email address is already subscribed.')
);
$status = $this->_subscriberFactory->create()->subscribe($email);
if ($status == MagentoNewsletterModelSubscriber::STATUS_NOT_ACTIVE)
$this->messageManager->addSuccess(__('The confirmation request has been sent.'));
else
$this->messageManager->addSuccess(__('Thank you for your subscription.'));
catch (MagentoFrameworkExceptionLocalizedException $e)
$this->messageManager->addException(
$e,
__('There was a problem with the subscription: %1', $e->getMessage())
);
catch (Exception $e)
$this->messageManager->addException($e, __('Something went wrong with the subscription.'));
$this->getResponse()->setRedirect($this->_urlInterface->getUrl('custom-thankyou')); // Edit tith your custom url
add a comment |
Create a module with name STech_Subscription and create the files like below steps:
Step 1:
Create registration.php under:
app/code/STech/Subscription/registration.php
with below content:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Subscription',
__DIR__
);
Step 2:
Create module.xml under:
app/code/STech/Subscription/etc/module.xml
with below content:
Step 3:
Create di.xml under:
app/code/STech/Subscription/etc/frontend/di.xml
with below content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoNewsletterControllerSubscriberNewAction" type="STechSubscriptionControllerSubscriberNewAction" />
</config>
Step 4:
Create NewAction.php under:
app/code/STech/Subscription/Controller/Subscriber/NewAction.php
with below content:
<?php
namespace STechSubscriptionControllerSubscriber;
use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
use MagentoCustomerModelSession;
use MagentoCustomerModelUrl as CustomerUrl;
use MagentoFrameworkAppActionContext;
use MagentoStoreModelStoreManagerInterface;
use MagentoNewsletterModelSubscriberFactory;
class NewAction extends MagentoNewsletterControllerSubscriberNewAction
protected $customerAccountManagement;
protected $_urlInterface;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
MagentoFrameworkUrlInterface $urlInterface
)
$this->_urlInterface = $urlInterface;
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement);
public function execute()
if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email'))
$email = (string)$this->getRequest()->getPost('email');
try
$this->validateEmailFormat($email);
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
$subscriber = $this->_subscriberFactory->create()->loadByEmail($email);
if ($subscriber->getId()
&& $subscriber->getSubscriberStatus() == MagentoNewsletterModelSubscriber::STATUS_SUBSCRIBED
)
throw new MagentoFrameworkExceptionLocalizedException(
__('This email address is already subscribed.')
);
$status = $this->_subscriberFactory->create()->subscribe($email);
if ($status == MagentoNewsletterModelSubscriber::STATUS_NOT_ACTIVE)
$this->messageManager->addSuccess(__('The confirmation request has been sent.'));
else
$this->messageManager->addSuccess(__('Thank you for your subscription.'));
catch (MagentoFrameworkExceptionLocalizedException $e)
$this->messageManager->addException(
$e,
__('There was a problem with the subscription: %1', $e->getMessage())
);
catch (Exception $e)
$this->messageManager->addException($e, __('Something went wrong with the subscription.'));
$this->getResponse()->setRedirect($this->_urlInterface->getUrl('custom-thankyou')); // Edit tith your custom url
add a comment |
Create a module with name STech_Subscription and create the files like below steps:
Step 1:
Create registration.php under:
app/code/STech/Subscription/registration.php
with below content:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Subscription',
__DIR__
);
Step 2:
Create module.xml under:
app/code/STech/Subscription/etc/module.xml
with below content:
Step 3:
Create di.xml under:
app/code/STech/Subscription/etc/frontend/di.xml
with below content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoNewsletterControllerSubscriberNewAction" type="STechSubscriptionControllerSubscriberNewAction" />
</config>
Step 4:
Create NewAction.php under:
app/code/STech/Subscription/Controller/Subscriber/NewAction.php
with below content:
<?php
namespace STechSubscriptionControllerSubscriber;
use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
use MagentoCustomerModelSession;
use MagentoCustomerModelUrl as CustomerUrl;
use MagentoFrameworkAppActionContext;
use MagentoStoreModelStoreManagerInterface;
use MagentoNewsletterModelSubscriberFactory;
class NewAction extends MagentoNewsletterControllerSubscriberNewAction
protected $customerAccountManagement;
protected $_urlInterface;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
MagentoFrameworkUrlInterface $urlInterface
)
$this->_urlInterface = $urlInterface;
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement);
public function execute()
if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email'))
$email = (string)$this->getRequest()->getPost('email');
try
$this->validateEmailFormat($email);
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
$subscriber = $this->_subscriberFactory->create()->loadByEmail($email);
if ($subscriber->getId()
&& $subscriber->getSubscriberStatus() == MagentoNewsletterModelSubscriber::STATUS_SUBSCRIBED
)
throw new MagentoFrameworkExceptionLocalizedException(
__('This email address is already subscribed.')
);
$status = $this->_subscriberFactory->create()->subscribe($email);
if ($status == MagentoNewsletterModelSubscriber::STATUS_NOT_ACTIVE)
$this->messageManager->addSuccess(__('The confirmation request has been sent.'));
else
$this->messageManager->addSuccess(__('Thank you for your subscription.'));
catch (MagentoFrameworkExceptionLocalizedException $e)
$this->messageManager->addException(
$e,
__('There was a problem with the subscription: %1', $e->getMessage())
);
catch (Exception $e)
$this->messageManager->addException($e, __('Something went wrong with the subscription.'));
$this->getResponse()->setRedirect($this->_urlInterface->getUrl('custom-thankyou')); // Edit tith your custom url
Create a module with name STech_Subscription and create the files like below steps:
Step 1:
Create registration.php under:
app/code/STech/Subscription/registration.php
with below content:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'STech_Subscription',
__DIR__
);
Step 2:
Create module.xml under:
app/code/STech/Subscription/etc/module.xml
with below content:
Step 3:
Create di.xml under:
app/code/STech/Subscription/etc/frontend/di.xml
with below content:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<preference for="MagentoNewsletterControllerSubscriberNewAction" type="STechSubscriptionControllerSubscriberNewAction" />
</config>
Step 4:
Create NewAction.php under:
app/code/STech/Subscription/Controller/Subscriber/NewAction.php
with below content:
<?php
namespace STechSubscriptionControllerSubscriber;
use MagentoCustomerApiAccountManagementInterface as CustomerAccountManagement;
use MagentoCustomerModelSession;
use MagentoCustomerModelUrl as CustomerUrl;
use MagentoFrameworkAppActionContext;
use MagentoStoreModelStoreManagerInterface;
use MagentoNewsletterModelSubscriberFactory;
class NewAction extends MagentoNewsletterControllerSubscriberNewAction
protected $customerAccountManagement;
protected $_urlInterface;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
MagentoFrameworkUrlInterface $urlInterface
)
$this->_urlInterface = $urlInterface;
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement);
public function execute()
if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email'))
$email = (string)$this->getRequest()->getPost('email');
try
$this->validateEmailFormat($email);
$this->validateGuestSubscription();
$this->validateEmailAvailable($email);
$subscriber = $this->_subscriberFactory->create()->loadByEmail($email);
if ($subscriber->getId()
&& $subscriber->getSubscriberStatus() == MagentoNewsletterModelSubscriber::STATUS_SUBSCRIBED
)
throw new MagentoFrameworkExceptionLocalizedException(
__('This email address is already subscribed.')
);
$status = $this->_subscriberFactory->create()->subscribe($email);
if ($status == MagentoNewsletterModelSubscriber::STATUS_NOT_ACTIVE)
$this->messageManager->addSuccess(__('The confirmation request has been sent.'));
else
$this->messageManager->addSuccess(__('Thank you for your subscription.'));
catch (MagentoFrameworkExceptionLocalizedException $e)
$this->messageManager->addException(
$e,
__('There was a problem with the subscription: %1', $e->getMessage())
);
catch (Exception $e)
$this->messageManager->addException($e, __('Something went wrong with the subscription.'));
$this->getResponse()->setRedirect($this->_urlInterface->getUrl('custom-thankyou')); // Edit tith your custom url
answered Oct 15 '18 at 10:16
Sukumar GoraiSukumar Gorai
7,0353729
7,0353729
add a comment |
add a comment |
If you don't need to change the subscribe functionality and only want to redirect to a different page, you can simply do this by writing a custom plugin (interceptor).
The steps are mentioned below:
Step 1: Create a file app/code/Stack/NewsletterRedirect/registration.php and write below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Stack_NewsletterRedirect',
__DIR__
);
Step 2: Create the module.xml under app/code/Stack/NewsletterRedirect/etc folder and write below code in it:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Stack_NewsletterRedirect" setup_version="0.1.0"/>
</config>
Step 3: Define the plugin for MagentoNewsletterControllerSubscriberNewAction in the app/code/Stack/NewsletterRedirect/etc/frontend/di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoNewsletterControllerSubscriberNewAction">
<plugin name="redirect_after_newslettter" type="StackNewsletterRedirectPluginSubscriberRedirect"/>
</type>
</config>
Step 4: Write the following code in the plugin file (app/code/Stack/NewsletterRedirect/Plugin/Subscriber/Redirect.php):
<?php
namespace StackNewsletterRedirectPluginSubscriber;
use MagentoFrameworkAppResponseHttp as responseHttp;
use MagentoFrameworkUrlInterface;
class Redirect
public function __construct(
responseHttp $response, UrlInterface $url
)
$this->response = $response;
$this->_url = $url;
public function afterExecute(MagentoNewsletterControllerSubscriberNewAction $subject, $result)
$url = $this->_url->getUrl('contact/index/index');
$this->response->setRedirect($url);
return $result;
Note: You can change contact/index/index
to any other page URL.
Note: Don't forget to run the following commands after creating above files:
php bin/magento setup:upgrade
php bin/magento cache:clean
Please let me know if it works for you.
add a comment |
If you don't need to change the subscribe functionality and only want to redirect to a different page, you can simply do this by writing a custom plugin (interceptor).
The steps are mentioned below:
Step 1: Create a file app/code/Stack/NewsletterRedirect/registration.php and write below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Stack_NewsletterRedirect',
__DIR__
);
Step 2: Create the module.xml under app/code/Stack/NewsletterRedirect/etc folder and write below code in it:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Stack_NewsletterRedirect" setup_version="0.1.0"/>
</config>
Step 3: Define the plugin for MagentoNewsletterControllerSubscriberNewAction in the app/code/Stack/NewsletterRedirect/etc/frontend/di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoNewsletterControllerSubscriberNewAction">
<plugin name="redirect_after_newslettter" type="StackNewsletterRedirectPluginSubscriberRedirect"/>
</type>
</config>
Step 4: Write the following code in the plugin file (app/code/Stack/NewsletterRedirect/Plugin/Subscriber/Redirect.php):
<?php
namespace StackNewsletterRedirectPluginSubscriber;
use MagentoFrameworkAppResponseHttp as responseHttp;
use MagentoFrameworkUrlInterface;
class Redirect
public function __construct(
responseHttp $response, UrlInterface $url
)
$this->response = $response;
$this->_url = $url;
public function afterExecute(MagentoNewsletterControllerSubscriberNewAction $subject, $result)
$url = $this->_url->getUrl('contact/index/index');
$this->response->setRedirect($url);
return $result;
Note: You can change contact/index/index
to any other page URL.
Note: Don't forget to run the following commands after creating above files:
php bin/magento setup:upgrade
php bin/magento cache:clean
Please let me know if it works for you.
add a comment |
If you don't need to change the subscribe functionality and only want to redirect to a different page, you can simply do this by writing a custom plugin (interceptor).
The steps are mentioned below:
Step 1: Create a file app/code/Stack/NewsletterRedirect/registration.php and write below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Stack_NewsletterRedirect',
__DIR__
);
Step 2: Create the module.xml under app/code/Stack/NewsletterRedirect/etc folder and write below code in it:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Stack_NewsletterRedirect" setup_version="0.1.0"/>
</config>
Step 3: Define the plugin for MagentoNewsletterControllerSubscriberNewAction in the app/code/Stack/NewsletterRedirect/etc/frontend/di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoNewsletterControllerSubscriberNewAction">
<plugin name="redirect_after_newslettter" type="StackNewsletterRedirectPluginSubscriberRedirect"/>
</type>
</config>
Step 4: Write the following code in the plugin file (app/code/Stack/NewsletterRedirect/Plugin/Subscriber/Redirect.php):
<?php
namespace StackNewsletterRedirectPluginSubscriber;
use MagentoFrameworkAppResponseHttp as responseHttp;
use MagentoFrameworkUrlInterface;
class Redirect
public function __construct(
responseHttp $response, UrlInterface $url
)
$this->response = $response;
$this->_url = $url;
public function afterExecute(MagentoNewsletterControllerSubscriberNewAction $subject, $result)
$url = $this->_url->getUrl('contact/index/index');
$this->response->setRedirect($url);
return $result;
Note: You can change contact/index/index
to any other page URL.
Note: Don't forget to run the following commands after creating above files:
php bin/magento setup:upgrade
php bin/magento cache:clean
Please let me know if it works for you.
If you don't need to change the subscribe functionality and only want to redirect to a different page, you can simply do this by writing a custom plugin (interceptor).
The steps are mentioned below:
Step 1: Create a file app/code/Stack/NewsletterRedirect/registration.php and write below code:
<?php
MagentoFrameworkComponentComponentRegistrar::register(
MagentoFrameworkComponentComponentRegistrar::MODULE,
'Stack_NewsletterRedirect',
__DIR__
);
Step 2: Create the module.xml under app/code/Stack/NewsletterRedirect/etc folder and write below code in it:
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Stack_NewsletterRedirect" setup_version="0.1.0"/>
</config>
Step 3: Define the plugin for MagentoNewsletterControllerSubscriberNewAction in the app/code/Stack/NewsletterRedirect/etc/frontend/di.xml file:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="MagentoNewsletterControllerSubscriberNewAction">
<plugin name="redirect_after_newslettter" type="StackNewsletterRedirectPluginSubscriberRedirect"/>
</type>
</config>
Step 4: Write the following code in the plugin file (app/code/Stack/NewsletterRedirect/Plugin/Subscriber/Redirect.php):
<?php
namespace StackNewsletterRedirectPluginSubscriber;
use MagentoFrameworkAppResponseHttp as responseHttp;
use MagentoFrameworkUrlInterface;
class Redirect
public function __construct(
responseHttp $response, UrlInterface $url
)
$this->response = $response;
$this->_url = $url;
public function afterExecute(MagentoNewsletterControllerSubscriberNewAction $subject, $result)
$url = $this->_url->getUrl('contact/index/index');
$this->response->setRedirect($url);
return $result;
Note: You can change contact/index/index
to any other page URL.
Note: Don't forget to run the following commands after creating above files:
php bin/magento setup:upgrade
php bin/magento cache:clean
Please let me know if it works for you.
edited Oct 15 '18 at 10:34
answered Oct 15 '18 at 9:44
Mohit Kumar AroraMohit Kumar Arora
6,93851634
6,93851634
add a comment |
add a comment |
Sukumar's solution worked for me. In step 2 the code for the file module.xml is not showing, but you can see it here:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Subscription" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
add a comment |
Sukumar's solution worked for me. In step 2 the code for the file module.xml is not showing, but you can see it here:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Subscription" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
add a comment |
Sukumar's solution worked for me. In step 2 the code for the file module.xml is not showing, but you can see it here:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Subscription" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
Sukumar's solution worked for me. In step 2 the code for the file module.xml is not showing, but you can see it here:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="STech_Subscription" setup_version="0.0.1">
<sequence>
<module name="Magento_Backend"/>
<module name="Magento_Sales"/>
</sequence>
</module>
</config>
edited Apr 23 at 18:27
answered Apr 23 at 18:16
IsaacIsaac
313
313
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
add a comment |
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
With the redirect there is no need for the default newsletter success message. Any idea how to disable it?
– Isaac
Apr 23 at 18:54
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f246450%2fmagento-2-newsletter-subscription-redirection-to-custom-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
You have to rewrite a controller then you change the redirect, or simply with an observer
– PЯINCƏ
Oct 15 '18 at 8:26
@PRINCE I don't know which controller file should be edited? So, can you tell me that?
– Chintan Kaneriya
Oct 15 '18 at 8:49
Controller/newsletter/subscriber/newAction.php
– PЯINCƏ
Oct 15 '18 at 9:15