get confirmation before removing item from cart in magento 2?












1















I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.



I have tried some examples but still when i click on cancel the item gets removed from cart.



here is the code we need to change:-



<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>


If anyone get the solution?










share|improve this question


















  • 1





    Its already present. Check the demo here: magento2-demo.nexcess.net

    – Sejal Shah
    May 23 '17 at 13:51











  • No, its not already there. You did not get my point

    – Mandar Parbate
    May 24 '17 at 4:19













  • open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

    – Mandar Parbate
    May 24 '17 at 4:21











  • Not for mini-cart

    – Mandar Parbate
    May 24 '17 at 4:22











  • ok..I thought it's for minicart in the header

    – Sejal Shah
    May 24 '17 at 4:39
















1















I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.



I have tried some examples but still when i click on cancel the item gets removed from cart.



here is the code we need to change:-



<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>


If anyone get the solution?










share|improve this question


















  • 1





    Its already present. Check the demo here: magento2-demo.nexcess.net

    – Sejal Shah
    May 23 '17 at 13:51











  • No, its not already there. You did not get my point

    – Mandar Parbate
    May 24 '17 at 4:19













  • open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

    – Mandar Parbate
    May 24 '17 at 4:21











  • Not for mini-cart

    – Mandar Parbate
    May 24 '17 at 4:22











  • ok..I thought it's for minicart in the header

    – Sejal Shah
    May 24 '17 at 4:39














1












1








1








I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.



I have tried some examples but still when i click on cancel the item gets removed from cart.



here is the code we need to change:-



<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>


If anyone get the solution?










share|improve this question














I want to remove the items from cart from
checkoutcart
page, but before that i wanna to get a confirm from user.
it is possible to get confirmation from user after that i can remove the item from cart if he/she click OK, else he/she click cancel it should not delete the item from cart.



I have tried some examples but still when i click on cancel the item gets removed from cart.



here is the code we need to change:-



<a href="#"
title="<?php echo $block->escapeHtml(__('Remove item')); ?>"
class="action action-delete"
data-post='<?php /* @escapeNotVerified */ echo $block->getDeletePostJson(); ?>'>
<span>
<?php /* @escapeNotVerified */ echo __('Remove item')?>
</span>
</a>


If anyone get the solution?







magento2 cart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 23 '17 at 13:15









Mandar ParbateMandar Parbate

155423




155423








  • 1





    Its already present. Check the demo here: magento2-demo.nexcess.net

    – Sejal Shah
    May 23 '17 at 13:51











  • No, its not already there. You did not get my point

    – Mandar Parbate
    May 24 '17 at 4:19













  • open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

    – Mandar Parbate
    May 24 '17 at 4:21











  • Not for mini-cart

    – Mandar Parbate
    May 24 '17 at 4:22











  • ok..I thought it's for minicart in the header

    – Sejal Shah
    May 24 '17 at 4:39














  • 1





    Its already present. Check the demo here: magento2-demo.nexcess.net

    – Sejal Shah
    May 23 '17 at 13:51











  • No, its not already there. You did not get my point

    – Mandar Parbate
    May 24 '17 at 4:19













  • open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

    – Mandar Parbate
    May 24 '17 at 4:21











  • Not for mini-cart

    – Mandar Parbate
    May 24 '17 at 4:22











  • ok..I thought it's for minicart in the header

    – Sejal Shah
    May 24 '17 at 4:39








1




1





Its already present. Check the demo here: magento2-demo.nexcess.net

– Sejal Shah
May 23 '17 at 13:51





Its already present. Check the demo here: magento2-demo.nexcess.net

– Sejal Shah
May 23 '17 at 13:51













No, its not already there. You did not get my point

– Mandar Parbate
May 24 '17 at 4:19







No, its not already there. You did not get my point

– Mandar Parbate
May 24 '17 at 4:19















open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

– Mandar Parbate
May 24 '17 at 4:21





open checkout/cart page and click on delete item icon, you does not get a alert box or confirmation before deleting it

– Mandar Parbate
May 24 '17 at 4:21













Not for mini-cart

– Mandar Parbate
May 24 '17 at 4:22





Not for mini-cart

– Mandar Parbate
May 24 '17 at 4:22













ok..I thought it's for minicart in the header

– Sejal Shah
May 24 '17 at 4:39





ok..I thought it's for minicart in the header

– Sejal Shah
May 24 '17 at 4:39










2 Answers
2






active

oldest

votes


















2














You have to override form.phtml file



app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml


Add below code at last



<script>
require(['jquery', 'jquery/ui'], function($){
jQuery('.action-delete').click(function(e)
{
if(confirm('Do you want to remove this product?'))
{
return true;
}
else
{
return false;
}

});
});
</script>





