How to enable AJAX for the the 'Add to Cart' button of product widgets in Magento 2.2.3?(Solved) How to reach “add to cart” button and price inside Recently Viewed Products Widget in magento 2Magento 2.2.3 Minicart missing proceed to checkout texthow to install free theme using magento 2.2.3 with linux?Magento 2.2.3 Related Products add to cart button issueMagento 2 : When adding 10 (or any number) products to cart with the same sku is there a way to not increment?Private sales events issueIs the Magento Catalog List Product widget supports “Sort by Position”?How to add AJAX for the 'Add to Cart' button in wishlist page and in sidebar wishlist product in produst list page in Magento 2.2.3?Best Seller Block (links not working) - Magento 2.2

I preordered a game on my Xbox while on the home screen of my friend's account. Which of us owns the game?

A strange hotel

How bug prioritization works in agile projects vs non agile

Why do real positive eigenvalues result in an unstable system? What about eigenvalues between 0 and 1? or 1?

Prove that the countable union of countable sets is also countable

std::unique_ptr of base class holding reference of derived class does not show warning in gcc compiler while naked pointer shows it. Why?

What is the term for a person whose job is to place products on shelves in stores?

Suing a Police Officer Instead of the Police Department

Restricting the options of a lookup field, based on the value of another lookup field?

A faster way to compute the largest prime factor

Why must Chinese maps be obfuscated?

How much cash can I safely carry into the USA and avoid civil forfeiture?

What does "function" actually mean in music?

Where was the County of Thurn und Taxis located?

Do I need to watch Ant-Man and the Wasp and Captain Marvel before watching Avengers: Endgame?

Multiple fireplaces in an apartment building?

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

Negative Resistance

Why did C use the -> operator instead of reusing the . operator?

What does a straight horizontal line above a few notes, after a changed tempo mean?

Can a level 2 Warlock take one level in rogue, then continue advancing as a warlock?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

How can I wire a 9-position switch so that each position turns on one more LED than the one before?

All ASCII characters with a given bit count



How to enable AJAX for the the 'Add to Cart' button of product widgets in Magento 2.2.3?


(Solved) How to reach “add to cart” button and price inside Recently Viewed Products Widget in magento 2Magento 2.2.3 Minicart missing proceed to checkout texthow to install free theme using magento 2.2.3 with linux?Magento 2.2.3 Related Products add to cart button issueMagento 2 : When adding 10 (or any number) products to cart with the same sku is there a way to not increment?Private sales events issueIs the Magento Catalog List Product widget supports “Sort by Position”?How to add AJAX for the 'Add to Cart' button in wishlist page and in sidebar wishlist product in produst list page in Magento 2.2.3?Best Seller Block (links not working) - Magento 2.2






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








1















In Magento 2 the normal Add to Cart button has a very nice AJAX-based logic to add products to the cart.
However, when we use a Catalog Products List widget for example in CMS pages in the Home Page the button in this products list works with an HTTP POST which reloads the current page.
I want to add Ajax add to cart in grid.phtml in home page(Widget).



User experience suffers from this and it would be desirable if the button would have the same AJAX logic like in the default category product lists or on product pages.










