Magento2 – Fix Cannot Add Product to Cart Issue

addtocartmagento2

Whenever I tried to add product to cart from list page or product page in fresh setup Magento Ce 2.1 release it redirects to checkout page and no product gets added.

I tried disabling cache also.

Best Answer

If you ran in local and your path is :localhost please replace "localhost" to "127.0.0.1".
Following:
So you can change root URL by SQL query:

UPDATE core_config_data 
SET value = 'http://127.0.0.1/' 
WHERE path IN ('web/secure/base_url', 'web/unsecure/base_url');

It is sufficient for Magento 1.x but not for Magento 2.0. Magento 2.0 for some strange purpose additionally stores root URL in the third path: design/head/includes

The record looks like:

<link  rel="stylesheet" type="text/css"  media="all" href="<root URL>/pub/media/styles.css" />

So you need one more SQL query:

UPDATE core_config_data
SET value = REPLACE(value, '<old root URL or domain>', '<new root URL or domain>')
WHERE path = 'design/head/includes';

For example:

UPDATE core_config_data
SET value = REPLACE(value, 'http://localhost/', 'http://127.0.0.1/')
WHERE path = 'design/head/includes';

Then delete the cache:

rm -rf var/cache/*
Related Topic