Show correct variations count when generating a single variation (#37876)
This commit is contained in:
parent
3c2bae196b
commit
72551f170a
|
@ -0,0 +1,4 @@
|
|||
Significance: patch
|
||||
Type: fix
|
||||
|
||||
Show correct variations count when generating a single variation.
|
|
@ -47,13 +47,11 @@ jQuery( function ( $ ) {
|
|||
'woocommerce_variations_loaded',
|
||||
this.variations_loaded
|
||||
);
|
||||
$( document.body )
|
||||
.on( 'woocommerce_variations_added', this.variation_added )
|
||||
.on(
|
||||
'keyup',
|
||||
'.wc_input_variations_price',
|
||||
this.maybe_enable_button_to_add_price_to_variations
|
||||
);
|
||||
$( document.body ).on(
|
||||
'keyup',
|
||||
'.wc_input_variations_price',
|
||||
this.maybe_enable_button_to_add_price_to_variations
|
||||
);
|
||||
},
|
||||
|
||||
create_variations: function ( event ) {
|
||||
|
@ -328,21 +326,6 @@ jQuery( function ( $ ) {
|
|||
$( document.body ).trigger( 'wc-enhanced-select-init' );
|
||||
},
|
||||
|
||||
/**
|
||||
* Run actions when added a variation
|
||||
*
|
||||
* @param {Object} event
|
||||
* @param {Int} qty
|
||||
*/
|
||||
variation_added: function ( event, qty ) {
|
||||
if ( 1 === qty ) {
|
||||
wc_meta_boxes_product_variations_actions.variations_loaded(
|
||||
null,
|
||||
true
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Sets a price for every variation
|
||||
*/
|
||||
|
@ -997,10 +980,13 @@ jQuery( function ( $ ) {
|
|||
$(
|
||||
'button.cancel-variation-changes, button.save-variation-changes'
|
||||
).prop( 'disabled', false );
|
||||
$( '#variable_product_options' ).trigger(
|
||||
'woocommerce_variations_added',
|
||||
1
|
||||
|
||||
wc_meta_boxes_product_variations_pagenav.update_single_quantity();
|
||||
wc_meta_boxes_product_variations_actions.variations_loaded(
|
||||
null,
|
||||
true
|
||||
);
|
||||
|
||||
wc_meta_boxes_product_variations_ajax.show_hide_variation_empty_state();
|
||||
wc_meta_boxes_product_variations_ajax.unblock();
|
||||
}
|
||||
|
@ -1118,25 +1104,17 @@ jQuery( function ( $ ) {
|
|||
woocommerce_admin_meta_boxes_variations.ajax_url,
|
||||
data,
|
||||
function ( response ) {
|
||||
var count = parseInt( response, 10 );
|
||||
const count = parseInt( response, 10 ) || 0;
|
||||
|
||||
if ( 1 === count ) {
|
||||
window.alert(
|
||||
count +
|
||||
' ' +
|
||||
woocommerce_admin_meta_boxes_variations.i18n_variation_added
|
||||
);
|
||||
} else if ( 0 === count || count > 1 ) {
|
||||
window.alert(
|
||||
count +
|
||||
' ' +
|
||||
woocommerce_admin_meta_boxes_variations.i18n_variations_added
|
||||
);
|
||||
} else {
|
||||
window.alert(
|
||||
woocommerce_admin_meta_boxes_variations.i18n_no_variations_added
|
||||
);
|
||||
}
|
||||
const message =
|
||||
count === 1
|
||||
? woocommerce_admin_meta_boxes_variations.i18n_variation_added
|
||||
: woocommerce_admin_meta_boxes_variations.i18n_variations_added.replace(
|
||||
'%qty%',
|
||||
count
|
||||
);
|
||||
|
||||
window.alert( message );
|
||||
|
||||
wc_meta_boxes_product_variations_ajax.show_hide_variation_empty_state();
|
||||
|
||||
|
@ -1145,10 +1123,6 @@ jQuery( function ( $ ) {
|
|||
1,
|
||||
count
|
||||
);
|
||||
$( '#variable_product_options' ).trigger(
|
||||
'woocommerce_variations_added',
|
||||
count
|
||||
);
|
||||
} else {
|
||||
wc_meta_boxes_product_variations_ajax.unblock();
|
||||
}
|
||||
|
@ -1386,10 +1360,6 @@ jQuery( function ( $ ) {
|
|||
*/
|
||||
init: function () {
|
||||
$( document.body )
|
||||
.on(
|
||||
'woocommerce_variations_added',
|
||||
this.update_single_quantity
|
||||
)
|
||||
.on(
|
||||
'change',
|
||||
'.variations-pagenav .page-selector',
|
||||
|
@ -1426,46 +1396,35 @@ jQuery( function ( $ ) {
|
|||
// Set the new total of variations
|
||||
wrapper.attr( 'data-total', total );
|
||||
|
||||
if ( 1 === total ) {
|
||||
displaying_num.text(
|
||||
woocommerce_admin_meta_boxes_variations.i18n_variation_count_single.replace(
|
||||
'%qty%',
|
||||
total
|
||||
)
|
||||
);
|
||||
} else {
|
||||
displaying_num.text(
|
||||
woocommerce_admin_meta_boxes_variations.i18n_variation_count_plural.replace(
|
||||
'%qty%',
|
||||
total
|
||||
)
|
||||
);
|
||||
}
|
||||
const message =
|
||||
total === 1
|
||||
? woocommerce_admin_meta_boxes_variations.i18n_variation_count_single
|
||||
: woocommerce_admin_meta_boxes_variations.i18n_variation_count_plural.replace(
|
||||
'%qty%',
|
||||
total
|
||||
);
|
||||
|
||||
displaying_num.text( message );
|
||||
|
||||
return total;
|
||||
},
|
||||
|
||||
/**
|
||||
* Update variations quantity when add a new variation
|
||||
*
|
||||
* @param {Object} event
|
||||
* @param {Int} qty
|
||||
*/
|
||||
update_single_quantity: function ( event, qty ) {
|
||||
if ( 1 === qty ) {
|
||||
var page_nav = $( '.variations-pagenav' );
|
||||
update_single_quantity: function () {
|
||||
wc_meta_boxes_product_variations_pagenav.update_variations_count(
|
||||
1
|
||||
);
|
||||
|
||||
wc_meta_boxes_product_variations_pagenav.update_variations_count(
|
||||
qty
|
||||
);
|
||||
const page_nav = $( '.variations-pagenav' );
|
||||
|
||||
if ( page_nav.is( ':hidden' ) ) {
|
||||
$( 'option, optgroup', '.variation_actions' ).show();
|
||||
$( '.variation_actions' ).val( 'bulk_actions' );
|
||||
$( '#variable_product_options' ).find( '.toolbar' ).show();
|
||||
page_nav.show();
|
||||
$( '.pagination-links', page_nav ).hide();
|
||||
}
|
||||
if ( page_nav.is( ':hidden' ) ) {
|
||||
$( 'option, optgroup', '.variation_actions' ).show();
|
||||
$( '.variation_actions' ).val( 'bulk_actions' );
|
||||
$( '#variable_product_options' ).find( '.toolbar' ).show();
|
||||
page_nav.show();
|
||||
$( '.pagination-links', page_nav ).hide();
|
||||
}
|
||||
},
|
||||
|
||||
|
|
|
@ -297,14 +297,13 @@ if ( ! class_exists( 'WC_Admin_Assets', false ) ) :
|
|||
'i18n_last_warning' => esc_js( __( 'Last warning, are you sure?', 'woocommerce' ) ),
|
||||
'i18n_choose_image' => esc_js( __( 'Choose an image', 'woocommerce' ) ),
|
||||
'i18n_set_image' => esc_js( __( 'Set variation image', 'woocommerce' ) ),
|
||||
'i18n_variation_added' => esc_js( __( 'variation added', 'woocommerce' ) ),
|
||||
'i18n_variations_added' => esc_js( __( 'variations added', 'woocommerce' ) ),
|
||||
'i18n_no_variations_added' => esc_js( __( 'No variations added', 'woocommerce' ) ),
|
||||
'i18n_variation_added' => esc_js( __( '1 variation added', 'woocommerce' ) ),
|
||||
'i18n_variations_added' => esc_js( __( '%qty% variations added', 'woocommerce' ) ),
|
||||
'i18n_remove_variation' => esc_js( __( 'Are you sure you want to remove this variation?', 'woocommerce' ) ),
|
||||
'i18n_scheduled_sale_start' => esc_js( __( 'Sale start date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
|
||||
'i18n_scheduled_sale_end' => esc_js( __( 'Sale end date (YYYY-MM-DD format or leave blank)', 'woocommerce' ) ),
|
||||
'i18n_edited_variations' => esc_js( __( 'Save changes before changing page?', 'woocommerce' ) ),
|
||||
'i18n_variation_count_single' => esc_js( __( '%qty% variation', 'woocommerce' ) ),
|
||||
'i18n_variation_count_single' => esc_js( __( '1 variation', 'woocommerce' ) ),
|
||||
'i18n_variation_count_plural' => esc_js( __( '%qty% variations', 'woocommerce' ) ),
|
||||
'variations_per_page' => absint( apply_filters( 'woocommerce_admin_meta_boxes_variations_per_page', 15 ) ),
|
||||
);
|
||||
|
|
Loading…
Reference in New Issue