0

How to override the subscribe.phtml form which is in vendor / magento / module-newsletter to add my input data and save it in my database table ?

3
  • what you have tried so far?
    – Amit Bera
    Aug 2, 2019 at 9:12
  • Are you talking about subscribe.html or subscribe.phtml
    – Amit Bera
    Aug 2, 2019 at 9:15
  • Do you want a new field in the newsletter subscription? Aug 3, 2019 at 0:09

2 Answers 2

0

If you have to override newsletter in theme than you have to add subscribe.phtml file in

design/frontend/themename/theme/Module_Newsletter/templates/subscribe.phtml

Than you have to add below code in your footer block or call phtml in your footer.phtml file

{{block class="Magento\Newsletter\Block\Subscribe" name="static.newsletter" template="Magento_Newsletter::subscribe.phtml"}}

just do it and newsletter works properly

0

Hey @Pavel Ivatsko you can save your data using event and observe

event.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="newsletter_subscriber_save_before">
        <observer name="newsletter_subscriber_save_before" instance="vendor-name\module-name\Observer\newsletterSubscriberSave" />
    </event>
</config>

newsletterSubscriberSave.php

use \Magento\Framework\Event\Observer;
use \Magento\Framework\Event\ObserverInterface;
class newsletterSubscriberSave implements ObserverInterface
{
    protected $_request;

    public function __construct(
        \Magento\Framework\App\RequestInterface $request
    ) {
        $this->_request = $request;
    }

    public function execute(Observer $observer)
    {
        $subscriber = $observer->getEvent()->getSubscriber();
        $params = $this->_request->getParams();

        if(isset($params['subscriber_name'])) {
            $name = $params['subscriber_name'];
            $subscriber->setSubscriberName($name);
        }

        return $this;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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