Show errors for admin ajax variations
This commit is contained in:
parent
d0c2c10c47
commit
b0ce578541
|
@ -391,7 +391,7 @@ jQuery( function( $ ) {
|
|||
url: woocommerce_admin_meta_boxes_variations.ajax_url,
|
||||
data: data,
|
||||
type: 'POST',
|
||||
success: function() {
|
||||
success: function( response ) {
|
||||
// Allow change page, delete and add new variations
|
||||
need_update.removeClass( 'variation-needs-update' );
|
||||
$( 'button.cancel-variation-changes, button.save-variation-changes' ).attr( 'disabled', 'disabled' );
|
||||
|
@ -399,7 +399,7 @@ jQuery( function( $ ) {
|
|||
$( '#woocommerce-product-data' ).trigger( 'woocommerce_variations_saved' );
|
||||
|
||||
if ( typeof callback === 'function' ) {
|
||||
callback();
|
||||
callback( response );
|
||||
}
|
||||
|
||||
wc_meta_boxes_product_variations_ajax.unblock();
|
||||
|
@ -416,8 +416,15 @@ jQuery( function( $ ) {
|
|||
save_variations: function() {
|
||||
$( '#variable_product_options' ).trigger( 'woocommerce_variations_save_variations_button' );
|
||||
|
||||
wc_meta_boxes_product_variations_ajax.save_changes( function() {
|
||||
var current = $( '#variable_product_options .woocommerce_variations' ).attr( 'data-page' );
|
||||
wc_meta_boxes_product_variations_ajax.save_changes( function( error ) {
|
||||
var wrapper = $( '#variable_product_options .woocommerce_variations' ),
|
||||
current = wrapper.attr( 'data-page' );
|
||||
|
||||
$( '#variable_product_options #woocommerce_errors' ).remove();
|
||||
|
||||
if ( error ) {
|
||||
wrapper.before( error );
|
||||
}
|
||||
|
||||
$( '.variations-defaults select' ).each( function() {
|
||||
$( this ).attr( 'data-current', $( this ).val() );
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -20,7 +20,7 @@ if ( ! defined( 'ABSPATH' ) ) {
|
|||
class WC_Admin_Meta_Boxes {
|
||||
|
||||
private static $saved_meta_boxes = false;
|
||||
private static $meta_box_errors = array();
|
||||
public static $meta_box_errors = array();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
|
|
|
@ -1322,7 +1322,7 @@ class WC_Meta_Box_Product_Data {
|
|||
$unique_sku = wc_product_has_unique_sku( $variation_id, $new_sku );
|
||||
|
||||
if ( ! $unique_sku ) {
|
||||
WC_Admin_Meta_Boxes::add_error( __( 'Variation SKU must be unique.', 'woocommerce' ) );
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%s – Variation SKU must be unique.', 'woocommerce' ), $variation_id ) );
|
||||
} else {
|
||||
update_post_meta( $variation_id, '_sku', $new_sku );
|
||||
}
|
||||
|
@ -1442,14 +1442,14 @@ class WC_Meta_Box_Product_Data {
|
|||
$extension = pathinfo( $parsed_url, PATHINFO_EXTENSION );
|
||||
|
||||
if ( ! empty( $extension ) && ! in_array( $file_type['type'], $allowed_file_types ) ) {
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( 'The downloadable file %s cannot be used as it does not have an allowed file type. Allowed types include: %s', 'woocommerce' ), '<code>' . basename( $file_url ) . '</code>', '<code>' . implode( ', ', array_keys( $allowed_file_types ) ) . '</code>' ) );
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%s – The downloadable file %s cannot be used as it does not have an allowed file type. Allowed types include: %s', 'woocommerce' ), $variation_id, '<code>' . basename( $file_url ) . '</code>', '<code>' . implode( ', ', array_keys( $allowed_file_types ) ) . '</code>' ) );
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Validate the file exists
|
||||
if ( 'relative' === $file_is && ! apply_filters( 'woocommerce_downloadable_file_exists', file_exists( $file_url ), $file_url ) ) {
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( 'The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce' ), '<code>' . $file_url . '</code>' ) );
|
||||
WC_Admin_Meta_Boxes::add_error( sprintf( __( '#%s – The downloadable file %s cannot be used as it does not exist on the server.', 'woocommerce' ), $variation_id, '<code>' . $file_url . '</code>' ) );
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -2591,6 +2591,9 @@ class WC_AJAX {
|
|||
die( -1 );
|
||||
}
|
||||
|
||||
// Remove previous meta box errors
|
||||
WC_Admin_Meta_Boxes::$meta_box_errors = array();
|
||||
|
||||
$product_id = absint( $_POST['product_id'] );
|
||||
WC_Meta_Box_Product_Data::save_variations( $product_id, get_post( $product_id ) );
|
||||
|
||||
|
@ -2598,6 +2601,20 @@ class WC_AJAX {
|
|||
|
||||
// Clear cache/transients
|
||||
wc_delete_product_transients( $product_id );
|
||||
|
||||
if ( $errors = WC_Admin_Meta_Boxes::$meta_box_errors ) {
|
||||
echo '<div id="woocommerce_errors" class="error">';
|
||||
|
||||
foreach ( $errors as $error ) {
|
||||
echo '<p>' . wp_kses_post( $error ) . '</p>';
|
||||
}
|
||||
|
||||
echo '</div>';
|
||||
|
||||
delete_option( 'woocommerce_meta_box_errors' );
|
||||
}
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue