var siteurl = 'https://zarabi-group.com/index.php';var wait=""; var para=""; var delall =""; var frmcheckout = false; var loadcomplete = false; $(document).ready(function () { loadcomplete = true; StoreRequest('mo=showcart','1stshowcart'); }); function StoreRequest(url,p,postform,sendrequest = 0) { if(loadcomplete){ _StoreRequest(url,p,postform,sendrequest); }else{ //dialogStore("prompt", "dialogWait"); } } function _StoreRequest(requesturl, para, postform = false, sendrequest = 0,reloadAfterSuccess = false) { if(postform){postpara = createQuery(postform);}else{postpara="";} if(para!="1stshowcart"){ wait = true; // dialogStore("WaitModal", "dialogWait"); }else{ wait = false; para= "showcart"; } $.ajax({ type: "POST", url: siteurl + "?store_ajax=true&" + requesturl, data: postpara, success: function(response){ loadcomplete = true; if(sendrequest){StoreRequest('mo=showcart','1stshowcart');} if(reloadAfterSuccess){ window.location.reload(); } alertContents(response,para); return true; }, error: function(){ // dialogStore("prompt", "dialogError"); alert('عملیات با شکست مواجه شد, دوباره تلاش کنید'); return false; } }) .done(function(res){ console.log(res); // basket_option(); // $(".loading").delay(500).fadeOut(200); // var scrollHeight = document.querySelector('.basket_content').scrollHeight; // $('.basket_content').scrollTop(scrollHeight); }); } function alertContents(response,para){ if(wait==true){ // dialogStore("close", "dialogWait"); wait = false; } if (para=="showcart"){ cart_scroll(); $('#butshowcart').hide(); $('#div'+para).html(response); if($('#divnewbody').css("display")=="block"){ StoreRequest("mo=checkout","checkout"); } }else if(para=="addcart") { $('.popupWrapper').slideDown(); // for ravaknegar //dialogStore("prompt", response); }else if(para=="delcart") { // dialogStore("prompt", response); }else if(para=="checkout") { $('#divbody').hide(); $('#divnewbody').show(); $('#divnewbody').html(response); }else if(para=="submitcheckout") { if(response=="dialogError"){ // dialogStore("prompt", response); $('#divbody').show(); $('#divnewbody').hide(); }else{ $('#divnewbody').html(response); StoreRequest('mo=showcart','submitcheckoutok'); } }else if(para=="submitcheckoutcard") { if(response=="dialogError"){ // dialogStore("prompt", response); $('#divbody').show(); $('#divnewbody').hide(); }else{ if(response.substring(0,8) == '//script'){ eval(response); }else{ $('#divnewbody').html(response); } } }else if(para=="submitcheckoutok") { $('#butshowcart').hide(); $('#divshowcart').html(response); }else if(para=="") { $('#divnewbody').show(); $('#divnewbody').html(response); } if((para=="addcart" || para=="delcart") && !wait){ StoreRequest("mo=showcart","showcart"); } } // function dialogStore(type, divid){ // //if($.browser.msie){ // // $("body").css("overflow-x", "hidden"); // // $("body").css("overflow-y", "scroll"); // //} // var w = $('#'+divid).attr("width"); // var h = $('#'+divid).attr("height"); // if(!w){w='300';} // if(!h){h='150';} // if(type=="close"){ // $('#'+divid).dialog("close"); // }else if(type=="WaitModal"){ // $('#'+divid).dialog({modal: true,closeOnEscape: false, width: w, height: h,autoOpen: false}); // return false; // }else if(type=="prompt"){ // $('#'+divid).dialog({modal: true, width: w, height: h, buttons: { "OK": function() { $(this).dialog("close"); } }}); // return false; // } // } function StoreDelete(divid,pid){ //if($.browser.msie){ // $("body").css("overflow-x", "hidden"); // $("body").css("overflow-y", "scroll"); //} if(confirm('محصول از سبد خرید حذف شود ؟')){ // $(".loading").fadeIn(400); _StoreRequest('mo=delcart&pid=' + pid,'delcart',frmcheckout,1); // $(thisProduct).slideUp(400); // var thisProduct = $('.'+pid); } // var re = false; // var w = $('#'+divid).attr("width"); // var h = $('#'+divid).attr("height"); // if(!w){w='300';} // if(!h){h='150';} // $('#'+divid).dialog({ // resizable: false, // width:w, // height:h, // modal: true, // buttons: { // "Delete": function() { // $(this).dialog( "close" ); // }, // Cancel: function() { // $(this).dialog( "close" ); // } // } // }); } function createQuery(form){ var elements = form.elements; var pairs = new Array(); for (var i = 0; i < elements.length; i++) { if ((name = elements[i].name) && (value = elements[i].value)) pairs.push(name + "=" + encodeURIComponent(value)); } return pairs.join("&"); } function cart_scroll(){ var e = $('#cart_scroll'); if(e.length!=1) e = $('#cart_sidebar_scroll'); //$('body,html').animate({ scrollTop: 0 }, 500 ); // for ravaknegar }