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.
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityIf 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/*
Those who don't wish to change the localhost url and doesn't want to add vhost for this problem. Here's the quick fix.
The problem is due to form_key mismatch. The form key which gets posted during add to cart action is getting mismatched with store session form key.
Go to
vendor/magento/module-checkout/Controller/Cart/Add.php execute()
method. and comment out the first If condition.
**NOTE:**This is not a recommended solution for Production environment.
I am using Mac and I faced this issue using localhost as URL for Magento 2 instances. This is a quick fix if you made a new instance and/or trying to debug something quickly...
Following this answer posted above in this thread fixed my issue.
Sounds like it could be a session based issue, are you able to log into the magento admin or a customer account?
Anything in any of the logs pointing towards the add to cart functions?