需要在magento中实时显示用户的选择


Need to display user's choices realtime in magento

我正在开发一个magento网上商店,其中有一个页面,客户可以选择他/她想要取订单的路线。选择是双重的,目前是两组不同的按钮,所以没有复选框或单选按钮。用户首先选择日期,然后选择地点。

现在我正在调用一个javascript函数,它在按钮按下加载cookie,然后重新加载页面,并将用户返回到一个锚链接,这样用户就不会在第一次选择时感到困惑。当页面重新加载时,侧边栏包含php,它读取cookie的内容。这感觉不是很直观,我相信有更好的方法来做到这一点。用户所做的选择应该显示在侧栏购物车上,这是一个. php文件。只是一个简单的"你已经选择了路径x"就足够了,现在我有一个回声,但页面必须先重新加载。

所以简而言之,当用户做出选择时,侧边栏应该更新有关选择的信息,而不是页面重新加载自己并在锚点链接的帮助下返回位置。通知最好位于左侧栏。我不认为我想使用弹出窗口或临时通知,但他们可以是一个额外的功能。

我很确定这是一个非常简单的问题,但由于某种原因,我似乎找不到合适的关键词,然后是magento本身。

好的,这是目前为止我想到的最好的一个。我仍然认为它只是部分解决了,我想我可以从magento社区得到更多的帮助,但现在它工作得很好。

将此脚本包含到自定义中。phtml标题:

<script type="text/javascript">
function AJAX(){
   try{
      xmlHttp=new XMLHttpRequest(); // Firefox, Opera 8.0+, Safari
      return xmlHttp;
   }
   catch (e){
      try{
         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); // Internet Explorer
         return xmlHttp;
      }
      catch (e){
         try{
            xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
            return xmlHttp;
         }
         catch (e){
            alert("Your browser does not support AJAX.");
            return false;
         }
      }
   }
}

// Timestamp for preventing IE caching the GET request (common function)
function fetch_unix_timestamp()
{
    return parseInt(new Date().getTime().toString().substring(0, 10))
}
// Reload div with php
function refreshdiv_timediv(){
   var seconds = '3';
   var divid = "ajax";
   var url = "routes/customer_needs_to_see_this.php";
   var xmlHttp_one = AJAX();
   // No cache
   var timestamp = fetch_unix_timestamp();
   var nocacheurl = url+"?t="+timestamp;

   // The code...
   xmlHttp_one.onreadystatechange=function(){
      if(xmlHttp_one.readyState==4){
         document.getElementById(divid).innerHTML=xmlHttp_one.responseText;
         setTimeout('refreshdiv_timediv()',seconds*1000);
      }
   }
   xmlHttp_one.open("GET",nocacheurl,true);
   xmlHttp_one.send(null);
}
// Start the refreshing process
window.onload = function startrefresh(){
   setTimeout('refreshdiv_timediv()',seconds*1000);
}
</script>

然后我把customer_needs_to_see_this.php文件夹路由在www根目录。上面的脚本将自动刷新div "ajax",并且在ajax-div中有一个php include routes/user_needs_to_see_this.php。包含include的div位于cart_sidebar.phtml

我不得不把文件放在magento的模板文件之外,因为我不能做包括像../template/checkout/customer_needs_to_see_this.php。包括工作时,他们在同一文件夹的视图(php -file)文件,但否则它似乎不工作。此外,我无法让脚本从magento的模板文件中获取user_needs_to_see_this.php

现在,当客户在custom.phtml页面时,它每3秒更新一次。我认为这还好,因为它只是阅读和做饼干,所以不是什么沉重的事情。我以后可能会把它改成onclick。

我在这里得到了代码。

还有很多类似的例子,但上面的例子似乎涵盖了大多数基础。