Add Ajax Quantity Increment and Decrement Button on mini cart in Magento 2





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}







2















I want to implement Ajax Quantity Increment and Decrement Button functionality on cart items on Minicart. I didn't find any article or any module to achieve this. as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.Could anyone help me with it?










share|improve this question























  • magento.stackexchange.com/questions/216496/…

    – Mukesh Prajapati
    Oct 20 '18 at 5:35











  • Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

    – trilok kumar
    Oct 20 '18 at 6:05











  • yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

    – Mukesh Prajapati
    Oct 20 '18 at 6:18











  • magearray.com/enhanced-mini-cart.html This is available module for that

    – Mukesh Prajapati
    Oct 20 '18 at 6:21











  • Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

    – trilok kumar
    Oct 20 '18 at 6:23


















2















I want to implement Ajax Quantity Increment and Decrement Button functionality on cart items on Minicart. I didn't find any article or any module to achieve this. as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.Could anyone help me with it?










share|improve this question























  • magento.stackexchange.com/questions/216496/…

    – Mukesh Prajapati
    Oct 20 '18 at 5:35











  • Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

    – trilok kumar
    Oct 20 '18 at 6:05











  • yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

    – Mukesh Prajapati
    Oct 20 '18 at 6:18











  • magearray.com/enhanced-mini-cart.html This is available module for that

    – Mukesh Prajapati
    Oct 20 '18 at 6:21











  • Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

    – trilok kumar
    Oct 20 '18 at 6:23














2












2








2








I want to implement Ajax Quantity Increment and Decrement Button functionality on cart items on Minicart. I didn't find any article or any module to achieve this. as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.Could anyone help me with it?










share|improve this question














I want to implement Ajax Quantity Increment and Decrement Button functionality on cart items on Minicart. I didn't find any article or any module to achieve this. as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.Could anyone help me with it?







magento2 magento-2.1.7 mini-cart






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Oct 20 '18 at 4:33









trilok kumartrilok kumar

16710




16710













  • magento.stackexchange.com/questions/216496/…

    – Mukesh Prajapati
    Oct 20 '18 at 5:35











  • Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

    – trilok kumar
    Oct 20 '18 at 6:05











  • yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

    – Mukesh Prajapati
    Oct 20 '18 at 6:18











  • magearray.com/enhanced-mini-cart.html This is available module for that

    – Mukesh Prajapati
    Oct 20 '18 at 6:21











  • Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

    – trilok kumar
    Oct 20 '18 at 6:23



















  • magento.stackexchange.com/questions/216496/…

    – Mukesh Prajapati
    Oct 20 '18 at 5:35











  • Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

    – trilok kumar
    Oct 20 '18 at 6:05











  • yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

    – Mukesh Prajapati
    Oct 20 '18 at 6:18











  • magearray.com/enhanced-mini-cart.html This is available module for that

    – Mukesh Prajapati
    Oct 20 '18 at 6:21











  • Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

    – trilok kumar
    Oct 20 '18 at 6:23

















magento.stackexchange.com/questions/216496/…

– Mukesh Prajapati
Oct 20 '18 at 5:35





magento.stackexchange.com/questions/216496/…

– Mukesh Prajapati
Oct 20 '18 at 5:35













Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

– trilok kumar
Oct 20 '18 at 6:05





Thanks for comments Mukesh Prajapati but i need as qty increment(+) and decrement(-) inside the mini cart product price and the total must change without clicking on update.

– trilok kumar
Oct 20 '18 at 6:05













yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

– Mukesh Prajapati
Oct 20 '18 at 6:18





yes, from above link you can add increment and increment functionality after that you have to write custom ajax code to update mini cart via ajax.

– Mukesh Prajapati
Oct 20 '18 at 6:18













magearray.com/enhanced-mini-cart.html This is available module for that

– Mukesh Prajapati
Oct 20 '18 at 6:21





magearray.com/enhanced-mini-cart.html This is available module for that

– Mukesh Prajapati
Oct 20 '18 at 6:21













Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

– trilok kumar
Oct 20 '18 at 6:23





Thanks for comments Mukesh Prajapati the above link extension link doesn't contains demo

– trilok kumar
Oct 20 '18 at 6:23










2 Answers
2






active

oldest

votes


















1














We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.



<?php
<input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
?>



app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml




Increase by one:



<?php
<a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
?>


Decrease by one:



<?php
<a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
?>


Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -




app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml




function changeItemQuantity( id , num ) {
var qty_id = "cart[" + id + "][qty]";
var currentVal = parseInt( $(qty_id).value );
if ( currentVal != NaN )
{
$(qty_id).value = currentVal + num;
$("products-table-basket").submit();
}
}


