Merge pull request #15956 from woocommerce/add-cart-readdition-notice

Use ajax when restoring an item in the cart
This commit is contained in:
Claudio Sanches 2017-07-04 16:35:23 -03:00 committed by GitHub
commit ee87024d82
4 changed files with 36 additions and 3 deletions

File diff suppressed because one or more lines are too long

View File

@ -266,6 +266,7 @@ jQuery( function( $ ) {
this.remove_coupon_clicked = this.remove_coupon_clicked.bind( this );
this.quantity_update = this.quantity_update.bind( this );
this.item_remove_clicked = this.item_remove_clicked.bind( this );
this.item_restore_clicked = this.item_restore_clicked.bind( this );
this.update_cart = this.update_cart.bind( this );
$( document ).on(
@ -291,6 +292,10 @@ jQuery( function( $ ) {
'click',
'.woocommerce-cart-form .product-remove > a',
this.item_remove_clicked );
$( document ).on(
'click',
'.woocommerce-cart .restore-item',
this.item_restore_clicked );
$( document ).on(
'change input',
'.woocommerce-cart-form .cart_item :input',
@ -528,6 +533,34 @@ jQuery( function( $ ) {
block( $form );
block( $( 'div.cart_totals' ) );
$.ajax( {
type: 'GET',
url: $a.attr( 'href' ),
dataType: 'html',
success: function( response ) {
update_wc_div( response );
},
complete: function() {
unblock( $form );
unblock( $( 'div.cart_totals' ) );
}
} );
},
/**
* Handle when a restore item link is clicked.
*
* @param {Object} evt The JQuery event
*/
item_restore_clicked: function( evt ) {
evt.preventDefault();
var $a = $( evt.currentTarget );
var $form = $( 'form.woocommerce-cart-form' );
block( $form );
block( $( 'div.cart_totals' ) );
$.ajax( {
type: 'GET',
url: $a.attr( 'href' ),

File diff suppressed because one or more lines are too long

View File

@ -462,7 +462,7 @@ class WC_Form_Handler {
// Don't show undo link if removed item is out of stock.
if ( $product->is_in_stock() && $product->has_enough_stock( $cart_item['quantity'] ) ) {
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '">' . __( 'Undo?', 'woocommerce' ) . '</a>';
$removed_notice .= ' <a href="' . esc_url( WC()->cart->get_undo_url( $cart_item_key ) ) . '" class="restore-item">' . __( 'Undo?', 'woocommerce' ) . '</a>';
} else {
$removed_notice = sprintf( __( '%s removed.', 'woocommerce' ), $item_removed_title );
}