diff --git a/admin/admin-init.php b/admin/admin-init.php index 4747ba426e8..4e568d1efbc 100644 --- a/admin/admin-init.php +++ b/admin/admin-init.php @@ -95,6 +95,7 @@ function woocommerce_admin_scripts() { 'cart_total' => __("Calculate totals based on order items, discount amount, and shipping? Note, you will need to calculate discounts before tax manually.", 'woothemes'), 'copy_billing' => __("Copy billing information to shipping information? This will remove any currently entered shipping information.", 'woothemes'), 'prices_include_tax' => get_option('woocommerce_prices_include_tax'), + 'round_at_subtotal' => get_option( 'woocommerce_tax_round_at_subtotal' ), 'ID' => __('ID', 'woothemes'), 'item_name' => __('Item Name', 'woothemes'), 'quantity' => __('Quantity e.g. 2', 'woothemes'), diff --git a/assets/js/admin/write-panels.js b/assets/js/admin/write-panels.js index 57b3a680d95..48b55da586b 100644 --- a/assets/js/admin/write-panels.js +++ b/assets/js/admin/write-panels.js @@ -80,7 +80,7 @@ jQuery( function($){ totalItemTax = 0; // Calculate tax and discounts - cart_discount = cart_discount + itemDiscount; + cart_discount = parseFloat( cart_discount + itemDiscount ); if (itemTax && itemTax>0) { diff --git a/assets/js/admin/write-panels.min.js b/assets/js/admin/write-panels.min.js index 11eaaab4b0d..0e628faeea7 100644 --- a/assets/js/admin/write-panels.min.js +++ b/assets/js/admin/write-panels.min.js @@ -1 +1,539 @@ -jQuery(function(e){e("#upsell_product_data").bind("keypress",function(h){if(h.keyCode==13){return false}});e("ul.tabs").show();e("div.panel-wrap").each(function(){e("div.panel:not(div.panel:first)",this).hide()});e("ul.tabs a").click(function(){var h=e(this).closest("div.panel-wrap");e("ul.tabs li",h).removeClass("active");e(this).parent().addClass("active");e("div.panel",h).hide();e(e(this).attr("href")).show();return false});e("a.edit_address").click(function(){e(this).hide();e(this).closest(".order_data").find("div.address").hide();e(this).closest(".order_data").find("div.edit_address").show()});jQuery("select.chosen_select").chosen();jQuery("select.chosen_select_nostd").chosen({allow_single_deselect:"true"});e("#order_items_list button.remove_row").live("click",function(){var h=confirm(woocommerce_writepanel_params.remove_item_notice);if(h){e(this).closest("tr.item").hide();e("input",e(this).closest("tr.item")).val("")}return false});e("button.calc_totals").live("click",function(){var r=confirm(woocommerce_writepanel_params.cart_total);if(r){var j=e("#order_items_list tr.item").size();var p=0;var q=e("input#_order_discount").val();var h=e("input#_order_shipping").val();var l=parseFloat(e("input#_order_shipping_tax").val());var m=0;var k=0;var p=0;var o=0;var n=0;if(!q){q=0}if(!h){h=0}if(!l){l=0}if(j>0){for(i=0;i0){if(woocommerce_writepanel_params.prices_include_tax=="yes"){taxRate=(itemTax/100)+1;price_in_tax=(itemCost*taxRate)*itemQty;discounted_price=price_in_tax-itemDiscount;totalItemTax=(discounted_price-(discounted_price/taxRate))*100;totalItemTax=totalItemTax.toFixed(2);totalItemTax=Math.round(totalItemTax)/100;discounted_price=discounted_price-totalItemTax}else{taxRate=(itemTax/100);discounted_price=(itemCost*taxRate)-itemDiscount;totalItemTax=(discounted_price*taxRate)*100;totalItemTax=totalItemTax.toFixed(2);totalItemTax=Math.round(totalItemTax)/100}}else{discounted_price=(itemCost*itemQty)-itemDiscount}totalItemCost=parseFloat(discounted_price);k=parseFloat(k+totalItemCost);p=parseFloat(p+(itemCost*itemQty));m=parseFloat(m+totalItemTax)}}o=parseFloat(k)+parseFloat(m)-parseFloat(q)+parseFloat(h)+parseFloat(l);if(o<0){o=0}e("input#_cart_discount").val(n.toFixed(2));e("input#_order_subtotal").val(p.toFixed(2));e("input#_order_tax").val(m.toFixed(2));e("input#_order_shipping_tax").val(l.toFixed(2));e("input#_order_total").val(o.toFixed(2))}return false});e("button.add_shop_order_item").click(function(){var k=e("select.add_item_id").val();if(k){e("table.woocommerce_order_items").block({message:null,overlayCSS:{background:"#fff url("+woocommerce_writepanel_params.plugin_url+"/assets/images/ajax-loader.gif) no-repeat center",opacity:0.6}});var h=e("table.woocommerce_order_items tbody tr.item").size();var j={action:"woocommerce_add_order_item",item_to_add:e("select.add_item_id").val(),index:h,security:woocommerce_writepanel_params.add_order_item_nonce};e.post(woocommerce_writepanel_params.ajax_url,j,function(l){e("table.woocommerce_order_items tbody#order_items_list").append(l);e("table.woocommerce_order_items").unblock();e("select.add_item_id").css("border-color","").val("");e(".tips").easyTooltip()})}else{e("select.add_item_id").css("border-color","red")}});e("button.add_meta").live("click",function(){var h=e(this).closest("tr.item").attr("rel");e(this).closest("table.meta").find(".meta_items").append('');return false});e("button.remove_meta").live("click",function(){var h=confirm("Remove this meta key?");if(h){e(this).closest("tr").remove()}return false});e("button.billing-same-as-shipping").live("click",function(){var h=confirm(woocommerce_writepanel_params.copy_billing);if(h){e("input#shipping_first_name").val(e("input#billing_first_name").val());e("input#shipping_last_name").val(e("input#billing_last_name").val());e("input#shipping_company").val(e("input#billing_company").val());e("input#shipping_address_1").val(e("input#billing_address_1").val());e("input#shipping_address_2").val(e("input#billing_address_2").val());e("input#shipping_city").val(e("input#billing_city").val());e("input#shipping_postcode").val(e("input#billing_postcode").val());e("input#shipping_country").val(e("input#billing_country").val());e("input#shipping_state").val(e("input#billing_state").val())}return false});e("select#product-type").change(function(){var h=e(this).val();e(".show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external").hide();if(h=="simple"){e(".show_if_simple").show();e("input#manage_stock").change()}else{if(h=="variable"){e(".show_if_variable").show();e("input#manage_stock").change();e("input#downloadable").prop("checked",false).change();e("input#virtual").removeAttr("checked").change()}else{if(h=="grouped"){e(".show_if_grouped").show();e("input#downloadable").prop("checked",false).change();e("input#virtual").removeAttr("checked").change()}else{if(h=="external"){e(".show_if_external").show();e("input#downloadable").prop("checked",false).change();e("input#virtual").removeAttr("checked").change()}}}}e("ul.tabs li:visible").eq(0).find("a").click();e("body").trigger("woocommerce-product-type-change",h,e(this))}).change();e("input#downloadable").change(function(){e(".show_if_downloadable").hide();if(e("input#downloadable").is(":checked")){e(".show_if_downloadable").show()}if(e(".downloads_tab").is(".active")){e("ul.tabs li:visible").eq(0).find("a").click()}}).change();e("input#virtual").change(function(){e(".show_if_virtual").hide();if(e("input#virtual").is(":checked")){e(".show_if_virtual").show()}}).change();e("input#manage_stock").change(function(){if(e(this).is(":checked")){e("div.stock_fields").show()}else{e("div.stock_fields").hide()}}).change();var f=e("#sale_price_dates_from, #sale_price_dates_to").datepicker({defaultDate:"",dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:true,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:true,onSelect:function(k){var l=this.id=="sale_price_dates_from"?"minDate":"maxDate",h=e(this).data("datepicker"),j=e.datepicker.parseDate(h.settings.dateFormat||e.datepicker._defaults.dateFormat,k,h.settings);f.not(this).datepicker("option",l,j)}});e(".date-picker").datepicker({dateFormat:"yy-mm-dd",numberOfMonths:1,showButtonPanel:true,showOn:"button",buttonImage:woocommerce_writepanel_params.calendar_image,buttonImageOnly:true});e("#attributes_list select.multiselect").chosen();var d=e("#attributes_list").children("tr").get();d.sort(function(j,h){var l=e(j).attr("rel");var k=e(h).attr("rel");return(lk)?1:0});e(d).each(function(h,j){e("#attributes_list").append(j)});function b(){e("table.woocommerce_attributes, table.woocommerce_variable_attributes").each(function(){if(e("tbody tr",this).size()==0){e(this).parent().hide()}else{e(this).parent().show()}})}b();function c(){e("#attributes_list tr").each(function(h,j){e(".attribute_position",j).val(parseInt(e(j).index("#attributes_list tr")))})}e("button.add_attribute").click(function(){var j=e("table.woocommerce_attributes tbody tr").size();var k=e("select.attribute_taxonomy").val();if(!k){var l=e("select#product-type").val();if(l!="variable"){enable_variation='style="display:none;"'}else{enable_variation=""}e("table.woocommerce_attributes tbody").append('')}else{var h=e("table.woocommerce_attributes tbody tr."+k);e("table.woocommerce_attributes tbody").append(e(h));e(h).show();c()}b()});e("button.hide_row").live("click",function(){var h=confirm("Remove this attribute?");if(h){e(this).parent().parent().find("select, input[type=text]").val("");e(this).parent().parent().hide();b()}return false});e("#attributes_list button.remove_row").live("click",function(){var h=confirm("Remove this attribute?");if(h){e(this).parent().parent().remove();b();c()}return false});e("table.woocommerce_attributes tbody").sortable({items:"tr",cursor:"move",axis:"y",handle:".handle",scrollSensitivity:40,helper:function(j,h){h.children().each(function(){e(this).width(e(this).width())});h.css("left","0");return h},start:function(h,j){j.item.css("background-color","#f6f6f6")},stop:function(h,j){j.item.removeAttr("style");c()}});e(".multi_select_products button").live("click",function(){var o=e(this).parent().parent().parent().parent();var h=e(this);var k=h.parent().parent();if(k.is(".multi_select_products_target_upsell")||k.is(".multi_select_products_target_crosssell")){h.parent().remove()}else{if(h.is(".add_upsell")){var m=e(".multi_select_products_target_upsell",e(o));var n="upsell_ids[]"}else{var m=e(".multi_select_products_target_crosssell",e(o));var n="crosssell_ids[]"}var j=e("li[rel="+h.parent().attr("rel")+"]",m);if(e(j).size()>0){return false}var l=h.parent().clone();l.find("button:eq(0)").html("×");l.find("button:eq(1)").remove();l.find("input").val(h.parent().attr("rel"));l.find(".product_id").attr("name",n);l.appendTo(m)}});var g;e(".multi_select_products #product_search").bind("keyup click",function(){e(".multi_select_products_source").addClass("loading");e(".multi_select_products_source li:not(.product_search)").remove();if(g){g.abort()}var k=e(this).val();var h=this;var j=e(this).attr("rel");if(k.length<3){e(".multi_select_products_source").removeClass("loading");return}var l={name:j,search:encodeURI(k),action:"woocommerce_upsell_crosssell_search_products",security:woocommerce_writepanel_params.upsell_crosssell_search_products_nonce};g=e.ajax({url:woocommerce_writepanel_params.ajax_url,data:l,type:"POST",success:function(m){e(".multi_select_products_source").removeClass("loading");e(".multi_select_products_source li:not(.product_search)").remove();e(h).parent().parent().append(m)}})});var a;window.send_to_editor_default=window.send_to_editor;jQuery(".upload_file_button").live("click",function(){a=jQuery(this).parent().find(".file_path");formfield=jQuery(a).attr("name");window.send_to_editor=window.send_to_download_url;tb_show("","media-upload.php?post_id="+woocommerce_writepanel_params.post_id+"&type=downloadable_product&from=wc01&TB_iframe=true");return false});window.send_to_download_url=function(h){file_url=jQuery(h).attr("href");if(file_url){jQuery(a).val(file_url)}tb_remove();window.send_to_editor=window.send_to_editor_default}}); \ No newline at end of file +jQuery( function($){ + + // Prevent enter submitting post form + $("#upsell_product_data").bind("keypress", function(e) { + if (e.keyCode == 13) return false; + }); + + // TABS + $('ul.tabs').show(); + $('div.panel-wrap').each(function(){ + $('div.panel:not(div.panel:first)', this).hide(); + }); + $('ul.tabs a').click(function(){ + var panel_wrap = $(this).closest('div.panel-wrap'); + $('ul.tabs li', panel_wrap).removeClass('active'); + $(this).parent().addClass('active'); + $('div.panel', panel_wrap).hide(); + $( $(this).attr('href') ).show(); + return false; + }); + + // ORDERS + $('a.edit_address').click(function(){ + + $(this).hide(); + $(this).closest('.order_data').find('div.address').hide(); + $(this).closest('.order_data').find('div.edit_address').show(); + + }); + + // Chosen selects + jQuery("select.chosen_select").chosen(); + + jQuery("select.chosen_select_nostd").chosen({ + allow_single_deselect: 'true' + }); + + $('#order_items_list button.remove_row').live('click', function(){ + var answer = confirm(woocommerce_writepanel_params.remove_item_notice); + if (answer){ + $(this).closest('tr.item').hide(); + $('input', $(this).closest('tr.item')).val(''); + } + return false; + }); + + $('button.calc_totals').live('click', function(){ + var answer = confirm(woocommerce_writepanel_params.cart_total); + if (answer){ + + var item_count = $('#order_items_list tr.item').size(); + var subtotal = 0; + var discount = $('input#_order_discount').val(); + var shipping = $('input#_order_shipping').val(); + var shipping_tax = parseFloat($('input#_order_shipping_tax').val()); + var tax = 0; + var itemTotal = 0; + var subtotal = 0; + var total = 0; + var cart_discount = 0; + + if (!discount) discount = 0; + if (!shipping) shipping = 0; + if (!shipping_tax) shipping_tax = 0; + + // Items + if (item_count>0) { + for (i=0; i0) { + + if (woocommerce_writepanel_params.prices_include_tax == 'yes') { + + taxRate = ( itemTax/100 ) + 1; + + // Discount worked out from tax inc. price then tax worked out backwards + price_in_tax = ( itemCost * taxRate ); + + discounted_price = ( price_in_tax * itemQty ) - itemDiscount; + + // Total item tax (after discount) + totalItemTax = ( discounted_price - ( discounted_price / taxRate ) ); + + if (woocommerce_writepanel_params.round_at_subtotal == 'no') { + + totalItemTax = totalItemTax * 100; + totalItemTax = totalItemTax.toFixed(2); + totalItemTax = Math.round( totalItemTax ) / 100; + + } + + discounted_price = discounted_price - totalItemTax; + + subtotal = subtotal + parseFloat( price_in_tax - ( Math.round( (itemCost*(itemTax/100))*100 ) / 100 ) * itemQty ); + + } else { + + taxRate = ( itemTax/100 ); + + // Discount worked out from ex. price and tax worked out forwards + discounted_price = (itemCost * itemQty) - itemDiscount; + + totalItemTax = ( discounted_price * taxRate ); + + if (woocommerce_writepanel_params.round_at_subtotal == 'no') { + + totalItemTax = totalItemTax * 100; + totalItemTax = totalItemTax.toFixed(2); + totalItemTax = Math.round( totalItemTax ) / 100; + + } + + subtotal = subtotal + parseFloat( (itemCost * itemQty) ); + + } + + + } else { + + discounted_price = (itemCost * itemQty ) - itemDiscount; + + subtotal = subtotal + parseFloat( (itemCost*itemQty) ); + + } + + totalItemCost = parseFloat( discounted_price ); + + itemTotal = itemTotal + parseFloat( totalItemCost ); + + tax = tax + parseFloat( totalItemTax ); + + } + } + + if (woocommerce_writepanel_params.round_at_subtotal == 'yes') { + + tax = tax * 100; + tax = tax.toFixed(2); + tax = Math.round( tax ) / 100; + + } + + total = parseFloat(itemTotal) + parseFloat(tax) - parseFloat(discount) + parseFloat(shipping) + parseFloat(shipping_tax); + + if (total < 0 ) total = 0; + + $('input#_cart_discount').val( cart_discount.toFixed(2) ); + $('input#_order_subtotal').val( subtotal.toFixed(2) ); + $('input#_order_tax').val( tax.toFixed(2) ); + $('input#_order_shipping_tax').val( shipping_tax.toFixed(2) ); + $('input#_order_total').val( total.toFixed(2) ); + + } + return false; + }); + + $('button.add_shop_order_item').click(function(){ + + var add_item_id = $('select.add_item_id').val(); + + if (add_item_id) { + + $('table.woocommerce_order_items').block({ message: null, overlayCSS: { background: '#fff url(' + woocommerce_writepanel_params.plugin_url + '/assets/images/ajax-loader.gif) no-repeat center', opacity: 0.6 } }); + + var size = $('table.woocommerce_order_items tbody tr.item').size(); + + var data = { + action: 'woocommerce_add_order_item', + item_to_add: $('select.add_item_id').val(), + index: size, + security: woocommerce_writepanel_params.add_order_item_nonce + }; + + $.post( woocommerce_writepanel_params.ajax_url, data, function(response) { + + $('table.woocommerce_order_items tbody#order_items_list').append( response ); + $('table.woocommerce_order_items').unblock(); + $('select.add_item_id').css('border-color', '').val(''); + $(".tips").easyTooltip(); + + }); + + } else { + $('select.add_item_id').css('border-color', 'red'); + } + + }); + + $('button.add_meta').live('click', function(){ + + var index = $(this).closest('tr.item').attr('rel'); + + $(this).closest('table.meta').find('.meta_items').append(''); + + return false; + + }); + + $('button.remove_meta').live('click', function(){ + var answer = confirm("Remove this meta key?") + if (answer){ + $(this).closest('tr').remove(); + } + return false; + }); + + $('button.billing-same-as-shipping').live('click', function(){ + var answer = confirm(woocommerce_writepanel_params.copy_billing); + if (answer){ + $('input#shipping_first_name').val( $('input#billing_first_name').val() ); + $('input#shipping_last_name').val( $('input#billing_last_name').val() ); + $('input#shipping_company').val( $('input#billing_company').val() ); + $('input#shipping_address_1').val( $('input#billing_address_1').val() ); + $('input#shipping_address_2').val( $('input#billing_address_2').val() ); + $('input#shipping_city').val( $('input#billing_city').val() ); + $('input#shipping_postcode').val( $('input#billing_postcode').val() ); + $('input#shipping_country').val( $('input#billing_country').val() ); + $('input#shipping_state').val( $('input#billing_state').val() ); + } + return false; + }); + + // PRODUCT TYPE SPECIFIC OPTIONS + $('select#product-type').change(function(){ + + // Get value + var select_val = $(this).val(); + + $('.show_if_simple, .show_if_variable, .show_if_grouped, .show_if_external').hide(); + + if (select_val=='simple') { + $('.show_if_simple').show(); + $('input#manage_stock').change(); + } + + else if (select_val=='variable') { + $('.show_if_variable').show(); + $('input#manage_stock').change(); + $('input#downloadable').prop('checked', false).change(); + $('input#virtual').removeAttr('checked').change(); + } + + else if (select_val=='grouped') { + $('.show_if_grouped').show(); + $('input#downloadable').prop('checked', false).change(); + $('input#virtual').removeAttr('checked').change(); + } + + else if (select_val=='external') { + $('.show_if_external').show(); + $('input#downloadable').prop('checked', false).change(); + $('input#virtual').removeAttr('checked').change(); + } + + $('ul.tabs li:visible').eq(0).find('a').click(); + + $('body').trigger('woocommerce-product-type-change', select_val, $(this) ); + + }).change(); + + $('input#downloadable').change(function(){ + + $('.show_if_downloadable').hide(); + + if ($('input#downloadable').is(':checked')) { + $('.show_if_downloadable').show(); + } + + if ($('.downloads_tab').is('.active')) $('ul.tabs li:visible').eq(0).find('a').click(); + + }).change(); + + $('input#virtual').change(function(){ + + $('.show_if_virtual').hide(); + + if ($('input#virtual').is(':checked')) { + $('.show_if_virtual').show(); + } + + }).change(); + + // STOCK OPTIONS + $('input#manage_stock').change(function(){ + if ($(this).is(':checked')) $('div.stock_fields').show(); + else $('div.stock_fields').hide(); + }).change(); + + + // DATE PICKER FIELDS + var dates = $( "#sale_price_dates_from, #sale_price_dates_to" ).datepicker({ + defaultDate: "", + dateFormat: "yy-mm-dd", + numberOfMonths: 1, + showButtonPanel: true, + showOn: "button", + buttonImage: woocommerce_writepanel_params.calendar_image, + buttonImageOnly: true, + onSelect: function( selectedDate ) { + var option = this.id == "sale_price_dates_from" ? "minDate" : "maxDate", + instance = $( this ).data( "datepicker" ), + date = $.datepicker.parseDate( + instance.settings.dateFormat || + $.datepicker._defaults.dateFormat, + selectedDate, instance.settings ); + dates.not( this ).datepicker( "option", option, date ); + } + }); + + $( ".date-picker" ).datepicker({ + dateFormat: "yy-mm-dd", + numberOfMonths: 1, + showButtonPanel: true, + showOn: "button", + buttonImage: woocommerce_writepanel_params.calendar_image, + buttonImageOnly: true + }); + + + // ATTRIBUTE TABLES + + // Multiselect attributes + $("#attributes_list select.multiselect").chosen(); + + // Initial order + var woocommerce_attributes_table_items = $('#attributes_list').children('tr').get(); + woocommerce_attributes_table_items.sort(function(a, b) { + var compA = $(a).attr('rel'); + var compB = $(b).attr('rel'); + return (compA < compB) ? -1 : (compA > compB) ? 1 : 0; + }) + $(woocommerce_attributes_table_items).each( function(idx, itm) { $('#attributes_list').append(itm); } ); + + // Show + function show_attribute_table() { + $('table.woocommerce_attributes, table.woocommerce_variable_attributes').each(function(){ + if ($('tbody tr', this).size()==0) + $(this).parent().hide(); + else + $(this).parent().show(); + }); + } + show_attribute_table(); + + function row_indexes() { + $('#attributes_list tr').each(function(index, el){ $('.attribute_position', el).val( parseInt( $(el).index('#attributes_list tr') ) ); }); + }; + + // Add rows + $('button.add_attribute').click(function(){ + + var size = $('table.woocommerce_attributes tbody tr').size(); + + var attribute_type = $('select.attribute_taxonomy').val(); + + if (!attribute_type) { + + var product_type = $('select#product-type').val(); + if (product_type!='variable') enable_variation = 'style="display:none;"'; else enable_variation = ''; + + // Add custom attribute row + $('table.woocommerce_attributes tbody').append(''); + + } else { + + // Reveal taxonomy row + var thisrow = $('table.woocommerce_attributes tbody tr.' + attribute_type); + $('table.woocommerce_attributes tbody').append( $(thisrow) ); + $(thisrow).show(); + row_indexes(); + + } + + show_attribute_table(); + }); + + $('button.hide_row').live('click', function(){ + var answer = confirm("Remove this attribute?") + if (answer){ + $(this).parent().parent().find('select, input[type=text]').val(''); + $(this).parent().parent().hide(); + show_attribute_table(); + } + return false; + }); + + $('#attributes_list button.remove_row').live('click', function(){ + var answer = confirm("Remove this attribute?") + if (answer){ + $(this).parent().parent().remove(); + show_attribute_table(); + row_indexes(); + } + return false; + }); + + // Attribute ordering + $('table.woocommerce_attributes tbody').sortable({ + items:'tr', + cursor:'move', + axis:'y', + handle: '.handle', + scrollSensitivity:40, + helper:function(e,ui){ + ui.children().each(function(){ + $(this).width($(this).width()); + }); + ui.css('left', '0'); + return ui; + }, + start:function(event,ui){ + ui.item.css('background-color','#f6f6f6'); + }, + stop:function(event,ui){ + ui.item.removeAttr('style'); + row_indexes(); + } + }); + + + + // Cross sells/Up sells + $('.multi_select_products button').live('click', function(){ + + var wrapper = $(this).parent().parent().parent().parent(); + + var button = $(this); + var button_parent = button.parent().parent(); + + if (button_parent.is('.multi_select_products_target_upsell') || button_parent.is('.multi_select_products_target_crosssell')) { + button.parent().remove(); + } else { + if (button.is('.add_upsell')) { + var target = $('.multi_select_products_target_upsell', $(wrapper)); + var product_id_field_name = 'upsell_ids[]'; + } else { + var target = $('.multi_select_products_target_crosssell', $(wrapper)); + var product_id_field_name = 'crosssell_ids[]'; + } + + var exists = $('li[rel=' + button.parent().attr('rel') + ']', target); + + if ($(exists).size()>0) return false; + + var cloned_item = button.parent().clone(); + + cloned_item.find('button:eq(0)').html('×'); + cloned_item.find('button:eq(1)').remove(); + cloned_item.find('input').val( button.parent().attr('rel') ); + cloned_item.find('.product_id').attr('name', product_id_field_name); + + cloned_item.appendTo(target); + } + }); + + var xhr; + + $('.multi_select_products #product_search').bind('keyup click', function(){ + + $('.multi_select_products_source').addClass('loading'); + $('.multi_select_products_source li:not(.product_search)').remove(); + + if (xhr) xhr.abort(); + + var search = $(this).val(); + var input = this; + var name = $(this).attr('rel'); + + if (search.length<3) { + $('.multi_select_products_source').removeClass('loading'); + return; + } + + var data = { + name: name, + search: encodeURI(search), + action: 'woocommerce_upsell_crosssell_search_products', + security: woocommerce_writepanel_params.upsell_crosssell_search_products_nonce + }; + + xhr = $.ajax({ + url: woocommerce_writepanel_params.ajax_url, + data: data, + type: 'POST', + success: function( response ) { + + $('.multi_select_products_source').removeClass('loading'); + $('.multi_select_products_source li:not(.product_search)').remove(); + $(input).parent().parent().append( response ); + + } + }); + + }); + + // Uploading files + var file_path_field; + + window.send_to_editor_default = window.send_to_editor; + + jQuery('.upload_file_button').live('click', function(){ + + file_path_field = jQuery(this).parent().find('.file_path'); + + formfield = jQuery(file_path_field).attr('name'); + + window.send_to_editor = window.send_to_download_url; + + tb_show('', 'media-upload.php?post_id=' + woocommerce_writepanel_params.post_id + '&type=downloadable_product&from=wc01&TB_iframe=true'); + return false; + }); + + window.send_to_download_url = function(html) { + + file_url = jQuery(html).attr('href'); + if (file_url) { + jQuery(file_path_field).val(file_url); + } + tb_remove(); + window.send_to_editor = window.send_to_editor_default; + + } + +}); \ No newline at end of file diff --git a/classes/checkout.class.php b/classes/checkout.class.php index 27ec24e7ea9..53b1869ebab 100644 --- a/classes/checkout.class.php +++ b/classes/checkout.class.php @@ -685,7 +685,7 @@ class woocommerce_checkout { 'cost' => $_product->get_price_excluding_tax( false ), 'row_discount' => number_format( ( ( $_product->get_price()-$woocommerce->cart->get_discounted_price( $values, $_product->get_price() ) ) * $values['quantity'] ) - , 2, '.', '' ), + , 4, '.', '' ), 'taxrate' => $rate, 'item_meta' => $item_meta->meta ), $values);