0

I have to hide the newsletter subscription form from customers who already subscribed.

For registered and loggedin customer i'm able to check the subscription status using the following method:

$customerSession = Mage::getSingleton("customer/session");
$email = $customerSession->getCustomer()->getEmail();
$subscriber = Mage::getModel('newsletter/subscriber')->loadByEmail($email);
    $status = $subscriber->isSubscribed(); // status = 1 if subscribed.

But I want to hide it for guest customers also (obviously for that particular session alone).

How could I do that? Can anyone help?

1

Your config.xml:

<config>
    <frontend>
        <events>
            <newsletter_subscriber_save_after>
                <observers>
                    <your_module_node>
                        <class>Your_Module_Model_Observer</class>
                        <method>newsletterSubscriberSaveAfter</method>
                    </your_module_node>
                </observers>
            </newsletter_subscriber_save_after>
        </events>
    </frontend>
    /*another config nodes*/
</config>

Your Observer.php:

public function newsletterSubscriberSaveAfter($observer)
{
    $subscription = $observer->getEvent()->getSubscriber();
    if ($subscription->subscriber_email) {
        Mage::getSingleton('customer/session')->setSubscribed(true);
    }
}

Template /app/design/frontend/base/default/template/newsletter/subscribe.phtml:

<?php if (!Mage::getSingleton('customer/session')->getSubscribed()): ?>
<!--here is original html -->
<?php endif; ?>
0

Override the subscriber controller Mage_Newsletter_SubscriberController and on the newAction() method, when the customer is subscribed just add a flag to the session.
Then, in the newsletter block template, just check if that session flag is set.

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.