From ac3ddba858ce45ad6f029c6e37d13673e3427703 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 16 Nov 2011 15:25:45 +0000 Subject: [PATCH] Country defaults to store base. State field defaults to 'please select state' - not alabama for US. Closes #200. --- assets/js/woocommerce.min.js | 583 ++++++++++++++++++++++++++++++++++- classes/cart.class.php | 2 - classes/checkout.class.php | 12 + classes/order.class.php | 12 +- readme.txt | 3 + 5 files changed, 607 insertions(+), 5 deletions(-) diff --git a/assets/js/woocommerce.min.js b/assets/js/woocommerce.min.js index 4ba70dcfa8c..c4a57bf1b5b 100644 --- a/assets/js/woocommerce.min.js +++ b/assets/js/woocommerce.min.js @@ -1 +1,582 @@ -jQuery(document).ready(function(f){if(woocommerce_params.option_ajax_add_to_cart=="yes"){f(".add_to_cart_button").live("click",function(){var n=f(this);if(n.is(".product_type_simple, .product_type_downloadable, .product_type_virtual")){f(n).addClass("loading");var o={action:"woocommerce_add_to_cart",product_id:f(n).attr("rel"),security:woocommerce_params.add_to_cart_nonce};f("body").trigger("adding_to_cart");f.post(woocommerce_params.ajax_url,o,function(p){f(n).removeClass("loading");o=f.parseJSON(p);if(o.error){alert(o.error);return}fragments=o;if(fragments){f.each(fragments,function(q,r){f(q).addClass("updating")})}f(".widget_shopping_cart, .shop_table.cart, .updating, .cart_totals").fadeTo("400","0.6").block({message:null,overlayCSS:{background:"transparent url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});f(n).addClass("added");if(f(".widget_shopping_cart").size()>0){f(".widget_shopping_cart:eq(0)").load(window.location+" .widget_shopping_cart:eq(0) > *",function(){if(fragments){f.each(fragments,function(q,r){f(q).replaceWith(r)})}f(".widget_shopping_cart, .updating").css("opacity","1").unblock()})}else{if(fragments){f.each(fragments,function(q,r){f(q).replaceWith(r)})}f(".widget_shopping_cart, .updating").css("opacity","1").unblock()}f(".shop_table.cart").load(window.location+" .shop_table.cart:eq(0) > *",function(){f("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('').prepend('');f(".shop_table.cart").css("opacity","1").unblock()});f(".cart_totals").load(window.location+" .cart_totals:eq(0) > *",function(){f(".cart_totals").css("opacity","1").unblock()});f("body").trigger("added_to_cart")});return false}else{return true}})}f("select.orderby").change(function(){f(this).closest("form").submit()});f("#rating").hide().before('

12345

