if (typeof Virtuemart === "undefined") Virtuemart = {}; Virtuemart.stopSendtocart = false; Virtuemart.setproducttype = function(form, id) { form.view = null; var datas = form.serialize(); var runs= 0, maxruns = 20; var container = form; while(!container.hasClass('product-container') && !container.hasClass('productdetails') && !container.hasClass('vm-product-details-container') && runs<=maxruns){ container = container.parent(); runs++; } if(runs>maxruns){ console.log('setproducttype: Could not find parent container product-container nor product-field-display'); return false; } var prices = container.find(".product-price"); if (0 == prices.length) { prices = jQuery("#productPrice" + id); } datas = datas.replace("&view=cart", ""); prices.fadeTo("fast", 0.75); jQuery.ajax({ type: "POST", cache: false, dataType: "json", url: Virtuemart.vmSiteurl + "index.php?&option=com_virtuemart&view=productdetails&task=recalculate&format=json&nosef=1" + Virtuemart.vmLang, data: datas }).done( function (data, textStatus) { prices.fadeTo("fast", 1); // Remove previous messages generated by this AJAX call: jQuery( "#system-message-container #system-message div.vmprices-message").remove(); // refresh price for (var key in data) { var value = data[key]; // console.log('my datas',key,value); if ( key=='messages' ) { // Extract the messages from the returned string, add the vmprices-message class (so the next ajax call // can remove them again) and then move the messages to the original message container. // Things are complicated by the fact that no #system-message element exists if no messages were printed so far var newmessages = jQuery( data[key] ).find("div.alert").addClass("vmprices-message"); if (!jQuery( "#system-message-container #system-message").length && newmessages.length) { jQuery( "#system-message-container" ).append( "
" ); } newmessages.appendTo( "#system-message-container #system-message"); } else { // prices if (value!=0) prices.find("span.Price"+key).show().html(value); else prices.find(".Price"+key).html(0).hide(); } } } ); return false; // prevent reload } Virtuemart.productUpdate = function() { // This Event Gets Fired As Soon As The New Product // Was Added To The Cart // This Way Third Party Developer Can Include Their Own // Add To Cart Module And Listen To The Event: "updateVirtueMartCartModule" jQuery('body').trigger('updateVirtueMartCartModule'); } Virtuemart.eventsetproducttype = function (event){ Virtuemart.setproducttype(event.data.cart,event.data.virtuemart_product_id); } Virtuemart.sendtocart = function (form){ if (Virtuemart.addtocart_popup ==1) { Virtuemart.cartEffect(form) ; } else { form.append(''); form.submit(); } } Virtuemart.cartEffect = function(form) { var dat = form.serialize(); if(usefancy){ jQuery.fancybox.showActivity(); } jQuery.ajax({ type: "POST", cache: false, dataType: "json", timeout: "20000", url: Virtuemart.vmSiteurl + "index.php?option=com_virtuemart&nosef=1&view=cart&task=addJS&format=json"+Virtuemart.vmLang+window.Itemid, data: dat }).done( function(datas, textStatus) { if(datas.stat ==1){ var txt = datas.msg; } else if(datas.stat ==2){ var txt = datas.msg +"

"+form.find(".pname").val()+"

"; } else { var txt = "

"+vmCartError+"

"+datas.msg; } if(usefancy){ jQuery.fancybox({ "titlePosition" : "inside", "transitionIn" : "fade", "transitionOut" : "fade", "changeFade" : "fast", "type" : "html", "autoCenter" : true, "closeBtn" : false, "closeClick" : false, "content" : txt } ); } else { jQuery.facebox( txt , 'my-groovy-style'); } jQuery('body').trigger('updateVirtueMartCartModule'); }); } Virtuemart.incrQuantity = (function(event) { var rParent = jQuery(this).parent().parent(); quantity = rParent.find('input[name="quantity[]"]'); virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val(); Ste = parseFloat(quantity.attr("step")); if (isNaN(Ste)) Ste = 1; Qtt = parseFloat(quantity.val()); if (!isNaN(Qtt)) { var q = Qtt + Ste; console.log(q); q = q.toFixed(1); quantity.val(q); maxQtt = parseFloat(quantity.attr("max")); if(!isNaN(maxQtt) && quantity.val()>maxQtt){ quantity.val(maxQtt); } Virtuemart.setproducttype(event.data.cart,virtuemart_product_id); } }); Virtuemart.decrQuantity = (function(event) { var rParent = jQuery(this).parent().parent(); var quantity = rParent.find('input[name="quantity[]"]'); var virtuemart_product_id = rParent.find('input[name="virtuemart_product_id[]"]').val(); var Ste = parseFloat(quantity.attr("step")); if (isNaN(Ste)) Ste = 1; var minQtt = parseFloat(quantity.attr("init")); if (isNaN(minQtt)) minQtt = 1; var Qtt = parseFloat(quantity.val()); if (!isNaN(Qtt) && Qtt>Ste) { var q = (Qtt - Ste); q = q.toFixed(1); quantity.val(q); if(!isNaN(minQtt) && quantity.val()remainder){ obj.value = quantity-remainder; } else { obj.value = step; } return false; } return true; } jQuery.noConflict(); /*jQuery(document).ready(function($) { Virtuemart.product(jQuery("form.product")); /*$("form.js-recalculate").each(function(){ if ($(this).find(".product-fields").length && !$(this).find(".no-vm-bind").length) { var id= $(this).find('input[name="virtuemart_product_id[]"]').val(); Virtuemart.setproducttype($(this),id); } });*/ //});