我已經修改了Magento處理類別的方式,以允許用戶通過鏈接將添加到購物車的ajax請求鏈接在一起從類別頁一次添加多個可配置產品網址。鏈接Ajax請求基於jQuery結果。每個只發送之前發送一次
基本上,用戶選擇一個複選框,他們想要添加的項目,這給出<li>
該產品是在一個'積極'類。這個jQuery抓住每個有活躍類的<li>
,然後從變量theLink中選定的下拉列表中抓取'add to cart URL'。
$j('li.active').each(function(){
var theLink = $j(this).find('.shopthislookpageselect').val();
var successString = "was added to your shopping cart."
$j.ajax({
beforeSend: function(){$j('#modalBackground').show();},
type:"POST",
url: theLink,
success: function(data){
var returnPage = data;
var exists = (returnPage.indexOf(successString) !== -1);
if (exists) {$j('.col-main').prepend('<ul class="messages"><li class="success-msg"><ul><li><span>The items selected were added to your shopping cart. View your cart <a href="https://www.culturekings.com.au/checkout/cart/">HERE</a></span></li></ul></li></ul>'); $j("html, body").animate({ scrollTop: 0 }, "slow"); }
else {alert ('There was a problem adding these products to your cart. \n Please select the View Full Product Info link to add these items individually.')}
},
error: function(){alert('There was a problem adding these products to your cart. \n Please select the View Full Product Info link to add these items individually.');},
complete: function(){$j('#modalBackground').fadeOut(200);}
});
});
在div modalBackground
是具有加載GIF這是應該在每個AJAX調用的開始顯示,並隱藏在端部具有透明的全寬度和高度覆蓋。
問題是modalBackground顯示在第一個ajax調用的開始處並隱藏在結尾處,但之後它不再顯示任何其他調用。我可以看到這個函數仍在運行,因爲我可以計算成功函數每次成功調用結束時顯示的成功消息。
以前是否只發一次?如果是這樣,爲什或者我應該爲疊加處理方式做出不同的處理。
請注意,如果Magneto添加到購物車控制器中沒有改變大的東西,它將無法處理一次添加所有產品,所以我被困在做這些多個Ajax請求。
這是偉大的,完美的作品。很明顯,我必須添加var theLink = ...和var successString = ...位,其中//所有其他內容都已被註釋,並且它可以直接從蝙蝠中運行!不錯的工作! – James
非常感謝。工作得很好 – Rippo