Merge pull request #13306 from woocommerce/fix-13303

Fix multiple item additon to orders
This commit is contained in:
Mike Jolley 2017-02-23 18:11:02 +00:00 committed by GitHub
commit 04aebd9fa7
4 changed files with 36 additions and 41 deletions

View File

@ -1058,39 +1058,27 @@ jQuery( function ( $ ) {
},
add_item: function( add_item_ids ) {
add_item_ids = add_item_ids.split( ',' );
if ( add_item_ids ) {
var count = add_item_ids.length;
wc_meta_boxes_order_items.block();
$.each( add_item_ids, function( index, value ) {
var data = {
action : 'woocommerce_add_order_item',
item_to_add: add_item_ids,
dataType : 'json',
order_id : woocommerce_admin_meta_boxes.post_id,
security : woocommerce_admin_meta_boxes.order_item_nonce
};
var data = {
action : 'woocommerce_add_order_item',
item_to_add: value,
dataType : 'json',
order_id : woocommerce_admin_meta_boxes.post_id,
security : woocommerce_admin_meta_boxes.order_item_nonce
};
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( response.success ) {
$( 'table.woocommerce_order_items tbody#order_line_items' ).append( response.data.html );
} else {
window.alert( response.data.error );
}
if ( !--count ) {
wc_meta_boxes_order.init_tiptip();
wc_meta_boxes_order_items.unblock();
}
});
$.post( woocommerce_admin_meta_boxes.ajax_url, data, function( response ) {
if ( response.success ) {
$( 'table.woocommerce_order_items tbody#order_line_items' ).append( response.data.html );
} else {
window.alert( response.data.error );
}
wc_meta_boxes_order.init_tiptip();
wc_meta_boxes_order_items.unblock();
});
}
},

File diff suppressed because one or more lines are too long

View File

@ -283,7 +283,7 @@ if ( wc_tax_enabled() ) {
</header>
<article>
<form action="" method="post">
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="add_item_id" name="add_order_items" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>"></select>
<select class="wc-product-search" multiple="multiple" style="width: 50%;" id="add_item_id" name="add_order_items[]" data-placeholder="<?php esc_attr_e( 'Search for a product&hellip;', 'woocommerce' ); ?>"></select>
</form>
</article>
<footer>

View File

@ -744,22 +744,29 @@ class WC_AJAX {
}
try {
$item_to_add = absint( $_POST['item_to_add'] );
$order_id = absint( $_POST['order_id'] );
$order = wc_get_order( $order_id );
$order_id = absint( $_POST['order_id'] );
$order = wc_get_order( $order_id );
$items_to_add = wp_parse_id_list( is_array( $_POST['item_to_add'] ) ? $_POST['item_to_add'] : array( $_POST['item_to_add'] ) );
if ( ! $order || ! in_array( get_post_type( $item_to_add ), array( 'product', 'product_variation' ) ) ) {
throw new Exception( __( 'Invalid product', 'woocommerce' ) );
if ( ! $order ) {
throw new Exception( __( 'Invalid order', 'woocommerce' ) );
}
$item_id = $order->add_product( wc_get_product( $item_to_add ) );
$item = apply_filters( 'woocommerce_ajax_order_item', $order->get_item( $item_id ), $item_id );
$order_taxes = $order->get_taxes();
$class = 'new_row';
ob_start();
do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item );
include( 'admin/meta-boxes/views/html-order-item.php' );
foreach ( $items_to_add as $item_to_add ) {
if ( ! in_array( get_post_type( $item_to_add ), array( 'product', 'product_variation' ) ) ) {
continue;
}
$item_id = $order->add_product( wc_get_product( $item_to_add ) );
$item = apply_filters( 'woocommerce_ajax_order_item', $order->get_item( $item_id ), $item_id );
$order_taxes = $order->get_taxes();
$class = 'new_row';
do_action( 'woocommerce_ajax_add_order_item_meta', $item_id, $item );
include( 'admin/meta-boxes/views/html-order-item.php' );
}
wp_send_json_success( array(
'html' => ob_get_clean(),