Magento – Add to Cart Not Working – Magento 2

addtocartmagento2

Magento 2.1.2
PHP Version: 5.6.17
MySQL Version: 5.6.33

The store is completely set up, designed and in production mode. Braintree payment method is set up. Categories and products are created. Everything seems to work fine; except "Add to Cart" or checkout.

When I navigate to storefront as a guest and click "Add to Cart" to add the product to cart, it doesn't work– It redirects to a blank page with the error below…

"The page isn’t redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete".

Additional information

I have tried it in all browsers and got the same error result

NOTE: It's a Magento multistore

Any had this issue before? And what could be causing this?

Thanks in advance!

Best Answer

I had this issue and it turned out to be ModSecurity detecting false positives.

I knew it was server-level as I could intentionally put a syntax error in the .htaccess file and yet the redirect loop was still occurring.

Over in WHM, Home » Security Center » ModSecurity™ Tools shows a Hit List. From here it's easy to see what's going on. In my case, rules 981245 and 981246 were being triggered by the mage-messages cookie (urldecoded for convenience)...

mage-messages=[{"type":"success","text":"You added Simple Test Product to your shopping cart."}]

Preg matching on the two rules gave:

Array
(
    [0] => Array
        (
            [0] => ":"success","t
            [1] => ":"You a
        )

)
Array
(
    [0] => Array
        (
            [0] => "type":"
            [1] => "text":"
        )
)

It looks specifically like ":" was the trigger.

Security Center » ModSecurity™ Tools » Rules List allows you to disable individual rules so this is what I did.

Related Topic