share|improve this answer


























  • how to do the same with pop up modal ...

    – sangan
    Nov 27 '17 at 9:41



















0














To display confirm box using popup modal,
Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml




  1. Remove data-post from <a> tag for delete product from cart

  2. Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.

  3. Add below code at the bottom of the same file.




<script>
var deleteFromCart;
require([ 'jquery',
'Magento_Customer/js/model/authentication-popup',
'Magento_Ui/js/modal/alert',
'Magento_Ui/js/modal/confirm',
'jquery/ui',
'mage/decorate',
'mage/collapsible',
'mage/cookies'], function($, authenticationPopup, alert, confirm){

deleteFromCart=function(datapass)
{

var data1=datapass;

$.extend(data1.data, {
'form_key': $.mage.cookies.get('form_key')
});

confirm({
content: 'Are you sure you would like to remove this item from the shopping cart?',
actions: {
/** @inheritdoc */
confirm: function () {


$.post({
url: data1.action,
data:data1.data,
showLoader: true,
success: function (res) {
location.reload();
},
error: function (xhr, status, error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
}
});
},

/** @inheritdoc */
always: function (e) {
e.stopImmediatePropagation();
return false;
}
}
});
}

});
</script>





share|improve this answer










New contributor




Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "479"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f175731%2fget-confirmation-before-removing-item-from-cart-in-magento-2%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2














    You have to override form.phtml file



    app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml


    Add below code at last



    <script>
    require(['jquery', 'jquery/ui'], function($){
    jQuery('.action-delete').click(function(e)
    {
    if(confirm('Do you want to remove this product?'))
    {
    return true;
    }
    else
    {
    return false;
    }

    });
    });
    </script>





    share|improve this answer


























    • how to do the same with pop up modal ...

      – sangan
      Nov 27 '17 at 9:41
















    2














    You have to override form.phtml file



    app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml


    Add below code at last



    <script>
    require(['jquery', 'jquery/ui'], function($){
    jQuery('.action-delete').click(function(e)
    {
    if(confirm('Do you want to remove this product?'))
    {
    return true;
    }
    else
    {
    return false;
    }

    });
    });
    </script>





    share|improve this answer


























    • how to do the same with pop up modal ...

      – sangan
      Nov 27 '17 at 9:41














    2












    2








    2







    You have to override form.phtml file



    app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml


    Add below code at last



    <script>
    require(['jquery', 'jquery/ui'], function($){
    jQuery('.action-delete').click(function(e)
    {
    if(confirm('Do you want to remove this product?'))
    {
    return true;
    }
    else
    {
    return false;
    }

    });
    });
    </script>





    share|improve this answer















    You have to override form.phtml file



    app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml


    Add below code at last



    <script>
    require(['jquery', 'jquery/ui'], function($){
    jQuery('.action-delete').click(function(e)
    {
    if(confirm('Do you want to remove this product?'))
    {
    return true;
    }
    else
    {
    return false;
    }

    });
    });
    </script>






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited May 30 '17 at 13:27

























    answered May 30 '17 at 12:55









    Camit1dkCamit1dk

    381117




    381117













    • how to do the same with pop up modal ...

      – sangan
      Nov 27 '17 at 9:41



















    • how to do the same with pop up modal ...

      – sangan
      Nov 27 '17 at 9:41

















    how to do the same with pop up modal ...

    – sangan
    Nov 27 '17 at 9:41





    how to do the same with pop up modal ...

    – sangan
    Nov 27 '17 at 9:41













    0














    To display confirm box using popup modal,
    Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml




    1. Remove data-post from <a> tag for delete product from cart

    2. Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.

    3. Add below code at the bottom of the same file.




    <script>
    var deleteFromCart;
    require([ 'jquery',
    'Magento_Customer/js/model/authentication-popup',
    'Magento_Ui/js/modal/alert',
    'Magento_Ui/js/modal/confirm',
    'jquery/ui',
    'mage/decorate',
    'mage/collapsible',
    'mage/cookies'], function($, authenticationPopup, alert, confirm){

    deleteFromCart=function(datapass)
    {

    var data1=datapass;

    $.extend(data1.data, {
    'form_key': $.mage.cookies.get('form_key')
    });

    confirm({
    content: 'Are you sure you would like to remove this item from the shopping cart?',
    actions: {
    /** @inheritdoc */
    confirm: function () {


    $.post({
    url: data1.action,
    data:data1.data,
    showLoader: true,
    success: function (res) {
    location.reload();
    },
    error: function (xhr, status, error) {
    var err = eval("(" + xhr.responseText + ")");
    console.log(err.Message);
    }
    });
    },

    /** @inheritdoc */
    always: function (e) {
    e.stopImmediatePropagation();
    return false;
    }
    }
    });
    }

    });
    </script>





    share|improve this answer










    New contributor




    Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.

























      0














      To display confirm box using popup modal,
      Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml




      1. Remove data-post from <a> tag for delete product from cart

      2. Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.

      3. Add below code at the bottom of the same file.




      <script>
      var deleteFromCart;
      require([ 'jquery',
      'Magento_Customer/js/model/authentication-popup',
      'Magento_Ui/js/modal/alert',
      'Magento_Ui/js/modal/confirm',
      'jquery/ui',
      'mage/decorate',
      'mage/collapsible',
      'mage/cookies'], function($, authenticationPopup, alert, confirm){

      deleteFromCart=function(datapass)
      {

      var data1=datapass;

      $.extend(data1.data, {
      'form_key': $.mage.cookies.get('form_key')
      });

      confirm({
      content: 'Are you sure you would like to remove this item from the shopping cart?',
      actions: {
      /** @inheritdoc */
      confirm: function () {


      $.post({
      url: data1.action,
      data:data1.data,
      showLoader: true,
      success: function (res) {
      location.reload();
      },
      error: function (xhr, status, error) {
      var err = eval("(" + xhr.responseText + ")");
      console.log(err.Message);
      }
      });
      },

      /** @inheritdoc */
      always: function (e) {
      e.stopImmediatePropagation();
      return false;
      }
      }
      });
      }

      });
      </script>





      share|improve this answer










      New contributor




      Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.























        0












        0








        0







        To display confirm box using popup modal,
        Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml




        1. Remove data-post from <a> tag for delete product from cart

        2. Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.

        3. Add below code at the bottom of the same file.




        <script>
        var deleteFromCart;
        require([ 'jquery',
        'Magento_Customer/js/model/authentication-popup',
        'Magento_Ui/js/modal/alert',
        'Magento_Ui/js/modal/confirm',
        'jquery/ui',
        'mage/decorate',
        'mage/collapsible',
        'mage/cookies'], function($, authenticationPopup, alert, confirm){

        deleteFromCart=function(datapass)
        {

        var data1=datapass;

        $.extend(data1.data, {
        'form_key': $.mage.cookies.get('form_key')
        });

        confirm({
        content: 'Are you sure you would like to remove this item from the shopping cart?',
        actions: {
        /** @inheritdoc */
        confirm: function () {


        $.post({
        url: data1.action,
        data:data1.data,
        showLoader: true,
        success: function (res) {
        location.reload();
        },
        error: function (xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        console.log(err.Message);
        }
        });
        },

        /** @inheritdoc */
        always: function (e) {
        e.stopImmediatePropagation();
        return false;
        }
        }
        });
        }

        });
        </script>





        share|improve this answer










        New contributor




        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.










        To display confirm box using popup modal,
        Edit YOUR_THEME/Magento_Checkout/templates/cart/item/default.phtml




        1. Remove data-post from <a> tag for delete product from cart

        2. Add onclick='deleteFromCart(setItem($_item)->getDeletePostJson($_item) ?>)' in the same tag.

        3. Add below code at the bottom of the same file.




        <script>
        var deleteFromCart;
        require([ 'jquery',
        'Magento_Customer/js/model/authentication-popup',
        'Magento_Ui/js/modal/alert',
        'Magento_Ui/js/modal/confirm',
        'jquery/ui',
        'mage/decorate',
        'mage/collapsible',
        'mage/cookies'], function($, authenticationPopup, alert, confirm){

        deleteFromCart=function(datapass)
        {

        var data1=datapass;

        $.extend(data1.data, {
        'form_key': $.mage.cookies.get('form_key')
        });

        confirm({
        content: 'Are you sure you would like to remove this item from the shopping cart?',
        actions: {
        /** @inheritdoc */
        confirm: function () {


        $.post({
        url: data1.action,
        data:data1.data,
        showLoader: true,
        success: function (res) {
        location.reload();
        },
        error: function (xhr, status, error) {
        var err = eval("(" + xhr.responseText + ")");
        console.log(err.Message);
        }
        });
        },

        /** @inheritdoc */
        always: function (e) {
        e.stopImmediatePropagation();
        return false;
        }
        }
        });
        }

        });
        </script>






        share|improve this answer










        New contributor




        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        share|improve this answer



        share|improve this answer








        edited 27 mins ago





















        New contributor




        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.









        answered Jan 11 at 11:41









        KhushbuKhushbu

        11




        11




        New contributor




        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.





        New contributor





        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






        Khushbu is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f175731%2fget-confirmation-before-removing-item-from-cart-in-magento-2%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Polycentropodidae

            Magento 2 Error message: Invalid state change requested

            Paulmy