Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento Newletter subscription - show error if already subscribed

Hi I am using default newsletters subscription package in magento. I need to show an error if the user is already registered with Us I've seen an option like this

    $emailExist = Mage::getModel('newsletter/subscriber')->load($email, 'subscriber_email');
    if ($emailExist->getId()) {
      Mage::throwException($this->__('This email address is already exist.'));
    }

from here Show error message in guest subscriber if user already subscribe with that Id

But this is not working for me, still i am getting same thanks for subscription message. thanks

like image 671
manipvd Avatar asked Nov 01 '22 00:11

manipvd


1 Answers

Check this............

$NewSellt= Mage::getModel('newsletter/subscriber')->subscribe($email);
if($NewSellt->getId()>0){
//if exits

}

If customer is registered user

$ownerId = Mage::getModel('customer/customer')
                        ->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
                        ->loadByEmail($email)
                        ->getId();
    if ($ownerId !== null && $ownerId != $customerSession->getId()) {
                   //'This email address is already assigned to another user.
                }
like image 62
Amit Bera Avatar answered Jan 04 '23 15:01

Amit Bera