Skip to content

Commit

Permalink
Fix undo on storefront
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejolley committed May 3, 2016
1 parent e073f2b commit b39ec6b
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
8 changes: 4 additions & 4 deletions assets/js/admin/quick-edit.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*global ajaxurl, inlineEditPost, inlineEditL10n */
/*global ajaxurl, inlineEditPost, inlineEditL10n, woocommerce_admin */
jQuery(function( $ ) {
$( '#the-list' ).on( 'click', '.editinline', function() {

Expand Down Expand Up @@ -27,9 +27,9 @@ jQuery(function( $ ) {
tax_status = $wc_inline_data.find( '.tax_status' ).text(),
tax_class = $wc_inline_data.find( '.tax_class' ).text(),
backorders = $wc_inline_data.find( '.backorders' ).text();
var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point),
formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point);

var formatted_regular_price = regular_price.replace('.', woocommerce_admin.mon_decimal_point ),
formatted_sale_price = sale_price.replace('.', woocommerce_admin.mon_decimal_point );

$( 'input[name="_sku"]', '.inline-edit-row' ).val( sku );
$( 'input[name="_regular_price"]', '.inline-edit-row' ).val( formatted_regular_price );
Expand Down
2 changes: 1 addition & 1 deletion assets/js/admin/quick-edit.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 20 additions & 12 deletions assets/js/frontend/cart.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,32 @@ jQuery( function( $ ) {
var $html = $.parseHTML( html_str );
var $new_form = $( 'table.shop_table.cart', $html ).closest( 'form' );

// Error message collection
var $error = $( '.woocommerce-error', $html );
var $message = $( '.woocommerce-message', $html );

// Remove errors
$( '.woocommerce-error, .woocommerce-message' ).remove();

if ( $new_form.length === 0 ) {
// No items to display now! Replace all cart content.
var $cart_html = $( '.cart-empty', $html ).closest( '.woocommerce' );
$( 'table.shop_table.cart' ).closest( '.woocommerce' ).replaceWith( $cart_html );

if ( $error.length > 0 ) {
show_notice( $error, $( '.cart-empty' ).closest( '.woocommerce' ) );
} else if ( $message.length > 0 ) {
show_notice( $message, $( '.cart-empty' ).closest( '.woocommerce' ) );
}
} else {
var $error = $( '.woocommerce-error', $html );
var $message = $( '.woocommerce-message', $html );
$( 'table.shop_table.cart' ).closest( 'form' ).replaceWith( $new_form );
$( 'table.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true );

if ( $error.length > 0 ) {
show_notice( $error );
} else if ( $message.length > 0 ) {
show_notice( $message );
} else {
// No new message/error, just remove existing one.
$( '.woocommerce-error, .woocommerce-message' ).remove();
}

$( 'table.shop_table.cart' ).closest( 'form' ).replaceWith( $new_form );
$( 'table.shop_table.cart' ).closest( 'form' ).find( 'input[name="update_cart"]' ).prop( 'disabled', true );
}
};

Expand All @@ -91,11 +98,12 @@ jQuery( function( $ ) {
*
* @param {Object} The Notice HTML Element in string or object form.
*/
var show_notice = function( html_element ) {
var $form = $( 'table.shop_table.cart' ).closest( 'form' );

var show_notice = function( html_element, $target ) {
if ( ! $target ) {
$target = $( 'table.shop_table.cart' ).closest( 'form' );
}
$( '.woocommerce-error, .woocommerce-message' ).remove();
$form.before( html_element );
$target.before( html_element );
};


Expand Down
Loading

0 comments on commit b39ec6b

Please sign in to comment.