Merge branch 'master' of github.com:woocommerce/woocommerce

This commit is contained in:
Rodrigo Primo 2019-01-10 16:39:22 -02:00
commit a7463c5535
8 changed files with 132 additions and 12 deletions

View File

@ -750,7 +750,7 @@ jQuery( function ( $ ) {
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( true === response.success ) {
// Redirect to same page for show the refunded status
window.location.href = window.location.href;
window.location.reload();
} else {
window.alert( response.data.error );
wc_meta_boxes_order_items.reload_items();

View File

@ -329,7 +329,13 @@ jQuery( function( $ ) {
.on( 'change', '#variable_product_options .woocommerce_variations :input', this.input_changed )
.on( 'change', '.variations-defaults select', this.defaults_changed );
$( 'form#post' ).on( 'submit', this.save_on_submit );
var postForm = $( 'form#post' );
postForm.on( 'submit', this.save_on_submit );
$( 'input:submit', postForm ).bind( 'click keypress', function() {
postForm.data( 'callerid', this.id );
});
$( '.wc-metaboxes-wrapper' ).on( 'click', 'a.do_variation_action', this.do_variation_action );
},
@ -524,7 +530,14 @@ jQuery( function( $ ) {
* After saved, continue with form submission
*/
save_on_submit_done: function() {
$( 'form#post' ).submit();
var postForm = $( 'form#post' ),
callerid = postForm.data( 'callerid' );
if ( 'publish' === callerid ) {
postForm.append('<input type="hidden" name="publish" value="1" />').submit();
} else {
postForm.append('<input type="hidden" name="save-post" value="1" />').submit();
}
},
/**

View File

@ -33,11 +33,11 @@ if ( ! defined( 'ABSPATH' ) ) {
<option value=""><?php echo esc_html( sprintf( __( 'No default %s&hellip;', 'woocommerce' ), wc_attribute_label( $attribute->get_name() ) ) ); ?></option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name, $option, $attribute->get_name(), $product_object ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute->get_name(), $product_object ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>

View File

@ -35,11 +35,11 @@ if ( ! defined( 'ABSPATH' ) ) {
</option>
<?php if ( $attribute->is_taxonomy() ) : ?>
<?php foreach ( $attribute->get_terms() as $option ) : ?>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name ) ); ?></option>
<option <?php selected( $selected_value, $option->slug ); ?> value="<?php echo esc_attr( $option->slug ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option->name, $option, $attribute->get_name(), $product_object ) ); ?></option>
<?php endforeach; ?>
<?php else : ?>
<?php foreach ( $attribute->get_options() as $option ) : ?>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); ?></option>
<option <?php selected( $selected_value, $option ); ?> value="<?php echo esc_attr( $option ); ?>"><?php echo esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute->get_name(), $product_object ) ); ?></option>
<?php endforeach; ?>
<?php endif; ?>
</select>

View File

@ -579,10 +579,28 @@ final class WC_Cart_Totals {
$taxes[ $rate_id ] += $this->round_line_tax( $rate );
}
}
$taxes = $this->round_merged_taxes( $taxes );
return $in_cents ? $taxes : wc_remove_number_precision_deep( $taxes );
}
/**
* Round merged taxes.
*
* @since 3.5.4
* @param array $taxes Taxes to round.
* @return array
*/
protected function round_merged_taxes( $taxes ) {
if ( $this->round_at_subtotal() ) {
foreach ( $taxes as $rate_id => $tax ) {
$taxes[ $rate_id ] = wc_round_tax_total( $tax, 0 );
}
}
return $taxes;
}
/**
* Combine item taxes into a single array, preserving keys.
*

View File

@ -2908,14 +2908,14 @@ if ( ! function_exists( 'wc_dropdown_variation_attribute_options' ) ) {
foreach ( $terms as $term ) {
if ( in_array( $term->slug, $options, true ) ) {
$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';
$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name, $term, $attribute, $product ) ) . '</option>';
}
}
} else {
foreach ( $options as $option ) {
// This handles < 2.4.0 bw compatibility where text attributes were not sanitized.
$selected = sanitize_title( $args['selected'] ) === $args['selected'] ? selected( $args['selected'], sanitize_title( $option ), false ) : selected( $args['selected'], $option, false );
$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ) . '</option>';
$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $option, null, $attribute, $product ) ) . '</option>';
}
}
}
@ -3406,7 +3406,7 @@ function wc_get_formatted_cart_item_data( $cart_item, $flat = false ) {
$label = wc_attribute_label( $taxonomy );
} else {
// If this is a custom option slug, get the options name.
$value = apply_filters( 'woocommerce_variation_option_name', $value );
$value = apply_filters( 'woocommerce_variation_option_name', $value, null, $taxonomy, $cart_item['data'] );
$label = wc_attribute_label( str_replace( 'attribute_', '', $name ), $cart_item['data'] );
}

View File

@ -12,7 +12,7 @@
*
* @see https://docs.woocommerce.com/document/template-structure/
* @package WooCommerce/Templates
* @version 3.4.0
* @version 3.6.0
*/
defined( 'ABSPATH' ) || exit;
@ -20,7 +20,7 @@ defined( 'ABSPATH' ) || exit;
global $post;
?>
<form action="<?php echo esc_url( get_permalink( $post->ID ) ); ?>" method="post" class="track_order">
<form action="<?php echo esc_url( get_permalink( $post->ID ) ); ?>" method="post" class="woocommerce-form woocommerce-form-track-order track_order">
<p><?php esc_html_e( 'To track your order please enter your Order ID in the box below and press the "Track" button. This was given to you on your receipt and in the confirmation email you should have received.', 'woocommerce' ); ?></p>

View File

@ -12,6 +12,95 @@ class WC_Tests_Cart extends WC_Unit_Test_Case {
WC()->customer->set_is_vat_exempt( false );
}
/**
* Test tax rounding.
* Ticket:
* https://github.com/woocommerce/woocommerce/issues/21021
*/
public function test_cart_get_total_issue_21021() {
update_option( 'woocommerce_prices_include_tax', 'yes' );
update_option( 'woocommerce_calc_taxes', 'yes' );
update_option( 'woocommerce_tax_round_at_subtotal', 'yes' );
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '23.0000',
'tax_rate_name' => 'TAX23',
'tax_rate_priority' => '1',
'tax_rate_compound' => '0',
'tax_rate_shipping' => '1',
'tax_rate_order' => '1',
'tax_rate_class' => '23percent',
);
$tax_rate_23 = WC_Tax::_insert_tax_rate( $tax_rate );
$tax_rate = array(
'tax_rate_country' => '',
'tax_rate_state' => '',
'tax_rate' => '5.0000',
'tax_rate_name' => 'TAX5',
'tax_rate_priority' => '2',
'tax_rate_compound' => '0',
'tax_rate_shipping' => '0',
'tax_rate_order' => '1',
'tax_rate_class' => '5percent',
);
$tax_rate_5 = WC_Tax::_insert_tax_rate( $tax_rate );
// Create product with price 19
$product = WC_Helper_Product::create_simple_product();
$product->set_price( 19 );
$product->set_regular_price( 19 );
$product->set_tax_class( '5percent' );
$product->save();
// Create product with price 59
$product2 = WC_Helper_Product::create_simple_product();
$product2->set_price( 59 );
$product2->set_regular_price( 59 );
$product->set_tax_class( '5percent' );
$product2->save();
// Create a flat rate method.
$flat_rate_settings = array(
'enabled' => 'yes',
'title' => 'Flat rate',
'availability' => 'all',
'countries' => '',
'tax_status' => 'taxable',
'cost' => '8.05',
);
update_option( 'woocommerce_flat_rate_settings', $flat_rate_settings );
update_option( 'woocommerce_flat_rate', array() );
WC_Cache_Helper::get_transient_version( 'shipping', true );
WC()->shipping->load_shipping_methods();
WC()->cart->empty_cart();
// Set the flat_rate shipping method
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
// Add product to cart x1, calc and test
WC()->cart->add_to_cart( $product->get_id(), 1 );
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
WC()->cart->calculate_totals();
$this->assertEquals( 28.9, WC()->cart->total );
// Add product2 to cart
WC()->cart->add_to_cart( $product2->get_id(), 1 );
WC()->session->set( 'chosen_shipping_methods', array( 'flat_rate' ) );
WC()->cart->calculate_totals();
$this->assertEquals( 87.9, WC()->cart->total );
WC_Helper_Product::delete_product( $product->get_id() );
WC_Helper_Product::delete_product( $product2->get_id() );
WC_Tax::_delete_tax_rate( $tax_rate_23 );
WC_Tax::_delete_tax_rate( $tax_rate_5 );
}
/**
* Test some discount logic which has caused issues in the past.
* Ticket: