Magento2: Product is added to cart twice the quantity when customer clicks Add To Cart button second time

Created on 12 Jun 2018  路  6Comments  路  Source: magento/magento2


Products are added to the cart twice the quantity, when you click on Add To Cart button more than one.

Preconditions

  1. Ubuntu 18.04
  2. PHP 7.1.18
  3. MySQL 5.7.22
  4. Magento 2.2.4
  5. Google Chrome 67.0.3396.79 or Firefox 60.0.1

Steps to reproduce

  1. Create a simple product in the Magento Admin.
  2. Go to product detail page in Store Front.
  3. Change the quantity to 5.
  4. Click on Add To Cart.
  5. Verify the quantity by looking at the Mini Cart at the upper-right corner.
  6. Click on Add To Cart again.
  7. Verify the quantity is now 15, instead of 10.

Expected result

  1. I expect to add to cart the given quantity whenever I click Add To Cart button.

Actual result

  1. After the first time, it always add the twice the quantity to the cart. When I inspect the network, I see there is two calls.
    screenshot from 2018-06-12 10-18-26
Format is valid

Most helpful comment

Hi @bnymn, thanks for the well written issue!

But I'm going to close it, as it has already been reported before in https://github.com/magento/magento2/issues/15052 & https://github.com/magento/magento2/issues/15580

Quick summary: it's a new bug introduced in one of those new modules from Amazon which get installed by default now in Magento 2.2.4. Quick fix is if you don't need those modules to simply disable them, which should fix your issue. If you don't want to disable those modules, it is mentioned over here that a fix is pending for Magento 2.2.5: https://github.com/amzn/amazon-payments-magento-2-plugin/pull/227

All 6 comments

Hi @bnymn, thanks for the well written issue!

But I'm going to close it, as it has already been reported before in https://github.com/magento/magento2/issues/15052 & https://github.com/magento/magento2/issues/15580

Quick summary: it's a new bug introduced in one of those new modules from Amazon which get installed by default now in Magento 2.2.4. Quick fix is if you don't need those modules to simply disable them, which should fix your issue. If you don't want to disable those modules, it is mentioned over here that a fix is pending for Magento 2.2.5: https://github.com/amzn/amazon-payments-magento-2-plugin/pull/227

Hi,
I am too facing add to cart issue, like adding product twice for second time onwards.

Once disabled Amazon module, works fine, is there any other solutions without disabling module for Magento 2.2.4 .

@vasudevsundar Hey, how did you disable amazon module? I wanna do it correctly, cause i don't use it anywhere

@swishhh, you have two options:

  1. In composer, define that you don't want to download and install those modules, by adding these lines to the composer.json file:
    "replace": {
        "amzn/amazon-pay-and-login-magento-2-module": "*"
    }

Then run composer update, followed by a bin/magento setup:upgrade.

After this, there won't be any trace of the Amazon modules code in your project, there might still be some leftovers in the database though, but that's less important and shouldn't cause problems.

  1. Disable the modules in Magento, by running this command:
    bin/magento module:disable Amazon_Core Amazon_Login Amazon_Payment

After this, the code of the Amazon modules is still in your project, but it is just not active.

You can choose whatever you're most comfortable with :)

@hostep thanks a lot :)

Any one help me how can i add add-to-cart button on CMS. I need Name, Thumbnail Image, Price, Add-to-cart Button On CMS PAGE, here add to cart not woking,

code :

file path: app/desgin/frontend/base/default/template/myphp/myphpcode.phtml

Place the below code

<?php $_productCollection = Mage::getModel('catalog/product')->getCollection()
                ->addAttributeToSelect('*');
?>
<table>
 <tr>
  <th class="prosku">Sku</th>
  <th class="proname">Name</th>
  <th class="proprice">Price</th>
  <th class="proimg">Thumbnail</th>
  <th class="pro-button">Add to Cart Button</th>
 </tr>
<?php 
    if(count($_productCollection)) {
        foreach($_productCollection as $product) {
?>
 <tr>
  <td class="prodsku"><?php echo $product->getSku(); ?></td>
  <td class="prodname"><?php echo $product->getName();?></td>
  <td class="prodprice"><?php echo $product->getPrice();?></td>
  <td class="prodimg"><img src="<?php echo $product->getImageUrl();?>" width="100px" height="100px"/></td>
  <td class="prod-add_to_Cart-button"><?php if($product->isSaleable()): ?>
   <p><button type="button" title="<?php echo Mage::helper('core')->quoteEscape($this->__('Add to Cart')) ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button></p>
   <?php else: ?>
   <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
   <?php endif; ?></td>
 </tr>
<?php
}
    }
?>
 </table>
<style type="text/css">
.prodsku, .prodname, .prodprice,  .prodimg, .prod-add_to_Cart-button{
    padding:10px;
}
.prosku, .proname, .proprice,  .proimg, .pro-button{
    padding:10px;
}
</style>
Was this page helpful?
0 / 5 - 0 ratings