');f("p.stars a").click(function(){var n=f(this);f("#rating").val(n.text());f("p.stars a").removeClass("active");n.addClass("active");return false});var i=f(".price_slider_amount #min_price").val();var d=f(".price_slider_amount #max_price").val();current_min_price=parseInt(i);current_max_price=parseInt(d);if(woocommerce_params.min_price){current_min_price=parseInt(woocommerce_params.min_price)}if(woocommerce_params.max_price){current_max_price=parseInt(woocommerce_params.max_price)}f(".price_slider").slider({range:true,animate:true,min:i,max:d,values:[current_min_price,current_max_price],create:function(n,o){if(woocommerce_params.currency_pos=="left"){f(".price_slider_amount span").html(woocommerce_params.currency_symbol+current_min_price+" - "+woocommerce_params.currency_symbol+current_max_price)}else{if(woocommerce_params.currency_pos=="left_space"){f(".price_slider_amount span").html(woocommerce_params.currency_symbol+" "+current_min_price+" - "+woocommerce_params.currency_symbol+" "+current_max_price)}else{if(woocommerce_params.currency_pos=="right"){f(".price_slider_amount span").html(current_min_price+woocommerce_params.currency_symbol+" - "+current_max_price+woocommerce_params.currency_symbol)}else{if(woocommerce_params.currency_pos=="right_space"){f(".price_slider_amount span").html(current_min_price+" "+woocommerce_params.currency_symbol+" - "+current_max_price+" "+woocommerce_params.currency_symbol)}}}}f(".price_slider_amount #min_price").val(current_min_price);f(".price_slider_amount #max_price").val(current_max_price)},slide:function(n,o){if(woocommerce_params.currency_pos=="left"){f(".price_slider_amount span").html(woocommerce_params.currency_symbol+o.values[0]+" - "+woocommerce_params.currency_symbol+o.values[1])}else{if(woocommerce_params.currency_pos=="left_space"){f(".price_slider_amount span").html(woocommerce_params.currency_symbol+" "+o.values[0]+" - "+woocommerce_params.currency_symbol+" "+o.values[1])}else{if(woocommerce_params.currency_pos=="right"){f(".price_slider_amount span").html(o.values[0]+woocommerce_params.currency_symbol+" - "+o.values[1]+woocommerce_params.currency_symbol)}else{if(woocommerce_params.currency_pos=="right_space"){f(".price_slider_amount span").html(o.values[0]+" "+woocommerce_params.currency_symbol+" - "+o.values[1]+" "+woocommerce_params.currency_symbol)}}}}f("input#min_price").val(o.values[0]);f("input#max_price").val(o.values[1])}});f("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass("buttons_added").append('').prepend('');f(".plus").live("click",function(){var n=parseInt(f(this).prev(".qty").val());if(!n||n==""||n=="NaN"){n=0}f(this).prev(".qty").val(n+1)});f(".minus").live("click",function(){var n=parseInt(f(this).next(".qty").val());if(!n||n==""||n=="NaN"){n=1}if(n>0){f(this).next(".qty").val(n-1)}});var b=woocommerce_params.countries.replace(/"/g,'"');var k=f.parseJSON(b);f("select.country_to_state").change(function(){var t=f(this).val();var q=f("#"+f(this).attr("rel"));var u=f(q).attr("name");var p=f(q).attr("id");var s=f(q).val();if(k[t]){var o="";var r=k[t];for(var n in r){o=o+'"}if(f(q).is("input")){f(q).replaceWith('");q=f("#"+f(this).attr("rel"))}f(q).html(o);f(q).val(s)}else{if(f(q).is("select")){f(q).replaceWith('');q=f("#"+f(this).attr("rel"))}}}).change();f("div.woocommerce_tabs .panel").hide();f("div.woocommerce_tabs ul.tabs li a").click(function(){var n=f(this);var o=n.closest("div.woocommerce_tabs");f("ul.tabs li",o).removeClass("active");f("div.panel",o).hide();f("div"+n.attr("href")).show();n.parent().addClass("active");return false});f("div.woocommerce_tabs").each(function(){var n=window.location.hash;if(n.toLowerCase().indexOf("comment-")>=0){f("ul.tabs li.reviews_tab a",f(this)).click()}else{f("ul.tabs li:first a",f(this)).click()}});f(".shipping-calculator-form").hide();f(".shipping-calculator-button").click(function(){f(".shipping-calculator-form").slideToggle("slow");return false});function a(r,q){var n=true;for(name in r){var p=r[name];var o=q[name];if(p.length!=0&&o.length!=0&&p!=o){n=false}}return n}function m(p){var r=[];for(var o=0;o1){f(n).attr("src",q);f(t).attr("href",o)}else{f(n).attr("src",s);f(t).attr("href",r)}f(".single_variation_wrap").slideDown("200")}function c(o){var n=true;var q={};f(".variations select").each(function(){if(o&&f(this).attr("name")==o){n=false;q[f(this).attr("name")]=""}else{if(f(this).val().length==0){n=false}value=f(this).val();value=value.replace('"',""");q[f(this).attr("name")]=value}});var r=m(q);if(n){var p=r.pop();if(p){f("form input[name=variation_id]").val(p.variation_id);g(p)}else{f(".variations select").val("")}}else{h(r)}}f(".variations select").change(function(){f("form input[name=variation_id]").val("");f(".single_variation_wrap").hide();f(".single_variation").text("");c();f(this).blur();if(f().uniform&&f.isFunction(f.uniform.update)){f.uniform.update()}}).focus(function(){c(f(this).attr("name"))}).change();if(woocommerce_params.is_cart==1){f("select#shipping_method").live("change",function(){var o=f("#shipping_method").val();f("div.cart_totals").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});var n={action:"woocommerce_update_shipping_method",security:woocommerce_params.update_shipping_method_nonce,shipping_method:o};f.post(woocommerce_params.ajax_url,n,function(p){f("div.cart_totals").replaceWith(p)})})}if(woocommerce_params.is_checkout==1||woocommerce_params.is_pay_page==1){var l;var j;function e(){if(j){j.abort()}var u=f("#shipping_method").val();var t=f("#billing_country").val();var r=f("#billing_state").val();var n=f("input#billing_postcode").val();if(f("#shiptobilling input").is(":checked")||f("#shiptobilling input").size()==0){var o=f("#billing_country").val();var q=f("#billing_state").val();var s=f("input#billing_postcode").val()}else{var o=f("#shipping_country").val();var q=f("#shipping_state").val();var s=f("input#shipping_postcode").val()}f("#order_methods, #order_review").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});var p={action:"woocommerce_update_order_review",security:woocommerce_params.update_order_review_nonce,shipping_method:u,country:t,state:r,postcode:n,s_country:o,s_state:q,s_postcode:s,post_data:f("form.checkout").serialize()};j=f.ajax({type:"POST",url:woocommerce_params.ajax_url,data:p,success:function(v){f("#order_methods, #order_review").remove();f("#order_review_heading").after(v);f("#order_review input[name=payment_method]:checked").click()}})}f(function(){f("p.password").hide();f("input.show_password").change(function(){f("p.password").slideToggle()});f("div.shipping_address").hide();f("#shiptobilling input").change(function(){f("div.shipping_address").hide();if(!f(this).is(":checked")){f("div.shipping_address").slideDown()}}).change();if(woocommerce_params.option_guest_checkout=="yes"){f("div.create-account").hide();f("input#createaccount").change(function(){f("div.create-account").hide();if(f(this).is(":checked")){f("div.create-account").slideDown()}}).change()}f(".payment_methods input.input-radio").live("click",function(){f("div.payment_box").hide();if(f(this).is(":checked")){f("div.payment_box."+f(this).attr("ID")).slideDown()}});f("#order_review input[name=payment_method]:checked").click();f("form.login").hide();f("a.showlogin").click(function(){f("form.login").slideToggle();return false});f("#shipping_method").live("change",function(){clearTimeout(l);e()});f("input#billing_country, input#billing_state, #billing_postcode, input#shipping_country, input#shipping_state, #shipping_postcode").live("keydown",function(){clearTimeout(l);l=setTimeout("update_checkout()","1000")});f("select#billing_country, select#billing_state, select#shipping_country, select#shipping_state, #shiptobilling input, .update_totals_on_change").live("change",function(){clearTimeout(l);e()});if(woocommerce_params.is_checkout==1){e()}f("form.checkout").submit(function(){var n=this;if(f(n).is(".processing")){return false}f(n).addClass("processing").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});f.ajax({type:"POST",url:woocommerce_params.checkout_url,data:f(n).serialize(),success:function(p){f(".woocommerce_error, .woocommerce_message").remove();try{success=f.parseJSON(p);window.location=decodeURI(success.redirect)}catch(o){f(n).prepend(p);f(n).removeClass("processing").unblock();f("html, body").animate({scrollTop:(f("form.checkout").offset().top-100)},1000)}},dataType:"html"});return false})})}}); \ No newline at end of file +jQuery(document).ready(function($) { + + if (woocommerce_params.option_ajax_add_to_cart=='yes') { + + // Ajax add to cart + $('.add_to_cart_button').live('click', function() { + + // AJAX add to cart request + var thisbutton = $(this); + + if (thisbutton.is('.product_type_simple, .product_type_downloadable, .product_type_virtual')) { + + $(thisbutton).addClass('loading'); + + var data = { + action: 'woocommerce_add_to_cart', + product_id: $(thisbutton).attr('rel'), + security: woocommerce_params.add_to_cart_nonce + }; + + // Trigger event + $('body').trigger('adding_to_cart'); + + // Ajax action + $.post( woocommerce_params.ajax_url, data, function(response) { + + $(thisbutton).removeClass('loading'); + + // Get response + data = $.parseJSON( response ); + + if (data.error) { + alert(data.error); + return; + } + + fragments = data; + + // Block fragments class + if (fragments) { + $.each(fragments, function(key, value) { + $(key).addClass('updating'); + }); + } + + // Block widgets and fragments + $('.widget_shopping_cart, .shop_table.cart, .updating, .cart_totals').fadeTo('400', '0.6').block({message: null, overlayCSS: {background: 'transparent url(' + woocommerce_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}}); + + // Changes button classes + $(thisbutton).addClass('added'); + + // Cart widget load + if ($('.widget_shopping_cart').size()>0) { + $('.widget_shopping_cart:eq(0)').load( window.location + ' .widget_shopping_cart:eq(0) > *', function() { + + // Replace fragments + if (fragments) { + $.each(fragments, function(key, value) { + $(key).replaceWith(value); + }); + } + + // Unblock + $('.widget_shopping_cart, .updating').css('opacity', '1').unblock(); + } ); + } else { + // Replace fragments + if (fragments) { + $.each(fragments, function(key, value) { + $(key).replaceWith(value); + }); + } + + // Unblock + $('.widget_shopping_cart, .updating').css('opacity', '1').unblock(); + } + + // Cart page elements + $('.shop_table.cart').load( window.location + ' .shop_table.cart:eq(0) > *', function() { + + $("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass('buttons_added').append('').prepend(''); + + $('.shop_table.cart').css('opacity', '1').unblock(); + + }); + + $('.cart_totals').load( window.location + ' .cart_totals:eq(0) > *', function() { + $('.cart_totals').css('opacity', '1').unblock(); + }); + + // Trigger event so themes can refresh other areas + $('body').trigger('added_to_cart'); + + }); + + return false; + + } else { + return true; + } + + }); + + } + + // Orderby + $('select.orderby').change(function(){ + $(this).closest('form').submit(); + }); + + // Star ratings + $('#rating').hide().before('

