3

I am attempting to get my clients website to redirect to a new page that I have created, which will happen automatically after they signup to the newsletter. I have followed the instructions here but have the same issue mentioned at the bottom of the page - with the URL Redirect Method in place, the redirected page loads but it no longer records the subscriber in the admin: http://www.magentocommerce.com/boards/v/viewthread/273119/#t432370

Has anyone else experienced this issue or have advice on the solution? I am pretty new to Magento, so my knowledge is limited.

Thanks Michael

  • are you want for frontend. – Amit Bera Sep 23 '14 at 16:53
  • have you install any custom module for newsletter? – Keyul Shah Sep 23 '14 at 17:00
  • Hey Mike, feel free to post the relevant codes that helped you to resolve this issue and then please accept it. – Rajeev K Tomy Nov 8 '14 at 6:12
5

I ran into this same issue, and there is a simple fix. Rather than overwriting controllers, you can pass a hidden field in the form that defines the redirect URL.

<input type="hidden" name="referer_url" value="{my URL}">

newAction() in Mage_Newsletter_SubscriberController by default returns to the same page you're on, but _getRefererUrl() in Mage_Core_Controller_Varien_Action has options for overriding that by passing a parameter in the request.

| improve this answer | |
2

Magento save newsletter subscription from newsletter/manage/save and newsletter/subscribe/new url that means you need overwrite your controller class Mage_Newsletter_SubscriberController and Mage_Newsletter_ManageController and after subscription successfully you need redirect to you custom page using

$this->_redirect('custompgeurl');

See how override a controller in magento http://www.amitbera.com/how-to-override-a-controller-in-magento/

[Edit FULL CODE]:

Step1: app/code/local/Amit/Customnewsletter/etc/config.xml and full code for this file

<?xml version="1.0"?>
<config>
    <modules>
    <Amit_Customnewsletter>
            <version>1.0.0</version>
        </Amit_Customnewsletter>
    </modules>
    <frontend>
        <routers>
            <newsletter>
                <args>
                    <modules>
                        <customnewsletter before="Mage_Newsletter">Amit_Customnewsletter</customnewsletter>
                    </modules>
                </args>
            </newsletter>
        </routers>
    </frontend>    

</config>

step2: app/code/local/Amit/Customnewsletter/controllers/ManageController.php

code is

<?php
require_once Mage::getModuleDir('controllers', "Mage_Newsletter").DS."ManageController.php";
class Amit_Customnewsletter_ManageController extends Mage_Newsletter_ManageController
{
    public function saveAction()
    {
        if (!$this->_validateFormKey()) {
            return $this->_redirect('customer/account/');
        }
        try {
            Mage::getSingleton('customer/session')->getCustomer()
            ->setStoreId(Mage::app()->getStore()->getId())
            ->setIsSubscribed((boolean)$this->getRequest()->getParam('is_subscribed', false))
            ->save();
            if ((boolean)$this->getRequest()->getParam('is_subscribed', false)) {
                Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been saved.'));
            } else {
                Mage::getSingleton('customer/session')->addSuccess($this->__('The subscription has been removed.'));
            }
        }
        catch (Exception $e) {
            Mage::getSingleton('customer/session')->addError($this->__('An error occurred while saving your subscription.'));
        }
    //need to change here
       // $this->_redirect('customer/account/');
       $this->_redirect('custompageurl');
    }
}

Step3: app/code/local/Amit/Customnewsletter/controllers/SubscriberController.php

code:

<?php
require_once Mage::getModuleDir('controllers', "Mage_Newsletter").DS."SubscriberController.php";
class Amit_Customnewsletter_SubscriberController extends Mage_Newsletter_SubscriberController
{
    public function newAction(){
               if ($this->getRequest()->isPost() && $this->getRequest()->getPost('email')) {
            $session            = Mage::getSingleton('core/session');
            $customerSession    = Mage::getSingleton('customer/session');
            $email              = (string) $this->getRequest()->getPost('email');

            try {
                if (!Zend_Validate::is($email, 'EmailAddress')) {
                    Mage::throwException($this->__('Please enter a valid email address.'));
                }

                if (Mage::getStoreConfig(Mage_Newsletter_Model_Subscriber::XML_PATH_ALLOW_GUEST_SUBSCRIBE_FLAG) != 1 && 
                    !$customerSession->isLoggedIn()) {
                    Mage::throwException($this->__('Sorry, but administrator denied subscription for guests. Please <a href="%s">register</a>.', Mage::helper('customer')->getRegisterUrl()));
                }

                $ownerId = Mage::getModel('customer/customer')
                        ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
                        ->loadByEmail($email)
                        ->getId();
                if ($ownerId !== null && $ownerId != $customerSession->getId()) {
                    Mage::throwException($this->__('This email address is already assigned to another user.'));
                }

                $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
                if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
                    $session->addSuccess($this->__('Confirmation request has been sent.'));
                }
                else {
                    $session->addSuccess($this->__('Thank you for your subscription.'));
                }
            }
            catch (Mage_Core_Exception $e) {
                $session->addException($e, $this->__('There was a problem with the subscription: %s', $e->getMessage()));
            }
            catch (Exception $e) {
                $session->addException($e, $this->__('There was a problem with the subscription.'));
            }
        }
    //need change here 
        //$this->_redirectReferer();
    $this->_redirect('custompgeurl');
    }

    }

Step4: app/etc/modules/Amit_Customnewsletter.xml and code is

<?xml version="1.0"?>
    <config>
        <modules>
            <Amit_Customnewsletter>
                <active>true</active>
                <codePool>local</codePool>
            </Amit_Customnewsletter>
        </modules>
    </config>
| improve this answer | |
  • Thanks for your detailed response, but you will have to excuse me as I don't understand what you are telling me to do. My magento experience is very basic. I have tried modifying the SubscriberController file, but this has not worked (following these instructions: subhashecommerce.blogspot.co.uk/2013/05/… ) Upon reading the Magento official forum, they have advised never to update these files and everything should be done via the admin using the URL Rewrite Management menu. As far as I am aware the site does not have any custom modules installed. – Mike Hutton Sep 23 '14 at 17:37
  • not good use core rewrite.subhashecommerce.blogspot.co.uk/2013/05/… give good directon but from app\code\local\ folder controller did not.yuo need to follow just change subhashecommerce.blogspot.co.uk/2013/05/… – Amit Bera Sep 23 '14 at 17:46
  • Sorry, but I am still not understanding your instructions? – Mike Hutton Sep 23 '14 at 18:17
  • Managed to solve it. Thanks for your help. These instructions were correct: subhashecommerce.blogspot.co.uk/2013/05/… but the issue was in this location instead: /app/code/local/daffodil/advancednewsletter/controllers/subscribercontroller.php – Mike Hutton Sep 23 '14 at 18:36
  • 1
    There are two things to be changed: 1. Step 2: folder "Controller" -> "controllers" 2. There is one extra "}" in the Step 3 at end to be removed. – Yundong Cai Nov 17 '15 at 9:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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