$(document).ready(function(){ var useSwatch = false; var addPleaseSelect = true; var defaultMsg = ''; var warningMsg = ''; var ajaxAdd = ''; if (!defaultMsg) { defaultMsg = "Selecione..."; } if (!warningMsg) { warningMsg = "Selecione uma opção na listagem."; } if (!ajaxAdd) { ajaxAdd = 1; } // Add Please Select... to all product select boxes var $flag = false; if (addPleaseSelect) { $('#product select').each (function(n, select) { $(this).prepend(''); $(this).val(''); $(this).attr('id', 'opr_select_' +n); $flag = true; }); } // Hacky... Grab the add to cart onclick event and remove it if (ajaxAdd != 1 && $flag) { var atc = document.getElementById('add_to_cart'); var $atc_onclick = atc.getAttribute('onclick'); $('#add_to_cart').removeAttr('onclick'); } // Show warning if there are any unselected options var $okToAdd = false; $('#add_to_cart').click(function (event) { $('#product select :selected').each (function(i, select) { if (ajaxAdd == '1') { if ($(select).val() == '') { event.stopImmediatePropagation(); alert(warningMsg); return false; } } else { if ($(select).val() == '') { alert(warningMsg); $okToAdd = false; return false; } else { $okToAdd = true; } } }); if ($okToAdd == true) { eval($atc_onclick); } }); // If using swatch, and not using the please select, then default the swatch to the image of the current options if (useSwatch && !addPleaseSelect) { $('.opr_ajax_error').remove(); $('#product select option:selected').each(function(i, option) { var select_id = $(option).parent().attr('id'); // ajax lookup $.ajax({ type: 'post', url: 'index.php?route=product/options_plus_redux/updateImage', dataType: 'json', data: $('#product :input'), success: function (data) { // Update the main image with the new image. var swatch = data.swatch; var thumb = data.thumb; var popup = data.popup; var info = data.info; var stock = data.quantity; // Swap Image if exists... if (swatch && useSwatch) { // Remove existing image $('#option_image_'+select_id).parent().parent().remove(); $(option).parent().parent().after('
');
}
},
success: function (data) {
// Update the main image with the new image.
var swatch = data.swatch;
var thumb = data.thumb;
var popup = data.popup;
var info = data.info;
var stock = data.quantity;
var val_estoque = "Sem Estoque";
var t = "";
if (stock==0){
el = document.getElementById("estoque");
el.innerHTML = "Sem Estoque";
}else{
el = document.getElementById("estoque");
el.innerHTML = "Em Estoque";
}
el = document.getElementById("preco");
t=$(option).text().split("]");
var preco = t[1].replace("R$","").replace(".","").replace(",",".");
var v = preco;
el = document.getElementById("parc");
var p = "";
for(i=1;i<=10;i++){
if (i >=2 && i <=6){
v = parseFloat((preco * 0.125) + parseFloat(preco));
}
if (i >=7 && i <=10){
v = parseFloat((preco * 0.25) + parseFloat(preco));
}
parcela = v / i;
parcela = parseFloat(parcela).toFixed(2);
p = p + "