0

I have the Newsletter need to confirm disabled

enter image description here

When I subscribe from footer or from a logged account it works, but when I subscribe from the new account form then the subscription status is set to unconfirmed.

By default new customers are disabled, and need to be manually activated from backend, but when I activate the new customer then the newsletter status is set automatically to unsubscribed and an unsubscription email is sent to customer.

enter image description here

In this image customer with id 916 is not yet activated, and customer with id 917 is activated. So the status from 917 went from unconfirmed to unsubscribed. (both are fake emails).

Why are the new customers unconfirmed despite need to confirm is disabled? Why are they unsubscribed when this customers are activated?

Edit: I wanted to be sure that need to confirm is off, so just now I changed the subscribe function in app/code/core/Mage/Newsletter/Model/Subscriber.php to this:

// $isConfirmNeed   = (Mage::getStoreConfig(self::XML_PATH_CONFIRMATION_FLAG) == 1) ? true : false;
$isConfirmNeed = false;

But even with this change the new customers subscribed to the newsletter are unconfirmed.

2 Answers 2

1

Finally I've found a solution.

In app/code/core/Mage/Newsletter/Model/Subscriber.php in the subscribeCustomer function there is the following code:

$status = $customer->getIsSubscribed()
          ? (!is_null($confirmation) ? self::STATUS_UNCONFIRMED : self::STATUS_SUBSCRIBED)
          : self::STATUS_UNSUBSCRIBED;

So, confirmation is not null, and self::STATUS_UNCONFIRMED is asigned to $status.

I changed it to:

$status = $customer->getIsSubscribed() ? 
          self::STATUS_SUBSCRIBED : self::STATUS_UNSUBSCRIBED;

And now I avoid the unwanted unconfirmed status.

Maybe it is not the best solution, but it works. Now I will override this function model in code/local with the changes (not a good practice edit core files directly) I hope it helps somebody in the future after updating in local file.

3
  • You should not edit the core files
    – Vivek
    Jun 13, 2018 at 11:25
  • 1
    @Vivek this is exactly what I said, it is not a good practice to edit core files, so I overrided it in code/local folder.
    – Alex
    Jun 13, 2018 at 13:21
  • yes, thats what I mean :)
    – Vivek
    Jun 14, 2018 at 6:03
0

You can try below code Mage_Newsletter_SubscriberController

Make override the controller SubscriberController. Replace below code with newAction() function.

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);

                    $subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
                    # change status to "subscribed" and save
                    $subscriber->setStatus(Mage_Newsletter_Model_Subscriber::STATUS_SUBSCRIBED);
                    $subscriber->save();


                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.'));
            }
        }
        $this->_redirectReferer();
    }

Let me know if works!!

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.