landofcoder/module-newsletter-ajax

此包已被废弃,不再维护。未建议替代包。

此模块支持AJAX新闻订阅。

安装: 0

依赖项: 0

建议者: 0

安全: 0

星标: 2

关注者: 2

分支: 1

开放问题: 0

类型:magento2-module

dev-master 2020-05-21 08:38 UTC

This package is auto-updated.

Last update: 2023-12-16 21:18:35 UTC


README

Magento 2 Newsletter Ajax 允许您的客户在不刷新页面的情况下订阅新闻通讯。它还向希望进行自定义订阅流程的开发者返回JSON数据。

如何安装

下载到项目根目录下的 app/code/Lof/NewsletterAjax 目录。

在项目根目录下运行以下命令

开发者模式

php bin/magento module:enable Lof_NewsletterAjax
php bin/magento setup:upgrade

生产模式

php bin/magento module:enable Lof_NewsletterAjax
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy

如何使用

通过安装此模块,您现在可以向后端新闻订阅端点 https://yourdomain.com/newsletter/subscriber/new 发起AJAX请求,并获得包含 statusmessage 的JSON响应。这不会干扰当前的新闻订阅表单,因为模块会检查HTTP请求头并基于该值生成响应。这确保了与核心Magento 2功能和其他扩展新闻订阅的模块的兼容性。

如果您想在前端运行自定义流程,可以将此片段用作起点。

<script>
    require([
        'jquery'
    ], function ($) {
        $(function () {
            let subscribeForm = $('.form.subscribe');

            $(subscribeForm).on('submit', function(e) {
                e.preventDefault();
                let email = $('#newsletter').val();

                if ($(subscribeForm).valid()) {
                    $.ajax({
                        url: 'newsletter/subscriber/new/',
                        type: 'POST',
                        data: {
                            'email' : email
                        },
                        dataType: 'json',
                        showLoader: true,
                        complete: function(data, status) {
                            let response = JSON.parse(data.responseText);
                            // Run your custom process using the response data
                        }
                    });
                }
            });
        });
    });
</script>

用户指南

登录到您的Magento 2管理后台,从侧边栏选择“商店”。在“设置”下选择“配置”。从这里您可以从侧边栏选择“Landofcoder”并查看新闻订阅AJAX选项。启用此选项将覆盖页脚中的默认新闻订阅输入,并改为使用AJAX进行后台请求,并将显示结果模态框。