1

This question already has an answer here:

What would be the best way to create a modal after adding a product to cart (Showing "continue shopping" or "checkout")?

I though about using just JS with event. But, I don't know how to concile this the AJAX result.

marked as duplicate by Amit Bera Sep 11 '18 at 8:55

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

3

You can show ajax popup by extending catalog-add-to-cart.js file of Magento-Catalog module.

Steps to do :

1 - Copy catalog-add-to-cart.js from '\module-catalog\view\frontend\web\js/catalog-add-to-cart.js and place into your theme folder \Package/theme/Magento_Catalog/web/js/catalog-add-to-cart.js

2 - find ajaxSubmit: function and place below code snippet after self.enableAddToCartButton(form);

Code snippet :

//popup code start
                var popup = $('<div class="add-to-cart-dialog"/>').html($('.page-title span').text() + '<span> has been added to cart.</span>').modal({ //get product name from product view page only
                    modalClass: 'add-to-cart-popup',
                    //title: $.mage.__("No Title"),
                    buttons: [
                        {
                            text: 'Continue Shopping',
                            click: function () {
                                this.closeModal();
                            }
                        },
                        {
                            text: 'Proceed to Checkout',
                            click: function () {
                                window.location = window.checkout.checkoutUrl
                            }
                        }
                    ]
                });
                popup.modal('openModal');
                //popup code end

And you are done. deploy-statcic content, flush cache etc

  • Your answer is almost the same than this one : magento.stackexchange.com/questions/150794/… But yours is easier to implement and is perfectly working. Big thanks ! – Morgan Tartreau Sep 11 '18 at 8:37
  • Thanks you got the my answer.. now i am trying to override JS – 55840 Mar 14 at 6:17
  • @SatishVishwakarma, good happy to know if that works for you too, happy coding. – Naveed Asim Mar 14 at 6:31
  • @NaveedAsim, How can we use modal pop up if product is added to cart from custom page from ajax request by passing product id. – jafar pinjar Aug 20 at 7:39

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