0

I have extend a module for subscription newsletter in magento 2 for change in NewAction.php file. After enabling the Module it doesn't work As, i want to remove newsletter popup on subscription success.

My di.xml file is

<?xml version="1.0"?>

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
<preference for="Magento\Newsletter\Controller\Subscriber" type="News\Newslettermodule\Controller\Subscriber" />
</config>

My module.xml file is

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
<module name="News_Newslettermodule" setup_version="0.0.1" />
</config>

but it didn't work for me.

2
  • Are you sure your module is successfully installed? – Agnes Feb 5 '20 at 10:53
  • Yes it give me success message like The following modules have been enabled: – Prits Feb 5 '20 at 10:55
0

Do you mean You want to close modal popup on success? I will show my popup's JS, hope part of it will help you

define([
    'jquery',
    'Magento_Ui/js/modal/modal',
    'mage/cookies'
], function ($, modal) {
    'use strict';

    $.widget('devall.popupManager', {
        /**
         * creating popup
         */
        _create: function () {
            var self = this,
                popupOptions = {
                    responsive: true,
                    title: this.options.popupTitle,
                    buttons: false,
                    modalClass: 'popup-devnewsletter',
                    autoOpen: true,

                    /**
                     * setting a cookie
                     */
                    closed: function () {
                        self._setCookie();
                    }
                },
                contentOptions = {
                    success: this.options.successContent
                };

            if (!$.cookie('popup_cookie')) {

                if (this.options.popupEvent === 'Exit') {
                    $(document).mouseleave(function (e) {
                        e.preventDefault();
                        e.stopPropagation();
                        $(document).off('mouseleave');
                        modal(popupOptions, $('#popup-devnewsletter'));
                    });
                } else {
                    setTimeout(function () {
                        modal(popupOptions, $('#popup-devnewsletter'));
                    }, this.options.popupDelay * 1000);
                }
            }
            this.element.find('form').submit(function (e) {
                e.preventDefault();

                if ($(this).validation('isValid')) {
                    $.ajax({
                        url: $(this).attr('action'),
                        data: $(this).serialize(),
                        dataType: 'html',
                        type: 'POST',
                        showLoader: true,

                        /**
                         * Success function
                         */
                        success: function () {
                            $('#form-div-element').remove();
                            $('#devnewsletter-validate-detail').html(contentOptions.success);
                        }
                    });
                }
            });
        },

        /**
         * cookie function
         */
        _setCookie: function () {
            var expDate = new Date();

            expDate.setTime(expDate.getTime() + 1000 * 60 * 60 * 24 * 21);
            $.cookie('popup_cookie', 1, {
                expires: expDate
            });
        }
    });

    return $.devall.popupManager;
});

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.