share|improve this question




























    1















    In Magento 2 the normal Add to Cart button has a very nice AJAX-based logic to add products to the cart.
    However, when we use a Catalog Products List widget for example in CMS pages in the Home Page the button in this products list works with an HTTP POST which reloads the current page.
    I want to add Ajax add to cart in grid.phtml in home page(Widget).



    User experience suffers from this and it would be desirable if the button would have the same AJAX logic like in the default category product lists or on product pages.










    share|improve this question
























      1












      1








      1








      In Magento 2 the normal Add to Cart button has a very nice AJAX-based logic to add products to the cart.
      However, when we use a Catalog Products List widget for example in CMS pages in the Home Page the button in this products list works with an HTTP POST which reloads the current page.
      I want to add Ajax add to cart in grid.phtml in home page(Widget).



      User experience suffers from this and it would be desirable if the button would have the same AJAX logic like in the default category product lists or on product pages.










      share|improve this question














      In Magento 2 the normal Add to Cart button has a very nice AJAX-based logic to add products to the cart.
      However, when we use a Catalog Products List widget for example in CMS pages in the Home Page the button in this products list works with an HTTP POST which reloads the current page.
      I want to add Ajax add to cart in grid.phtml in home page(Widget).



      User experience suffers from this and it would be desirable if the button would have the same AJAX logic like in the default category product lists or on product pages.







      magento2.2.3






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked May 8 '18 at 12:53







      user66118



























          2 Answers
          2






          active

          oldest

          votes


















          1














          You have to override new_grid.phtml file



          app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/widget/new/content/new_grid.phtml


          Now Just Add



          <script type="text/x-magento-init">

          "[data-role=tocart-form], .form.map.checkout":
          "catalogAddToCart":
          "bindSubmit": true






          And write your Add to Cart button under the form.Just Replace
          form



          <?php 
          $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
          $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
          ?>
          <button class="action tocart primary" data-post='<?= /* @escapeNotVerified */ $postData ?>' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
          <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
          </button>


          To



          <?php
          $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
          $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
          $widgetdata = json_decode($postData);
          //var_dump($mydata->action);
          ?>
          <form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_item->getSku() ?>" action="<?= /* @NoEscape */ $widgetdata->action ?>" method="post">
          <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $widgetdata->data->product ?>">
          <!--<input type="hidden" name="<? //= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<? //= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">-->
          <?= $block->getBlockHtml('formkey') ?>
          <button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
          <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
          </button>
          </form>





          share|improve this answer
































            0














            I Found this free extension from Tigren that adds ajax support to add to cart button in widgets ,
            here is the link to it link to free extension



            note: if you don't like the popup you can disable it from the admin dashboard



            hope this will help someone in need






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



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f225166%2fhow-to-enable-ajax-for-the-the-add-to-cart-button-of-product-widgets-in-magent%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














              You have to override new_grid.phtml file



              app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/widget/new/content/new_grid.phtml


              Now Just Add



              <script type="text/x-magento-init">

              "[data-role=tocart-form], .form.map.checkout":
              "catalogAddToCart":
              "bindSubmit": true






              And write your Add to Cart button under the form.Just Replace
              form



              <?php 
              $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
              $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
              ?>
              <button class="action tocart primary" data-post='<?= /* @escapeNotVerified */ $postData ?>' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
              <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
              </button>


              To



              <?php
              $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
              $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
              $widgetdata = json_decode($postData);
              //var_dump($mydata->action);
              ?>
              <form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_item->getSku() ?>" action="<?= /* @NoEscape */ $widgetdata->action ?>" method="post">
              <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $widgetdata->data->product ?>">
              <!--<input type="hidden" name="<? //= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<? //= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">-->
              <?= $block->getBlockHtml('formkey') ?>
              <button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
              <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
              </button>
              </form>





              share|improve this answer





























                1














                You have to override new_grid.phtml file



                app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/widget/new/content/new_grid.phtml


                Now Just Add



                <script type="text/x-magento-init">

                "[data-role=tocart-form], .form.map.checkout":
                "catalogAddToCart":
                "bindSubmit": true






                And write your Add to Cart button under the form.Just Replace
                form



                <?php 
                $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                ?>
                <button class="action tocart primary" data-post='<?= /* @escapeNotVerified */ $postData ?>' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
                <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                </button>


                To



                <?php
                $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
                $widgetdata = json_decode($postData);
                //var_dump($mydata->action);
                ?>
                <form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_item->getSku() ?>" action="<?= /* @NoEscape */ $widgetdata->action ?>" method="post">
                <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $widgetdata->data->product ?>">
                <!--<input type="hidden" name="<? //= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<? //= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">-->
                <?= $block->getBlockHtml('formkey') ?>
                <button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
                <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                </button>
                </form>





                share|improve this answer



























                  1












                  1








                  1







                  You have to override new_grid.phtml file



                  app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/widget/new/content/new_grid.phtml


                  Now Just Add



                  <script type="text/x-magento-init">

                  "[data-role=tocart-form], .form.map.checkout":
                  "catalogAddToCart":
                  "bindSubmit": true






                  And write your Add to Cart button under the form.Just Replace
                  form



                  <?php 
                  $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                  $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                  ?>
                  <button class="action tocart primary" data-post='<?= /* @escapeNotVerified */ $postData ?>' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
                  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                  </button>


                  To



                  <?php
                  $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                  $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
                  $widgetdata = json_decode($postData);
                  //var_dump($mydata->action);
                  ?>
                  <form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_item->getSku() ?>" action="<?= /* @NoEscape */ $widgetdata->action ?>" method="post">
                  <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $widgetdata->data->product ?>">
                  <!--<input type="hidden" name="<? //= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<? //= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">-->
                  <?= $block->getBlockHtml('formkey') ?>
                  <button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
                  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                  </button>
                  </form>





                  share|improve this answer















                  You have to override new_grid.phtml file



                  app/design/frontend/vendorname/themename/Magento_Catalog/templates/product/widget/new/content/new_grid.phtml


                  Now Just Add



                  <script type="text/x-magento-init">

                  "[data-role=tocart-form], .form.map.checkout":
                  "catalogAddToCart":
                  "bindSubmit": true






                  And write your Add to Cart button under the form.Just Replace
                  form



                  <?php 
                  $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                  $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()])
                  ?>
                  <button class="action tocart primary" data-post='<?= /* @escapeNotVerified */ $postData ?>' type="button" title="<?= /* @escapeNotVerified */ __('Add to Cart') ?>">
                  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                  </button>


                  To



                  <?php
                  $postDataHelper = $this->helper('MagentoFrameworkDataHelperPostHelper');
                  $postData = $postDataHelper->getPostData($block->getAddToCartUrl($_item), ['product' => $_item->getEntityId()]);
                  $widgetdata = json_decode($postData);
                  //var_dump($mydata->action);
                  ?>
                  <form data-role="tocart-form" data-product-sku="<?= /* @NoEscape */ $_item->getSku() ?>" action="<?= /* @NoEscape */ $widgetdata->action ?>" method="post">
                  <input type="hidden" name="product" value="<?= /* @escapeNotVerified */ $widgetdata->data->product ?>">
                  <!--<input type="hidden" name="<? //= /* @escapeNotVerified */ Action::PARAM_NAME_URL_ENCODED ?>" value="<? //= /* @escapeNotVerified */ $postParams['data'][Action::PARAM_NAME_URL_ENCODED] ?>">-->
                  <?= $block->getBlockHtml('formkey') ?>
                  <button type="submit" title="<?= $block->escapeHtml(__('Add to Cart')) ?>" class="action tocart primary">
                  <span><?= /* @escapeNotVerified */ __('Add to Cart') ?></span>
                  </button>
                  </form>






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Sep 14 '18 at 5:33









                  Piyush

                  4,85972054




                  4,85972054










                  answered Sep 14 '18 at 5:25









                  AfreenAfreen

                  313110




                  313110























                      0














                      I Found this free extension from Tigren that adds ajax support to add to cart button in widgets ,
                      here is the link to it link to free extension



                      note: if you don't like the popup you can disable it from the admin dashboard



                      hope this will help someone in need






                      share|improve this answer



























                        0














                        I Found this free extension from Tigren that adds ajax support to add to cart button in widgets ,
                        here is the link to it link to free extension



                        note: if you don't like the popup you can disable it from the admin dashboard



                        hope this will help someone in need






                        share|improve this answer

























                          0












                          0








                          0







                          I Found this free extension from Tigren that adds ajax support to add to cart button in widgets ,
                          here is the link to it link to free extension



                          note: if you don't like the popup you can disable it from the admin dashboard



                          hope this will help someone in need






                          share|improve this answer













                          I Found this free extension from Tigren that adds ajax support to add to cart button in widgets ,
                          here is the link to it link to free extension



                          note: if you don't like the popup you can disable it from the admin dashboard



                          hope this will help someone in need







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 21 at 10:59









                          mahmudy-91mahmudy-91

                          165




                          165



























                              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%2f225166%2fhow-to-enable-ajax-for-the-the-add-to-cart-button-of-product-widgets-in-magent%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

                              Bulk add to cart function issuecart vs. mini cart issue … rwd themeRedirect Add to cart button to cart pageAdd to cart issue - Magento 2.1The requested Payment Method is not available When creating an orderM2: reason add-to-cart might not function in production modeAdd to cart issue in some android devicesMagento 2 - custom price can not add to subtotal and grand total after add to cartAdd to cart codeIssue with my cart module on pdp and cart pages, just keeps spinningBulk price and quantity update using rest api

                              Magento2 - How to hide price filter only in specific categories?Multiselect price filter attribute in layered navigationhide only some categories from layered navigation in magentoRemove Price Filter on certain categoriescustomize layered price filter?Hide Price for a particular customer groupPrice filter in layered navigation not working correctly with price including tax in magento 2.2.3Magento 2 how to hide attribute at Layered navigation?Magento 2. how to hide price only for specific categoriesMagento 2 How can I hide the price and total from cart and checkout summary?Magento2: Can we add navigation layered filter like price filter for other attribute?