Merge branch 'master' into experiment/product-sorting-index
This commit is contained in:
commit
e7bb5a8f41
|
@ -384,13 +384,13 @@ jQuery( function ( $ ) {
|
|||
if ( value != null ) {
|
||||
wc_meta_boxes_order_items.block();
|
||||
|
||||
var data = {
|
||||
var data = $.extend( {}, wc_meta_boxes_order_items.get_taxable_address(), {
|
||||
action : 'woocommerce_add_coupon_discount',
|
||||
dataType : 'json',
|
||||
order_id : woocommerce_admin_meta_boxes.post_id,
|
||||
security : woocommerce_admin_meta_boxes.order_item_nonce,
|
||||
coupon : value
|
||||
};
|
||||
} );
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
if ( response.success ) {
|
||||
|
@ -411,13 +411,13 @@ jQuery( function ( $ ) {
|
|||
var $this = $( this );
|
||||
wc_meta_boxes_order_items.block();
|
||||
|
||||
var data = {
|
||||
var data = $.extend( {}, wc_meta_boxes_order_items.get_taxable_address(), {
|
||||
action : 'woocommerce_remove_order_coupon',
|
||||
dataType : 'json',
|
||||
order_id : woocommerce_admin_meta_boxes.post_id,
|
||||
security : woocommerce_admin_meta_boxes.order_item_nonce,
|
||||
coupon : $this.data( 'code' )
|
||||
};
|
||||
} );
|
||||
|
||||
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
|
||||
if ( response.success ) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* jQuery FlexSlider v2.7.1
|
||||
* jQuery FlexSlider v2.7.2
|
||||
* Copyright 2012 WooThemes
|
||||
* Contributing Author: Tyler Smith
|
||||
*/
|
||||
|
@ -236,15 +236,35 @@
|
|||
if (slider.pagingCount > 1) {
|
||||
for (var i = 0; i < slider.pagingCount; i++) {
|
||||
slide = slider.slides.eq(i);
|
||||
if ( undefined === slide.attr( 'data-thumb-alt' ) ) { slide.attr( 'data-thumb-alt', '' ); }
|
||||
var altText = ( '' !== slide.attr( 'data-thumb-alt' ) ) ? altText = ' alt="' + slide.attr( 'data-thumb-alt' ) + '"' : '';
|
||||
item = (slider.vars.controlNav === "thumbnails") ? '<img src="' + slide.attr( 'data-thumb' ) + '"' + altText + '/>' : '<a href="#">' + j + '</a>';
|
||||
|
||||
if ( undefined === slide.attr( 'data-thumb-alt' ) ) {
|
||||
slide.attr( 'data-thumb-alt', '' );
|
||||
}
|
||||
|
||||
item = $( '<a></a>' ).attr( 'href', '#' ).text( j );
|
||||
if ( slider.vars.controlNav === "thumbnails" ) {
|
||||
item = $( '<img/>' ).attr( 'src', slide.attr( 'data-thumb' ) );
|
||||
}
|
||||
|
||||
if ( '' !== slide.attr( 'data-thumb-alt' ) ) {
|
||||
item.attr( 'alt', slide.attr( 'data-thumb-alt' ) );
|
||||
}
|
||||
|
||||
if ( 'thumbnails' === slider.vars.controlNav && true === slider.vars.thumbCaptions ) {
|
||||
var captn = slide.attr( 'data-thumbcaption' );
|
||||
if ( '' !== captn && undefined !== captn ) { item += '<span class="' + namespace + 'caption">' + captn + '</span>'; }
|
||||
if ( '' !== captn && undefined !== captn ) {
|
||||
var caption = $('<span></span>' ).addClass( namespace + 'caption' ).text( captn );
|
||||
item.append( caption );
|
||||
}
|
||||
}
|
||||
slider.controlNavScaffold.append('<li>' + item + '</li>');
|
||||
|
||||
var liElement = $( '<li>' );
|
||||
item.appendTo( liElement );
|
||||
liElement.append( '</li>' );
|
||||
|
||||
slider.controlNavScaffold.append(liElement);
|
||||
j++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -31,8 +31,9 @@ jQuery( function( $ ) {
|
|||
$( 'input#min_price, input#max_price' ).hide();
|
||||
$( '.price_slider, .price_label' ).show();
|
||||
|
||||
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
||||
max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
|
||||
var min_price = $( '.price_slider_amount #min_price' ).data( 'min' ),
|
||||
max_price = $( '.price_slider_amount #max_price' ).data( 'max' ),
|
||||
step = $( '.price_slider_amount' ).data( 'step' ) || 1,
|
||||
current_min_price = $( '.price_slider_amount #min_price' ).val(),
|
||||
current_max_price = $( '.price_slider_amount #max_price' ).val();
|
||||
|
||||
|
@ -41,6 +42,7 @@ jQuery( function( $ ) {
|
|||
animate: true,
|
||||
min: min_price,
|
||||
max: max_price,
|
||||
step: step,
|
||||
values: [ current_min_price, current_max_price ],
|
||||
create: function() {
|
||||
|
||||
|
|
|
@ -997,10 +997,10 @@ class WC_AJAX {
|
|||
$amount = isset( $_POST['amount'] ) ? wc_clean( wp_unslash( $_POST['amount'] ) ) : 0;
|
||||
|
||||
$calculate_tax_args = array(
|
||||
'country' => isset( $_POST['country'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
'country' => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
);
|
||||
|
||||
if ( strstr( $amount, '%' ) ) {
|
||||
|
@ -1138,8 +1138,14 @@ class WC_AJAX {
|
|||
$response = array();
|
||||
|
||||
try {
|
||||
$order_id = isset( $_POST['order_id'] ) ? absint( $_POST['order_id'] ) : 0;
|
||||
$order = wc_get_order( $order_id );
|
||||
$order_id = isset( $_POST['order_id'] ) ? absint( $_POST['order_id'] ) : 0;
|
||||
$order = wc_get_order( $order_id );
|
||||
$calculate_tax_args = array(
|
||||
'country' => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
);
|
||||
|
||||
if ( ! $order ) {
|
||||
throw new Exception( __( 'Invalid order', 'woocommerce' ) );
|
||||
|
@ -1155,6 +1161,9 @@ class WC_AJAX {
|
|||
throw new Exception( html_entity_decode( wp_strip_all_tags( $result->get_error_message() ) ) );
|
||||
}
|
||||
|
||||
$order->calculate_taxes( $calculate_tax_args );
|
||||
$order->calculate_totals( false );
|
||||
|
||||
ob_start();
|
||||
include 'admin/meta-boxes/views/html-order-items.php';
|
||||
$response['html'] = ob_get_clean();
|
||||
|
@ -1181,8 +1190,14 @@ class WC_AJAX {
|
|||
$response = array();
|
||||
|
||||
try {
|
||||
$order_id = isset( $_POST['order_id'] ) ? absint( $_POST['order_id'] ) : 0;
|
||||
$order = wc_get_order( $order_id );
|
||||
$order_id = isset( $_POST['order_id'] ) ? absint( $_POST['order_id'] ) : 0;
|
||||
$order = wc_get_order( $order_id );
|
||||
$calculate_tax_args = array(
|
||||
'country' => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
);
|
||||
|
||||
if ( ! $order ) {
|
||||
throw new Exception( __( 'Invalid order', 'woocommerce' ) );
|
||||
|
@ -1193,6 +1208,8 @@ class WC_AJAX {
|
|||
}
|
||||
|
||||
$order->remove_coupon( wc_clean( wp_unslash( $_POST['coupon'] ) ) );
|
||||
$order->calculate_taxes( $calculate_tax_args );
|
||||
$order->calculate_totals( false );
|
||||
|
||||
ob_start();
|
||||
include 'admin/meta-boxes/views/html-order-items.php';
|
||||
|
@ -1234,10 +1251,10 @@ class WC_AJAX {
|
|||
$order_item_ids = wp_unslash( $_POST['order_item_ids'] ); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$items = ( ! empty( $_POST['items'] ) ) ? wp_unslash( $_POST['items'] ) : ''; // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
|
||||
$calculate_tax_args = array(
|
||||
'country' => isset( $_POST['country'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
'country' => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
);
|
||||
|
||||
if ( ! is_array( $order_item_ids ) && is_numeric( $order_item_ids ) ) {
|
||||
|
@ -1349,10 +1366,10 @@ class WC_AJAX {
|
|||
|
||||
$order_id = absint( $_POST['order_id'] );
|
||||
$calculate_tax_args = array(
|
||||
'country' => isset( $_POST['country'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
'country' => isset( $_POST['country'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['country'] ) ) ) : '',
|
||||
'state' => isset( $_POST['state'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['state'] ) ) ) : '',
|
||||
'postcode' => isset( $_POST['postcode'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['postcode'] ) ) ) : '',
|
||||
'city' => isset( $_POST['city'] ) ? wc_strtoupper( wc_clean( wp_unslash( $_POST['city'] ) ) ) : '',
|
||||
);
|
||||
|
||||
// Parse the jQuery serialized items.
|
||||
|
|
|
@ -168,7 +168,7 @@ class WC_Frontend_Scripts {
|
|||
'flexslider' => array(
|
||||
'src' => self::get_asset_url( 'assets/js/flexslider/jquery.flexslider' . $suffix . '.js' ),
|
||||
'deps' => array( 'jquery' ),
|
||||
'version' => '2.7.1',
|
||||
'version' => '2.7.2',
|
||||
),
|
||||
'js-cookie' => array(
|
||||
'src' => self::get_asset_url( 'assets/js/js-cookie/js.cookie' . $suffix . '.js' ),
|
||||
|
|
|
@ -516,36 +516,32 @@ class WC_Query {
|
|||
return $args;
|
||||
}
|
||||
|
||||
$min = isset( $_GET['min_price'] ) ? floatval( $_GET['min_price'] ) : 0;
|
||||
$max = isset( $_GET['max_price'] ) ? floatval( $_GET['max_price'] ) : 9999999999;
|
||||
$current_min_price = isset( $_GET['min_price'] ) ? floatval( wp_unslash( $_GET['min_price'] ) ) : 0; // WPCS: input var ok, CSRF ok.
|
||||
$current_max_price = isset( $_GET['max_price'] ) ? floatval( wp_unslash( $_GET['max_price'] ) ) : PHP_INT_MAX; // WPCS: input var ok, CSRF ok.
|
||||
|
||||
/**
|
||||
* Adjust if the store taxes are not displayed how they are stored.
|
||||
* Kicks in when prices excluding tax are displayed including tax.
|
||||
*/
|
||||
if ( wc_tax_enabled() && 'incl' === get_option( 'woocommerce_tax_display_shop' ) && ! wc_prices_include_tax() ) {
|
||||
$tax_classes = array_merge( array( '' ), WC_Tax::get_tax_classes() );
|
||||
$class_min = $min;
|
||||
$class_max = $max;
|
||||
$tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.
|
||||
$tax_rates = WC_Tax::get_rates( $tax_class );
|
||||
|
||||
foreach ( $tax_classes as $tax_class ) {
|
||||
$tax_rates = WC_Tax::get_rates( $tax_class );
|
||||
|
||||
if ( $tax_rates ) {
|
||||
$class_min = $min + WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min, $tax_rates ) );
|
||||
$class_max = $max - WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max, $tax_rates ) );
|
||||
}
|
||||
if ( $tax_rates ) {
|
||||
$current_min_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $current_min_price, $tax_rates ) );
|
||||
$current_max_price -= WC_Tax::get_tax_total( WC_Tax::calc_inclusive_tax( $current_max_price, $tax_rates ) );
|
||||
}
|
||||
|
||||
$min = $class_min;
|
||||
$max = $class_max;
|
||||
}
|
||||
|
||||
$step = max( apply_filters( 'woocommerce_price_filter_widget_step', 10 ), 1 );
|
||||
$current_min_price = floor( $current_min_price / $step ) * $step;
|
||||
$current_max_price = ceil( $current_max_price / $step ) * $step;
|
||||
|
||||
$args['join'] = $this->append_product_sorting_table_join( $args['join'] );
|
||||
$args['where'] .= $wpdb->prepare(
|
||||
' AND wc_product_meta_lookup.min_price >= %f AND wc_product_meta_lookup.max_price <= %f ',
|
||||
$min,
|
||||
$max
|
||||
$current_min_price,
|
||||
$current_max_price
|
||||
);
|
||||
return $args;
|
||||
}
|
||||
|
|
|
@ -653,6 +653,9 @@ abstract class WC_Abstract_Legacy_Product extends WC_Data {
|
|||
*/
|
||||
public static function sync_average_rating( $post_id ) {
|
||||
wc_deprecated_function( 'WC_Product::sync_average_rating', '3.0', 'WC_Comments::get_average_rating_for_product or leave to CRUD.' );
|
||||
// See notes in https://github.com/woocommerce/woocommerce/pull/22909#discussion_r262393401.
|
||||
// Sync count first like in the original method https://github.com/woocommerce/woocommerce/blob/2.6.0/includes/abstracts/abstract-wc-product.php#L1101-L1128.
|
||||
self::sync_rating_count( $post_id );
|
||||
$average = WC_Comments::get_average_rating_for_product( wc_get_product( $post_id ) );
|
||||
update_post_meta( $post_id, '_wc_average_rating', $average );
|
||||
}
|
||||
|
|
|
@ -73,23 +73,45 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
return;
|
||||
}
|
||||
|
||||
$min_price = isset( $_GET['min_price'] ) ? wc_clean( wp_unslash( $_GET['min_price'] ) ) : null; // WPCS: input var ok, CSRF ok.
|
||||
$max_price = isset( $_GET['max_price'] ) ? wc_clean( wp_unslash( $_GET['max_price'] ) ) : null; // WPCS: input var ok, CSRF ok.
|
||||
if ( ! wc()->query->get_main_query()->post_count && null === $min_price && null === $max_price ) {
|
||||
// If there are not posts and we're not filtering, hide the widget.
|
||||
if ( ! WC()->query->get_main_query()->post_count && ! isset( $_GET['min_price'] ) && ! isset( $_GET['max_price'] ) ) { // WPCS: input var ok, CSRF ok.
|
||||
return;
|
||||
}
|
||||
|
||||
wp_enqueue_script( 'wc-price-slider' );
|
||||
|
||||
// Find min and max price in current result set.
|
||||
$prices = $this->get_filtered_price();
|
||||
$min = floor( $prices->min_price );
|
||||
$max = ceil( $prices->max_price );
|
||||
// Round values to nearest 10 by default.
|
||||
$step = max( apply_filters( 'woocommerce_price_filter_widget_step', 10 ), 1 );
|
||||
|
||||
if ( $min === $max ) {
|
||||
// Find min and max price in current result set.
|
||||
$prices = $this->get_filtered_price();
|
||||
$min_price = $prices->min_price;
|
||||
$max_price = $prices->max_price;
|
||||
|
||||
// Check to see if we should add taxes to the prices if store are excl tax but display incl.
|
||||
$tax_display_mode = get_option( 'woocommerce_tax_display_shop' );
|
||||
|
||||
if ( wc_tax_enabled() && ! wc_prices_include_tax() && 'incl' === $tax_display_mode ) {
|
||||
$tax_class = apply_filters( 'woocommerce_price_filter_widget_tax_class', '' ); // Uses standard tax class.
|
||||
$tax_rates = WC_Tax::get_rates( $tax_class );
|
||||
|
||||
if ( $tax_rates ) {
|
||||
$min_price += WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $min_price, $tax_rates ) );
|
||||
$max_price += WC_Tax::get_tax_total( WC_Tax::calc_exclusive_tax( $max_price, $tax_rates ) );
|
||||
}
|
||||
}
|
||||
|
||||
$min_price = apply_filters( 'woocommerce_price_filter_widget_min_amount', floor( $min_price / $step ) * $step );
|
||||
$max_price = apply_filters( 'woocommerce_price_filter_widget_max_amount', ceil( $max_price / $step ) * $step );
|
||||
|
||||
// If both min and max are equal, we don't need a slider.
|
||||
if ( $min_price === $max_price ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$current_min_price = isset( $_GET['min_price'] ) ? floor( floatval( wp_unslash( $_GET['min_price'] ) ) / $step ) * $step : $min_price; // WPCS: input var ok, CSRF ok.
|
||||
$current_max_price = isset( $_GET['max_price'] ) ? ceil( floatval( wp_unslash( $_GET['max_price'] ) ) / $step ) * $step : $max_price; // WPCS: input var ok, CSRF ok.
|
||||
|
||||
$this->widget_start( $args, $instance );
|
||||
|
||||
if ( '' === get_option( 'permalink_structure' ) ) {
|
||||
|
@ -98,15 +120,12 @@ class WC_Widget_Price_Filter extends WC_Widget {
|
|||
$form_action = preg_replace( '%\/page/[0-9]+%', '', home_url( trailingslashit( $wp->request ) ) );
|
||||
}
|
||||
|
||||
$min_price = null !== $min_price ? $min_price : apply_filters( 'woocommerce_price_filter_widget_min_amount', $min );
|
||||
$max_price = null !== $max_price ? $max_price : apply_filters( 'woocommerce_price_filter_widget_max_amount', $max );
|
||||
|
||||
echo '<form method="get" action="' . esc_url( $form_action ) . '">
|
||||
<div class="price_slider_wrapper">
|
||||
<div class="price_slider" style="display:none;"></div>
|
||||
<div class="price_slider_amount">
|
||||
<input type="text" id="min_price" name="min_price" value="' . esc_attr( $min_price ) . '" data-min="' . esc_attr( apply_filters( 'woocommerce_price_filter_widget_min_amount', $min ) ) . '" placeholder="' . esc_attr__( 'Min price', 'woocommerce' ) . '" />
|
||||
<input type="text" id="max_price" name="max_price" value="' . esc_attr( $max_price ) . '" data-max="' . esc_attr( apply_filters( 'woocommerce_price_filter_widget_max_amount', $max ) ) . '" placeholder="' . esc_attr__( 'Max price', 'woocommerce' ) . '" />
|
||||
<div class="price_slider_amount" data-step="' . esc_attr( $step ) . '">
|
||||
<input type="text" id="min_price" name="min_price" value="' . esc_attr( $current_min_price ) . '" data-min="' . esc_attr( $min_price ) . '" placeholder="' . esc_attr__( 'Min price', 'woocommerce' ) . '" />
|
||||
<input type="text" id="max_price" name="max_price" value="' . esc_attr( $current_max_price ) . '" data-max="' . esc_attr( $max_price ) . '" placeholder="' . esc_attr__( 'Max price', 'woocommerce' ) . '" />
|
||||
<button type="submit" class="button">' . esc_html__( 'Filter', 'woocommerce' ) . '</button>
|
||||
<div class="price_label" style="display:none;">
|
||||
' . esc_html__( 'Price:', 'woocommerce' ) . ' <span class="from"></span> — <span class="to"></span>
|
||||
|
|
Loading…
Reference in New Issue