I would like to show javascript alert once the product is successfuly added to the cart. How could I achieve it?


See here: Pop up minicart when I add a product to the cart magento 2

This will run some javascript to open the mini-cart when product added to cart. Change the script to have your pop up instead of expanding the cart. e.g.

define(["jquery/ui","jquery"], function(Component, $){
return function(config, element){
    var minicart = $(element);
    minicart.on('contentLoading', function () {
        minicart.on('contentUpdated', function () {
            //popup javascript here
            alert("ADDED SOMETHING TO CART");
  • This seems to target the minicart changing and not the product being added to cart, wouldn't your fix mean the alert shows if the cart is modified another way? – Ben Crook May 22 '17 at 16:22
  • Yeah true was just a quick idea. I know that it will only work on Ajax add to cart and that remove from cart ect require page reload so wont fire it. Unsure how to get around knowing when the cart has been updated. – harri May 22 '17 at 16:50
  • I think looking at the checkout/cart/add controller will be the better resolution, but I don't have any time to look into that at the moment :( – Ben Crook May 22 '17 at 16:52
  • Something like this: blog.chapagain.com.np/… – harri May 22 '17 at 16:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.