12345

'); + + $('p.stars a').click(function(){ + var star = $(this); + $('#rating').val( star.text() ); + $('p.stars a').removeClass('active'); + star.addClass('active'); + return false; + }); + + // Price slider + var min_price = $('.price_slider_amount #min_price').val(); + var max_price = $('.price_slider_amount #max_price').val(); + + current_min_price = parseInt(min_price); + current_max_price = parseInt(max_price); + + if (woocommerce_params.min_price) current_min_price = parseInt(woocommerce_params.min_price); + if (woocommerce_params.max_price) current_max_price = parseInt(woocommerce_params.max_price); + + $('.price_slider').slider({ + range: true, + animate: true, + min: min_price, + max: max_price, + values: [current_min_price,current_max_price], + create : function( event, ui ) { + + if (woocommerce_params.currency_pos == "left"){ + $( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + current_min_price + " - " + woocommerce_params.currency_symbol + current_max_price ); + } else if (woocommerce_params.currency_pos == "left_space") { + $( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + " " + current_min_price + " - " + woocommerce_params.currency_symbol + " " + current_max_price ); + } else if (woocommerce_params.currency_pos == "right") { + $( ".price_slider_amount span" ).html( current_min_price + woocommerce_params.currency_symbol + " - " + current_max_price + woocommerce_params.currency_symbol ); + } else if (woocommerce_params.currency_pos == "right_space") { + $( ".price_slider_amount span" ).html( current_min_price + " " + woocommerce_params.currency_symbol + " - " + current_max_price + " " + woocommerce_params.currency_symbol ); + } + + $( ".price_slider_amount #min_price" ).val(current_min_price); + $( ".price_slider_amount #max_price" ).val(current_max_price); + }, + slide: function( event, ui ) { + + if (woocommerce_params.currency_pos == "left"){ + $( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + ui.values[ 0 ] + " - " + woocommerce_params.currency_symbol + ui.values[ 1 ] ); + } else if (woocommerce_params.currency_pos == "left_space") { + $( ".price_slider_amount span" ).html( woocommerce_params.currency_symbol + " " + ui.values[ 0 ] + " - " + woocommerce_params.currency_symbol + " " + ui.values[ 1 ] ); + } else if (woocommerce_params.currency_pos == "right") { + $( ".price_slider_amount span" ).html( ui.values[ 0 ] + woocommerce_params.currency_symbol + " - " + ui.values[ 1 ] + woocommerce_params.currency_symbol ); + } else if (woocommerce_params.currency_pos == "right_space") { + $( ".price_slider_amount span" ).html( ui.values[ 0 ] + " " + woocommerce_params.currency_symbol + " - " + ui.values[ 1 ] + " " + woocommerce_params.currency_symbol ); + } + $( "input#min_price" ).val(ui.values[ 0 ]); + $( "input#max_price" ).val(ui.values[ 1 ]); + } + }); + + // Quantity buttons + $("div.quantity:not(.buttons_added), td.quantity:not(.buttons_added)").addClass('buttons_added').append('').prepend(''); + + $(".plus").live('click', function() { + var currentVal = parseInt($(this).prev(".qty").val()); + if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 0; + $(this).prev(".qty").val(currentVal + 1); + }); + + $(".minus").live('click', function() { + var currentVal = parseInt($(this).next(".qty").val()); + if (!currentVal || currentVal=="" || currentVal == "NaN") currentVal = 1; + if (currentVal > 0) $(this).next(".qty").val(currentVal - 1); + }); + + /* states */ + var states_json = woocommerce_params.countries.replace(/"/g, '"'); + var states = $.parseJSON( states_json ); + + $('select.country_to_state').change(function(){ + + var country = $(this).val(); + var state_box = $('#' + $(this).attr('rel')); + + var input_name = $(state_box).attr('name'); + var input_id = $(state_box).attr('id'); + + var value = $(state_box).val(); + + if (states[country]) { + var options = ''; + var state = states[country]; + for(var index in state) { + options = options + ''; + } + if ($(state_box).is('input')) { + // Change for select + $(state_box).replaceWith(''); + state_box = $('#' + $(this).attr('rel')); + } + $(state_box).html( '' + options); + + $(state_box).val(value); + } else { + if ($(state_box).is('select')) { + $(state_box).replaceWith(''); + } + } + + }).change(); + + /* Tabs */ + $('div.woocommerce_tabs .panel').hide(); + $('div.woocommerce_tabs ul.tabs li a').click(function(){ + + var tab = $(this); + var tabs_wrapper = tab.closest('div.woocommerce_tabs'); + + $('ul.tabs li', tabs_wrapper).removeClass('active'); + $('div.panel', tabs_wrapper).hide(); + $('div' + tab.attr('href')).show(); + tab.parent().addClass('active'); + + return false; + }); + $('div.woocommerce_tabs').each(function() { + var hash = window.location.hash; + if (hash.toLowerCase().indexOf("comment-") >= 0) { + $('ul.tabs li.reviews_tab a', $(this)).click(); + } else { + $('ul.tabs li:first a', $(this)).click(); + } + }); + + /* Shipping calculator */ + $('.shipping-calculator-form').hide(); + + $('.shipping-calculator-button').click(function() { + $('.shipping-calculator-form').slideToggle('slow'); + return false; + }); + + // Variations + + //check if two arrays of attributes match + function variations_match(attrs1, attrs2) { + var match = true; + for (name in attrs1) { + var val1 = attrs1[name]; + var val2 = attrs2[name]; + + if(val1.length != 0 && val2.length != 0 && val1 != val2) { + match = false; + } + } + + return match; + } + + //search for matching variations for given set of attributes + function find_matching_variations(settings) { + var matching = []; + + for (var i = 0; i < product_variations.length; i++) { + var variation = product_variations[i]; + var variation_id = variation.variation_id; + + if(variations_match(variation.attributes, settings)) { + matching.push(variation); + } + } + return matching; + } + + //disable option fields that are unavaiable for current set of attributes + function update_variation_values(variations) { + + // Loop through selects and disable/enable options based on selections + $('.variations select').each(function( index, el ){ + + current_attr_select = $(el); + + // Disable all + current_attr_select.find('option:gt(0)').attr('disabled', 'disabled'); + + // Get name + var current_attr_name = current_attr_select.attr('name'); + + // Loop through variations + for(num in variations) { + var attributes = variations[num].attributes; + + for(attr_name in attributes) { + var attr_val = attributes[attr_name]; + + if(attr_name == current_attr_name) { + if (attr_val) { + current_attr_select.find('option[value="'+attr_val+'"]').removeAttr('disabled'); + } else { + current_attr_select.find('option').removeAttr('disabled'); + } + } + } + } + + }); + + } + + //show single variation details (price, stock, image) + function show_variation(variation) { + var img = $('div.images img:eq(0)'); + var link = $('div.images a.zoom:eq(0)'); + var o_src = $(img).attr('original-src'); + var o_link = $(link).attr('original-href'); + + var variation_image = variation.image_src; + var variation_link = variation.image_link; + + $('.variations_button').show(); + $('.single_variation').html( variation.price_html + variation.availability_html ); + + if (!o_src) { + $(img).attr('original-src', $(img).attr('src')); + } + + if (!o_link) { + $(link).attr('original-href', $(link).attr('href')); + } + + if (variation_image && variation_image.length > 1) { + $(img).attr('src', variation_image); + $(link).attr('href', variation_link); + } else { + $(img).attr('src', o_src); + $(link).attr('href', o_link); + } + + $('.single_variation_wrap').slideDown('200'); + } + + //when one of attributes is changed - check everything to show only valid options + function check_variations( exclude ) { + var all_set = true; + var current_settings = {}; + + $('.variations select').each(function(){ + + if ( exclude && $(this).attr('name') == exclude ) { + + all_set = false; + current_settings[$(this).attr('name')] = ''; + + } else { + if ($(this).val().length == 0) all_set = false; + + // Get value + value = $(this).val(); + value = value.replace('"', '"'); + + // Add to settings array + current_settings[$(this).attr('name')] = value; + } + + }); + + var matching_variations = find_matching_variations(current_settings); + + if(all_set) { + var variation = matching_variations.pop(); + if (variation) { + $('form input[name=variation_id]').val(variation.variation_id); + show_variation(variation); + } else { + // Nothing found - reset fields + $('.variations select').val(''); + } + } else { + update_variation_values(matching_variations); + } + } + + $('.variations select').change(function(){ + + $('form input[name=variation_id]').val(''); + $('.single_variation_wrap').hide(); + $('.single_variation').text(''); + check_variations(); + $(this).blur(); + if( $().uniform && $.isFunction($.uniform.update) ) { + $.uniform.update(); + } + + }).focus(function(){ + + check_variations( $(this).attr('name') ); + + }).change(); + + if (woocommerce_params.is_cart==1) { + + $('select#shipping_method').live('change', function() { + + var method = $('#shipping_method').val(); + + $('div.cart_totals').block({message: null, overlayCSS: {background: '#fff url(' + woocommerce_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}}); + + var data = { + action: 'woocommerce_update_shipping_method', + security: woocommerce_params.update_shipping_method_nonce, + shipping_method: method + }; + + $.post( woocommerce_params.ajax_url, data, function(response) { + + $('div.cart_totals').replaceWith( response ); + + }); + + }); + + } + + if (woocommerce_params.is_checkout==1 || woocommerce_params.is_pay_page==1) { + + var updateTimer; + var xhr; + + function update_checkout() { + + if (xhr) xhr.abort(); + + var method = $('#shipping_method').val(); + var country = $('#billing_country').val(); + var state = $('#billing_state').val(); + var postcode = $('input#billing_postcode').val(); + + if ($('#shiptobilling input').is(':checked') || $('#shiptobilling input').size()==0) { + var s_country = $('#billing_country').val(); + var s_state = $('#billing_state').val(); + var s_postcode = $('input#billing_postcode').val(); + + } else { + var s_country = $('#shipping_country').val(); + var s_state = $('#shipping_state').val(); + var s_postcode = $('input#shipping_postcode').val(); + } + + $('#order_methods, #order_review').block({message: null, overlayCSS: {background: '#fff url(' + woocommerce_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}}); + + var data = { + action: 'woocommerce_update_order_review', + security: woocommerce_params.update_order_review_nonce, + shipping_method: method, + country: country, + state: state, + postcode: postcode, + s_country: s_country, + s_state: s_state, + s_postcode: s_postcode, + post_data: $('form.checkout').serialize() + }; + + xhr = $.ajax({ + type: 'POST', + url: woocommerce_params.ajax_url, + data: data, + success: function( response ) { + $('#order_methods, #order_review').remove(); + $('#order_review_heading').after(response); + $('#order_review input[name=payment_method]:checked').click(); + } + }); + + } + + $(function(){ + + $('p.password').hide(); + + $('input.show_password').change(function(){ + $('p.password').slideToggle(); + }); + + $('div.shipping_address').hide(); + + $('#shiptobilling input').change(function(){ + $('div.shipping_address').hide(); + if (!$(this).is(':checked')) { + $('div.shipping_address').slideDown(); + } + }).change(); + + if (woocommerce_params.option_guest_checkout=='yes') { + + $('div.create-account').hide(); + + $('input#createaccount').change(function(){ + $('div.create-account').hide(); + if ($(this).is(':checked')) { + $('div.create-account').slideDown(); + } + }).change(); + + } + + $('.payment_methods input.input-radio').live('click', function(){ + $('div.payment_box').hide(); + if ($(this).is(':checked')) { + $('div.payment_box.' + $(this).attr('ID')).slideDown(); + } + }); + + $('#order_review input[name=payment_method]:checked').click(); + + $('form.login').hide(); + + $('a.showlogin').click(function(){ + $('form.login').slideToggle(); + return false; + }); + + /* Update totals */ + $('#shipping_method').live('change', function(){ + clearTimeout(updateTimer); + update_checkout(); + }); + $('input#billing_country, input#billing_state, #billing_postcode, input#shipping_country, input#shipping_state, #shipping_postcode').live('keydown', function(){ + clearTimeout(updateTimer); + updateTimer = setTimeout("update_checkout()", '1000'); + }); + $('select#billing_country, select#billing_state, select#shipping_country, select#shipping_state, #shiptobilling input, .update_totals_on_change').live('change', function(){ + clearTimeout(updateTimer); + update_checkout(); + }); + + // Update on page load + if (woocommerce_params.is_checkout==1) update_checkout(); + + /* AJAX Form Submission */ + $('form.checkout').submit(function(){ + var form = this; + + if ($(form).is('.processing')) return false; + + $(form).addClass('processing').block({message: null, overlayCSS: {background: '#fff url(' + woocommerce_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6}}); + $.ajax({ + type: 'POST', + url: woocommerce_params.checkout_url, + data: $(form).serialize(), + success: function( code ) { + $('.woocommerce_error, .woocommerce_message').remove(); + try { + success = $.parseJSON( code ); + window.location = decodeURI(success.redirect); + } + catch(err) { + $(form).prepend( code ); + $(form).removeClass('processing').unblock(); + + $('html, body').animate({ + scrollTop: ($('form.checkout').offset().top - 100) + }, 1000); + } + }, + dataType: "html" + }); + return false; + }); + + }); + } + +}); \ No newline at end of file diff --git a/classes/cart.class.php b/classes/cart.class.php index 6c273d88628..a297b867488 100644 --- a/classes/cart.class.php +++ b/classes/cart.class.php @@ -90,8 +90,6 @@ class woocommerce_cart { * Sets the php session data for the cart and coupons */ function set_session() { - $cart = array(); - // Set cart and coupon session data $_SESSION['cart'] = $this->cart_contents; $_SESSION['coupons'] = $this->applied_coupons; diff --git a/classes/checkout.class.php b/classes/checkout.class.php index 6c104ef00a4..e8157e3b37a 100644 --- a/classes/checkout.class.php +++ b/classes/checkout.class.php @@ -828,6 +828,8 @@ class woocommerce_checkout { /** Gets the value either from the posted data, or from the users meta data */ function get_value( $input ) { + global $woocommerce; + if (isset( $this->posted[$input] ) && !empty($this->posted[$input])) : return $this->posted[$input]; elseif (is_user_logged_in()) : @@ -842,6 +844,16 @@ class woocommerce_checkout { break; endswitch; + else : + + switch ( $input ) : + + case "billing_country" : + return $woocommerce->countries->get_base_country(); + break; + + endswitch; + endif; } } \ No newline at end of file diff --git a/classes/order.class.php b/classes/order.class.php index c5d36c02f1c..103ffcd9be3 100644 --- a/classes/order.class.php +++ b/classes/order.class.php @@ -99,12 +99,16 @@ class woocommerce_order { // Formatted Addresses $formatted_address = array(); + $country = ($this->billing_country && isset($woocommerce->countries->countries[$this->billing_country])) ? $woocommerce->countries->countries[$this->billing_country] : $this->billing_country; + + $state = ($this->billing_country && $this->billing_state && isset($woocommerce->countries->states[$this->billing_country][$this->billing_state])) ? $woocommerce->countries->states[$this->billing_country][$this->billing_state] : $this->billing_state; + $address = array_map('trim', array( $this->billing_address_1, $this->billing_address_2, $this->billing_city, - $this->billing_state, + $state, $this->billing_postcode, $country )); @@ -113,12 +117,16 @@ class woocommerce_order { if ($this->shipping_address_1) : $formatted_address = array(); + $country = ($this->shipping_country && isset($woocommerce->countries->countries[$this->shipping_country])) ? $woocommerce->countries->countries[$this->shipping_country] : $this->shipping_country; + + $state = ($this->shipping_country && $this->shipping_state && isset($woocommerce->countries->states[$this->shipping_country][$this->shipping_state])) ? $woocommerce->countries->states[$this->shipping_country][$this->shipping_state] : $this->shipping_state; + $address = array_map('trim', array( $this->shipping_address_1, $this->shipping_address_2, $this->shipping_city, - $this->shipping_state, + $state, $this->shipping_postcode, $country )); diff --git a/readme.txt b/readme.txt index b42fd59fe53..cb5c50d9d76 100644 --- a/readme.txt +++ b/readme.txt @@ -104,6 +104,9 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo * PayPal standard stores payer email address * Added handling for paypal reversal and refunded statuses * Downloads check order status is completed before allowing access - to do this we've added a new column to the permissions table (order id). Existing rows will be updated upon activation. +* Formatted address shows full state name +* State field shows 'select a state by default' +* Country defaults to base country on checkout = 1.2.1 - 10/11/2011 = * Reworked downloadable and virtual products - now variations can be downloadable/virtual too making it more flexible