From 24421c7a645d525ee9b145a2b83f9feb519c6c80 Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Sun, 24 Apr 2016 13:09:49 +0200 Subject: [PATCH] Add onBeforeAddProductToCart and onAfterAddProductToCart events. onBeforeAddProductToCart allows event handlers to stop the event by returning false. --- js/shoppingcart_cart_events.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/js/shoppingcart_cart_events.js b/js/shoppingcart_cart_events.js index 877ec84..d130535 100644 --- a/js/shoppingcart_cart_events.js +++ b/js/shoppingcart_cart_events.js @@ -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); @@ -87,7 +94,6 @@ button.html(window.PLUGIN_SHOPPINGCART.translations.ADD_TO_CART); button.attr('disabled', null); }, 2000); - }); /***********************************************************/