Magento – Magento 2.2.2 add to cart not working after server change

addtocartmagento2.2.2server-setup

Add to cart was not working on local server and it was fixed by changing the base_url in database from "http://localhost/magento2" to "http://127.0.0.1/magento2".

Now after all design changes when this installation was moved to live server, we made the respective changes in DB, env.php and cleared cache.

Every link and all functionalities are working fine except 'Add to cart' functionality has stopped working.

Following are the issues with 'Add to cart':

  1. On category page (product listing page): when 'Add to cart' button is clicked, it directly takes to 'cart' page without adding product to cart.

  2. On Product detail page: When clicked on 'Add to cart' button, its text changes to 'Adding' and it stays the same and product is never added to cart.

There are no errors in console for both of the above scenarios.

Following I have tried:

Deleted following directories:

  • pub\static
  • var\cache
  • var\page_cache
  • var\view_preprocessed
  • var\composer_home

Ran these commands using ssh:

  • php bin/magento setup:static-content:deploy
  • php bin/magento indexer:reindex

And following commands to give magento's default permissions to directories:

  • sudo chmod -R a+wX pub
  • sudo chmod -R a+wX var
  • sudo chmod -R a+wX app
  • sudo chmod -R a+wX app/etc
  • sudo chmod -R a+wX generated

Updated cookie_lifetime to 86400 in admin.

Cleared cache from admin.

But still issue persists.

Please help in resolving this.

Best Answer

Are you using apache? Make sure .htaccess file is been read or else try adding index.php to url.

Also make sure Php rewrite module is enabled.

Related Topic