これまで私がこれまでに出てきた最高のものです。私はまだそれが部分的にしか解決されていないと考え、私はマゼンタのコミュニティからより多くの助けを得ることができると思うが、今は十分に機能する。
はcustom.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>
それから私は、WWWのルートディレクトリにフォルダのルートにcustomer_needs_to_see_this.phpを置きます。上記のスクリプトは自動的にdiv "ajax"をリフレッシュし、ajax-divの中にはPHPがありますroutes/user_needs_to_see_this.php
が含まれています。インクルード付きのdivはcart_sidebar.phtml
のように配置されています。私はmagentoのテンプレートファイルの外にファイルを置く必要がありました。../template/checkout/customer_needs_to_see_this.php
のようなものは含まれていませんでした。彼らはビュー(phtmlファイル)と同じフォルダにいるときの作業を含むが、それ以外の場合は動作しないようです。また、magentoのテンプレートファイルからuser_needs_to_see_this.php
を取得するスクリプトを取得できませんでした。
お客様がcustom.phtml
ページにアクセスすると、現在は3秒ごとに更新されます。私はその大丈夫だと思うのは、そのクッキーを読んで作るだけなので、何も重くないからです。私は将来それをonclickに変更するかもしれない。
コードhereがあります。
このような他の例もたくさんありますが、上記の例はほとんどのベースをカバーしているようです。
"リアルタイム"を "ajax"に変更しました。これは、あなたが思っていることだと思うからです。また、「jquery」タグを使用することを意味しますか? MagentoにはPrototypeが標準で同梱されていますが、テーマにはjQueryもあります。 – clockworkgeek
OKこれを部分的に解決しました。私は1週間以内にこれ以上の情報でこれを更新します。私はリアルタイムで更新するためのデータを取得しましたが、Magentoの構造はそれを少し難しくしました。 – kartaju