Skip to content

Commit

Permalink
Add onBeforeAddProductToCart and onAfterAddProductToCart events. onBe…
Browse files Browse the repository at this point in the history
…foreAddProductToCart allows event handlers to stop the event by returning false.
  • Loading branch information
flaviocopes committed Apr 24, 2016
1 parent bfba41b commit 24421c7
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/shoppingcart_cart_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,16 @@
button.attr('disabled', 'disabled');
var i = 0;

var onBeforeAddProductToCart;
$(document).trigger(onBeforeAddProductToCart = $.Event('onBeforeAddProductToCart', { product: ShoppingCart.currentProduct }));
if (onBeforeAddProductToCart.result === false) {
return;
}

// Deep copy
var product = jQuery.extend(true, {}, ShoppingCart.currentProduct);

$(ShoppingCart).trigger('onAfterAddProductToCart', product);

ShoppingCart.addProduct(product, quantity);
button.html(window.PLUGIN_SHOPPINGCART.translations.PRODUCT_ADDED_TO_CART);
Expand All @@ -87,7 +94,6 @@
button.html(window.PLUGIN_SHOPPINGCART.translations.ADD_TO_CART);
button.attr('disabled', null);
}, 2000);

});

/***********************************************************/
Expand Down

0 comments on commit 24421c7

Please sign in to comment.