简体   繁体   English

magento通讯成功消息弹出

[英]magento newsletter success message popup

I want to create a pop up message box that showed after user subscribing the newsletter 我要创建一个弹出消息框,该框在用户订阅新闻通讯后显示

"your subscription have been confirmed [ok]" “您的订阅已被确认[确定]”

it must be in javascript or jquery cause i want to modifying it in magento front end area only 它必须在javascript或jquery中,因为我只想在magento前端区域中对其进行修改

it's similar like this post Magento newsletter succeess message in pop up but it's end up with no right answer and dead link 它类似于弹出Magento新闻通讯成功消息的消息,但最终没有正确答案和无效链接

another info :My Magento ver. 其他信息:我的Magento版本。 1.14.1.0 1.14.1.0

I have code a little bit and put it in the subscribe.phtml but it wont work 我有一些代码,并将其放在subscribe.phtml中,但它不起作用

<script type="text/javascript">
    var formdata = {'email': jQuery('input[name=email]').val()};
jQuery(document).ready(function() {

  jQuery('.btn-subs').click(function(){
    jQuery.ajax({
        method: "POST",
        url: "<?php echo Mage::getBaseUrl() ?>newsletter/subscriber/new/",
        data: formdata,
        datatype: 'json'
    })
    .success(function( data ) {
      alert( "Your Subscription has been confirmed" );
    })
    .error(function(data){
        alert(data);
        console.log(data);
    })
  });
});
</script>

Magento's builtin notification system is quite well-built and explained extensively by Inchoo here: http://inchoo.net/magento/magento-frontend/utilizing-magento-notification-system/ Magento的内置通知系统非常完善,Inchoo对此进行了详尽的解释: http ://inchoo.net/magento/magento-frontend/utilizing-magento-notification-system/

I'm kind of guessing that this is not exactly what you are looking for, since you state explicitly that it has to be done with javascript or with jquery. 我有点猜测这并不是您要查找的内容,因为您明确声明必须使用javascript或jquery完成。 Have you realised that it is possible for a magento controller action to basically stay on the same page but add a notification after subscribing someone to a newsletter page? 您是否意识到,magento控制器操作可能基本上停留在同一页面上,但在订阅某人到新闻稿页面后添加了通知?

This ( https://magento.stackexchange.com/questions/5063/reliable-way-to-redirect-to-last-page/5086 ) post helped me achieve to get a notification on a page with no redirect to a different page, just a reload of that same page. 这篇文章( https://magento.stackexchange.com/questions/5063/reliable-way-to-redirect-to-last-page/5086 )帮助我实现了在没有重定向到其他页面的页面上获得通知,只是重新加载了同一页面。

If you really insist on only using js/jquery, my instinct is that a simple alert would suffice. 如果您真的坚持只使用js / jquery,我的直觉是简单的警报就足够了。 This gives you by default only an 'ok' button, but i myself don't see the need for a 'cancel' button after an action has already been completed, unless this will undo the subscription to the newsletter i guess. 默认情况下,这仅给您一个“确定”按钮,但是我自己看不到在动作完成后需要“取消”按钮,除非我猜想这会撤消对新闻简报的订阅。

If this is not the case, could you give more information as to what you are trying to achieve and why it is important to use js/jquery only? 如果不是这种情况,您能否提供更多有关您要实现的目标以及仅使用js / jquery 为何重要的信息?

kind regards, 亲切的问候,

Tom 汤姆

You can post to the controller asynchronously (AJAX), but it will not give you anything meaningful to verify success with by default. 您可以异步发布到控制器(AJAX),但是默认情况下,它不会给您任何有意义的验证成功的信息。

What you would need to do is extend newsletter/subscriber/new (don't update the core file, any update will wipe your changes out.) 您需要做的是扩展新闻通讯/订阅者/新的(不要更新核心文件,任何更新都将清除您的更改。)

This could be helpful: http://inchoo.net/dev-talk/how-to-extend-magento-core-controller/ 这可能会有所帮助: http : //inchoo.net/dev-talk/how-to-extend-magento-core-controller/

Basically, what you want to do is create a new controller action, that does almost everything the existing controller does, but instead of redirecting when its done, it should echo data for your front-end to parse in the ajax response. 基本上,您想要做的是创建一个新的控制器动作,该动作将执行现有控制器几乎所有的工作,但是,完成后它应该回显数据,以便前端解析在ajax响应中,而不是进行重定向。 Also, you will want to remove the session success messages that are normally added. 另外,您将希望删除通常添加的会话成功消息。 (They'd show up on next page load.) (它们会在下一页加载时显示。)

So model your new controller after the existing one: 因此,在现有控制器的基础上为新控制器建模:

app/code/core/Mage/Newsletter/controllers/SubscriberController.php 应用程序/代码/核心/法师/新闻通讯/控制器/SubscriberController.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM