Magento 2 I want to update cart quantity using ajax, how can I do this?Magento 2 : How do I create my own...

How to prevent users from executing commands through browser URL

Can a hotel cancel a confirmed reservation?

Publishing research using outdated methods

Early credit roll before the end of the film

Which one of these password policies is more secure?

Find some digits of factorial 17

Can a person refuse a presidential pardon?

Does paint affect EMI ability of enclosure?

Pronunciation of umlaut vowels in the history of German

Can an insurance company drop you after receiving a bill and refusing to pay?

Using only 1s, make 29 with the minimum number of digits

Why would the Pakistan airspace closure cancel flights not headed to Pakistan itself?

Can making a creature unable to attack after it has been assigned as an attacker remove it from combat?

Eww, those bytes are gross

What are "industrial chops"?

Why is oil called more viscous than water when we slip on oil more than we do on water

What is the lore-based reason that the Spectator has the Create Food and Water trait, instead of simply not requiring food and water?

Can I string the D&D Starter Set campaign into another module, keeping the same characters?

Could a phylactery of a lich be a mirror or does it have to be a box?

How can I get my players to come to the game session after agreeing to a date?

Are there any modern advantages of a fire piston?

How to avoid being sexist when trying to employ someone to function in a very sexist environment?

Word or phrase for showing great skill at something WITHOUT formal training in it

Why would space fleets be aligned?



Magento 2 I want to update cart quantity using ajax, how can I do this?


Magento 2 : How do I create my own action in controller to call url from Ajax in Magento 2.xHow can bind jQuery to current document in Magento 2 When template load by ajaxcustom add to cart button using ajax not rendering top minicart in magento 2Magento 2 : How to improve ajax call?Magento 2 - Send form data to Controller using AJAX and return Result to PHTMLMagento 2 - Update quantity and totals of cart page without page reload?Magento 2: Not receiving all post params in ajax callI can not get data from AJAX (jQuery Widget)Ajax request on add to cart magento 2How to return value from knouckout js Ajax call













0















I have a controller, from where I can send cart quantity. And I used ajax call to fetch data



require([
'jquery'
], function($){
jQuery.ajax({
url: "/mycart/cartcount",
type: "POST",
data: "",
success: function (res) {
jQuery(".cart_qty").html(result);
}
});
});


My question is, how can I get cart quantity in my controller?










share|improve this question







New contributor




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

























    0















    I have a controller, from where I can send cart quantity. And I used ajax call to fetch data



    require([
    'jquery'
    ], function($){
    jQuery.ajax({
    url: "/mycart/cartcount",
    type: "POST",
    data: "",
    success: function (res) {
    jQuery(".cart_qty").html(result);
    }
    });
    });


    My question is, how can I get cart quantity in my controller?










    share|improve this question







    New contributor




    Asim Ali 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








      I have a controller, from where I can send cart quantity. And I used ajax call to fetch data



      require([
      'jquery'
      ], function($){
      jQuery.ajax({
      url: "/mycart/cartcount",
      type: "POST",
      data: "",
      success: function (res) {
      jQuery(".cart_qty").html(result);
      }
      });
      });


      My question is, how can I get cart quantity in my controller?










      share|improve this question







      New contributor




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












      I have a controller, from where I can send cart quantity. And I used ajax call to fetch data



      require([
      'jquery'
      ], function($){
      jQuery.ajax({
      url: "/mycart/cartcount",
      type: "POST",
      data: "",
      success: function (res) {
      jQuery(".cart_qty").html(result);
      }
      });
      });


      My question is, how can I get cart quantity in my controller?







      magento2






      share|improve this question







      New contributor




      Asim Ali 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 question







      New contributor




      Asim Ali 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 question




      share|improve this question






      New contributor




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









      asked 50 mins ago









      Asim AliAsim Ali

      297




      297




      New contributor




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





      New contributor





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






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






















          1 Answer
          1






          active

          oldest

          votes


















          0














          You can't simply update the qty field in the quote_item table because there is lots of constrains that has.




          1. Validate requested qty exist or not.

          2. Is the product is In-Stock or not.

          3. Is the product enabled or not and so.


          and yes you can update the quantity field in quote table.



          Try this, add this in your controller and you need to get item_id and qty to update the specific field.



          <?php                                                                 
          namespace VendorModuleControllerIndex;
          class Save extends MagentoFrameworkAppActionAction
          {
          public function __construct(
          MagentoFrameworkAppActionContext $context,
          MagentoQuoteApiCartRepositoryInterface $quote,
          array $data = []
          ) {
          $this->quoteRepository = $quote;
          parent::__construct($context, $data);
          }
          public function execute()
          {
          $item_id = '6';
          $qty = '10';
          $quote = $this->quoteRepository->getById($item_id);
          foreach ($quote->getItems() as $quoteItem) {
          $quoteItem->setQty($qty);
          }
          $quote->save();
          return true;
          }}


          Hope this will help you :)






          share|improve this answer























            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
            });


            }
            });






            Asim Ali is a new contributor. Be nice, and check out our Code of Conduct.










            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f263964%2fmagento-2-i-want-to-update-cart-quantity-using-ajax-how-can-i-do-this%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can't simply update the qty field in the quote_item table because there is lots of constrains that has.




            1. Validate requested qty exist or not.

            2. Is the product is In-Stock or not.

            3. Is the product enabled or not and so.


            and yes you can update the quantity field in quote table.



            Try this, add this in your controller and you need to get item_id and qty to update the specific field.



            <?php                                                                 
            namespace VendorModuleControllerIndex;
            class Save extends MagentoFrameworkAppActionAction
            {
            public function __construct(
            MagentoFrameworkAppActionContext $context,
            MagentoQuoteApiCartRepositoryInterface $quote,
            array $data = []
            ) {
            $this->quoteRepository = $quote;
            parent::__construct($context, $data);
            }
            public function execute()
            {
            $item_id = '6';
            $qty = '10';
            $quote = $this->quoteRepository->getById($item_id);
            foreach ($quote->getItems() as $quoteItem) {
            $quoteItem->setQty($qty);
            }
            $quote->save();
            return true;
            }}


            Hope this will help you :)






            share|improve this answer




























              0














              You can't simply update the qty field in the quote_item table because there is lots of constrains that has.




              1. Validate requested qty exist or not.

              2. Is the product is In-Stock or not.

              3. Is the product enabled or not and so.


              and yes you can update the quantity field in quote table.



              Try this, add this in your controller and you need to get item_id and qty to update the specific field.



              <?php                                                                 
              namespace VendorModuleControllerIndex;
              class Save extends MagentoFrameworkAppActionAction
              {
              public function __construct(
              MagentoFrameworkAppActionContext $context,
              MagentoQuoteApiCartRepositoryInterface $quote,
              array $data = []
              ) {
              $this->quoteRepository = $quote;
              parent::__construct($context, $data);
              }
              public function execute()
              {
              $item_id = '6';
              $qty = '10';
              $quote = $this->quoteRepository->getById($item_id);
              foreach ($quote->getItems() as $quoteItem) {
              $quoteItem->setQty($qty);
              }
              $quote->save();
              return true;
              }}


              Hope this will help you :)






              share|improve this answer


























                0












                0








                0







                You can't simply update the qty field in the quote_item table because there is lots of constrains that has.




                1. Validate requested qty exist or not.

                2. Is the product is In-Stock or not.

                3. Is the product enabled or not and so.


                and yes you can update the quantity field in quote table.



                Try this, add this in your controller and you need to get item_id and qty to update the specific field.



                <?php                                                                 
                namespace VendorModuleControllerIndex;
                class Save extends MagentoFrameworkAppActionAction
                {
                public function __construct(
                MagentoFrameworkAppActionContext $context,
                MagentoQuoteApiCartRepositoryInterface $quote,
                array $data = []
                ) {
                $this->quoteRepository = $quote;
                parent::__construct($context, $data);
                }
                public function execute()
                {
                $item_id = '6';
                $qty = '10';
                $quote = $this->quoteRepository->getById($item_id);
                foreach ($quote->getItems() as $quoteItem) {
                $quoteItem->setQty($qty);
                }
                $quote->save();
                return true;
                }}


                Hope this will help you :)






                share|improve this answer













                You can't simply update the qty field in the quote_item table because there is lots of constrains that has.




                1. Validate requested qty exist or not.

                2. Is the product is In-Stock or not.

                3. Is the product enabled or not and so.


                and yes you can update the quantity field in quote table.



                Try this, add this in your controller and you need to get item_id and qty to update the specific field.



                <?php                                                                 
                namespace VendorModuleControllerIndex;
                class Save extends MagentoFrameworkAppActionAction
                {
                public function __construct(
                MagentoFrameworkAppActionContext $context,
                MagentoQuoteApiCartRepositoryInterface $quote,
                array $data = []
                ) {
                $this->quoteRepository = $quote;
                parent::__construct($context, $data);
                }
                public function execute()
                {
                $item_id = '6';
                $qty = '10';
                $quote = $this->quoteRepository->getById($item_id);
                foreach ($quote->getItems() as $quoteItem) {
                $quoteItem->setQty($qty);
                }
                $quote->save();
                return true;
                }}


                Hope this will help you :)







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered 38 mins ago









                Prathap GunasekaranPrathap Gunasekaran

                667213




                667213






















                    Asim Ali is a new contributor. Be nice, and check out our Code of Conduct.










                    draft saved

                    draft discarded


















                    Asim Ali is a new contributor. Be nice, and check out our Code of Conduct.













                    Asim Ali is a new contributor. Be nice, and check out our Code of Conduct.












                    Asim Ali is a new contributor. Be nice, and check out our Code of Conduct.
















                    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%2f263964%2fmagento-2-i-want-to-update-cart-quantity-using-ajax-how-can-i-do-this%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

                    “%fieldName is a required field.”, in Magento2 REST API Call for GET Method Type The Next...

                    How to change City field to a dropdown in Checkout step Magento 2Magento 2 : How to change UI field(s)...

                    變成蝙蝠會怎樣? 參考資料 外部連結 导航菜单Thomas Nagel, "What is it like to be a...