$(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(''+alt+''); tb_init('.thickbox_option'); } }, error: function (html) { // Create an error element that gets shown only on error, removed on success $('body').append('Ajax Lookup Error. Tente novamente.'); }, complete: function() { $('.optplus_loading').remove(); } }); var swatch = $(option).attr('swatch'); var popup = $(option).attr('popup'); var title = $(option).attr('title'); var alt = $(option).attr('alt'); if (swatch) { $(option).parent().parent().after(''+alt+''); } // Add under main image if (info) { $('#image').parent().after('

'); } }); tb_init('.thickbox_option'); } // Store original image source var origSrc = $('#image').attr('src'); var origTitle = $('#image').attr('title'); var origAlt = $('#image').attr('alt'); var origPopup = $('#image').parent().attr('href'); // Bind select change to image swap $('#product select').bind('change', function() { // Set variables... var $this = $(this); var select_id = $(this).attr('id'); var select_name = $(this).attr('name'); var option = $(this).find("option:selected"); var swatch = $(option).attr('swatch'); var thumb = $(option).attr('thumb'); var popup = $(option).attr('popup'); var title = $(option).attr('title'); var alt = $(option).attr('alt'); // Remove existing option info $('#option_info').remove(); $('.opr_ajax_error').remove(); if ($(option).val()) { // ajax lookup $.ajax({ type: 'post', url: 'index.php?route=product/options_plus_redux/updateImage', dataType: 'json', //data: $('#product :input'), data: $('#product :input').serialize() +'&option_value_id='+$(option).val(), beforeSend: function() { if (!useSwatch) { $this.after(''+alt+''); } }, 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 + "
" + i + "x de R$ " + parcela; } //el.innerHTML = p; // Swap Image if exists... if (swatch && useSwatch) { // Remove existing image $('#option_image_'+select_id).parent().parent().remove(); $(option).parent().parent().after(''+alt+''); tb_init('.thickbox_option'); } else if (thumb) { $('#image').attr('src', thumb); $('#image').attr('title', title); $('#image').attr('alt', alt); $('#image').parent().attr('href', popup); } // Add under main image if (info) { $('#image').parent().after('

'); } }, error: function (html) { // Create an error element that gets shown only on error, removed on success $('body').append('Ajax Lookup Error. Tente novamente.'); }, complete: function() { $('.optplus_loading').remove(); } }); } else { $('#image').attr('src', origSrc); $('#image').attr('title', origTitle); $('#image').attr('title', origAlt); $('#image').parent().attr('href', origPopup); } }); });