enter image description here



References




  1. https://tomrobertshaw.net/2010/08/add-increase-and-decrease-quantity-buttons-to-items-in-magento-cart/

  2. https://www.magearray.com/enhanced-mini-cart.html

  3. https://community.magento.com/t5/Magento-2-x-Programming/Update-Cart-automatically-Using-Increment-and-decrement-Button/td-p/104958






share|improve this answer
























  • Thanks for comment Aditya Shah but code does not works for me.

    – trilok kumar
    Oct 22 '18 at 5:53











  • This is reference you need to enhance it

    – Aaditya
    Oct 22 '18 at 5:58











  • Aditya Shah can you please elaborate how can I get it

    – trilok kumar
    Oct 22 '18 at 6:00













  • Okay,just a min

    – Aaditya
    Oct 22 '18 at 6:25











  • You can consult a way to ajax re-load block totals in cart.

    – Aaditya
    Oct 22 '18 at 6:26



















0














You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.



https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement





share
























    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%2f247176%2fadd-ajax-quantity-increment-and-decrement-button-on-mini-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









    1














    We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.



    <?php
    <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
    ?>



    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml




    Increase by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Decrease by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -




    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml




    function changeItemQuantity( id , num ) {
    var qty_id = "cart[" + id + "][qty]";
    var currentVal = parseInt( $(qty_id).value );
    if ( currentVal != NaN )
    {
    $(qty_id).value = currentVal + num;
    $("products-table-basket").submit();
    }
    }


    enter image description here



    References




    1. https://tomrobertshaw.net/2010/08/add-increase-and-decrease-quantity-buttons-to-items-in-magento-cart/

    2. https://www.magearray.com/enhanced-mini-cart.html

    3. https://community.magento.com/t5/Magento-2-x-Programming/Update-Cart-automatically-Using-Increment-and-decrement-Button/td-p/104958






    share|improve this answer
























    • Thanks for comment Aditya Shah but code does not works for me.

      – trilok kumar
      Oct 22 '18 at 5:53











    • This is reference you need to enhance it

      – Aaditya
      Oct 22 '18 at 5:58











    • Aditya Shah can you please elaborate how can I get it

      – trilok kumar
      Oct 22 '18 at 6:00













    • Okay,just a min

      – Aaditya
      Oct 22 '18 at 6:25











    • You can consult a way to ajax re-load block totals in cart.

      – Aaditya
      Oct 22 '18 at 6:26
















    1














    We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.



    <?php
    <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
    ?>



    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml




    Increase by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Decrease by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -




    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml




    function changeItemQuantity( id , num ) {
    var qty_id = "cart[" + id + "][qty]";
    var currentVal = parseInt( $(qty_id).value );
    if ( currentVal != NaN )
    {
    $(qty_id).value = currentVal + num;
    $("products-table-basket").submit();
    }
    }


    enter image description here



    References




    1. https://tomrobertshaw.net/2010/08/add-increase-and-decrease-quantity-buttons-to-items-in-magento-cart/

    2. https://www.magearray.com/enhanced-mini-cart.html

    3. https://community.magento.com/t5/Magento-2-x-Programming/Update-Cart-automatically-Using-Increment-and-decrement-Button/td-p/104958






    share|improve this answer
























    • Thanks for comment Aditya Shah but code does not works for me.

      – trilok kumar
      Oct 22 '18 at 5:53











    • This is reference you need to enhance it

      – Aaditya
      Oct 22 '18 at 5:58











    • Aditya Shah can you please elaborate how can I get it

      – trilok kumar
      Oct 22 '18 at 6:00













    • Okay,just a min

      – Aaditya
      Oct 22 '18 at 6:25











    • You can consult a way to ajax re-load block totals in cart.

      – Aaditya
      Oct 22 '18 at 6:26














    1












    1








    1







    We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.



    <?php
    <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
    ?>



    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml




    Increase by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Decrease by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -




    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml




    function changeItemQuantity( id , num ) {
    var qty_id = "cart[" + id + "][qty]";
    var currentVal = parseInt( $(qty_id).value );
    if ( currentVal != NaN )
    {
    $(qty_id).value = currentVal + num;
    $("products-table-basket").submit();
    }
    }


    enter image description here



    References




    1. https://tomrobertshaw.net/2010/08/add-increase-and-decrease-quantity-buttons-to-items-in-magento-cart/

    2. https://www.magearray.com/enhanced-mini-cart.html

    3. https://community.magento.com/t5/Magento-2-x-Programming/Update-Cart-automatically-Using-Increment-and-decrement-Button/td-p/104958






    share|improve this answer













    We can make it easier by adding +1 and -1 links to change the quantity of each item. We will do this with some very simple JavaScript which takes the current value and adjusts it. Once this has been done, we submit the form through JavaScript to reduce customer effort.



    <?php
    <input name="cart[<?php echo $_item->getId() ?>][qty]" value="<?php echo $this->getQty() ?>" size="4" title="<?php echo $this->__('Qty') ?>" class="input-text qty" maxlength="12" id="cart[<?php echo $_item->getId() ?>][qty]"/>
    ?>



    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart/item/default.phtml




    Increase by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, 1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Decrease by one:



    <?php
    <a onclick="changeItemQuantity( <?php echo $_item->getId() ?>, -1 ); return false;" href="#"><img alt="add-arw" src="<?php echo $this->getSkinUrl('images/add-arw.png') ?>"></a>
    ?>


    Now the JavaScript function. We do not want it duplicated for every item so you can either put it in your theme’s JavaScript file or just below the table in the parent template -




    app/design/frontend/[interface_name]/[theme_name]/template/checkout/cart.phtml




    function changeItemQuantity( id , num ) {
    var qty_id = "cart[" + id + "][qty]";
    var currentVal = parseInt( $(qty_id).value );
    if ( currentVal != NaN )
    {
    $(qty_id).value = currentVal + num;
    $("products-table-basket").submit();
    }
    }


    enter image description here



    References




    1. https://tomrobertshaw.net/2010/08/add-increase-and-decrease-quantity-buttons-to-items-in-magento-cart/

    2. https://www.magearray.com/enhanced-mini-cart.html

    3. https://community.magento.com/t5/Magento-2-x-Programming/Update-Cart-automatically-Using-Increment-and-decrement-Button/td-p/104958







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Oct 20 '18 at 12:07









    AadityaAaditya

    4,20121139




    4,20121139













    • Thanks for comment Aditya Shah but code does not works for me.

      – trilok kumar
      Oct 22 '18 at 5:53











    • This is reference you need to enhance it

      – Aaditya
      Oct 22 '18 at 5:58











    • Aditya Shah can you please elaborate how can I get it

      – trilok kumar
      Oct 22 '18 at 6:00













    • Okay,just a min

      – Aaditya
      Oct 22 '18 at 6:25











    • You can consult a way to ajax re-load block totals in cart.

      – Aaditya
      Oct 22 '18 at 6:26



















    • Thanks for comment Aditya Shah but code does not works for me.

      – trilok kumar
      Oct 22 '18 at 5:53











    • This is reference you need to enhance it

      – Aaditya
      Oct 22 '18 at 5:58











    • Aditya Shah can you please elaborate how can I get it

      – trilok kumar
      Oct 22 '18 at 6:00













    • Okay,just a min

      – Aaditya
      Oct 22 '18 at 6:25











    • You can consult a way to ajax re-load block totals in cart.

      – Aaditya
      Oct 22 '18 at 6:26

















    Thanks for comment Aditya Shah but code does not works for me.

    – trilok kumar
    Oct 22 '18 at 5:53





    Thanks for comment Aditya Shah but code does not works for me.

    – trilok kumar
    Oct 22 '18 at 5:53













    This is reference you need to enhance it

    – Aaditya
    Oct 22 '18 at 5:58





    This is reference you need to enhance it

    – Aaditya
    Oct 22 '18 at 5:58













    Aditya Shah can you please elaborate how can I get it

    – trilok kumar
    Oct 22 '18 at 6:00







    Aditya Shah can you please elaborate how can I get it

    – trilok kumar
    Oct 22 '18 at 6:00















    Okay,just a min

    – Aaditya
    Oct 22 '18 at 6:25





    Okay,just a min

    – Aaditya
    Oct 22 '18 at 6:25













    You can consult a way to ajax re-load block totals in cart.

    – Aaditya
    Oct 22 '18 at 6:26





    You can consult a way to ajax re-load block totals in cart.

    – Aaditya
    Oct 22 '18 at 6:26













    0














    You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.



    https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement





    share




























      0














      You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.



      https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement





      share


























        0












        0








        0







        You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.



        https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement





        share













        You can download the extension and installed it for minicart Ajax Quantity Increment and Decrement Button.



        https://github.com/kirtinariya1/MinicartAjaxQtyIncrementDecrement






        share











        share


        share










        answered 6 mins ago









        Kirti NariyaKirti Nariya

        1,173415




        1,173415






























            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%2f247176%2fadd-ajax-quantity-increment-and-decrement-button-on-mini-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

            What other Star Trek series did the main TNG cast show up in?

            Berlina muro

            Berlina aerponto