5

Randomly, when I add something to cart from the product page, I am redirected to the cart page and told I have nothing in my cart. This doesn't happen consistently – if I refresh the cache (magento cache:clean), I'm able to add to cart again as normal (item is added to mini cart and I'm shown the confirmation message at the top of the product page).

Unfortunately, for no reason (that I can find), after using the site for a short period after the cache refresh, I run into the issue again!

I've disabled my custom theme and also the modules I've created, but it continues to happen.

I've checked the session, which appears to be blank on the times the cart fails to update.

Any help/advice/ideas where to look, would be extremely helpful.

1 Answer 1

1

This may be due to corrupted database data.

Have you tried to truncate, analyse and repair both persistant_session and session table?

NOTE: This will empty all guest carts

It is important to always verify both the server and Magento logs var/log

Computer / Browser Related

I'm surprised that clearing Magento cache affected the issue positively, I would usually aim for the browser cache when it comes to session. This can also be a problem related to a specific computer having issues with cookie management. You may try with different computers and browsers.

Core file restoration / Fresh Installation

If this does not resolve the issue I would create a complete backup of the filsystem and copy the files from an original Magento installation over the Magento installation overriding all core files with the originals. This may resolve the issue in the case the problem would be caused by modified core files. On the other side if your actual installation relies on modified core files, these changes would be lost. Pay attention not to overwrite the .htaccess file with the default one. You may also try to install a fresh copy of the same Magento version elsewhere and test it to see if your are experiencing the same behavior.

File System Ownership / Permissions

This type of issue may arise when there is a file ownership issue. As Magento 2 maintenance can be done via command line, some ownership issues may appear if the wrong user or root was used to execute the maintenance script. This is a common problem among Magento 2 developers/store managers.

File permissions can also prevent Magento from reading/writing files in some folders therefore preventing further script execution. It is important to evaluate each folder specifically while maintaining the balance between security and flexibility and to never set the file permission to 777.

You may find useful this official Magento guide regarding the subject.

Server Software / Hardware

If the issue persist, we may think of a php or server misconfiguration, or even a hardware failure.

11
  • Many thanks for you your response. To test the issue, I installed a new 'clean' version of M2. The problem also exists on the clean version too – it tends to just happen when trying to add configurable products.
    – Mitch7663
    Commented Nov 14, 2016 at 9:13
  • As you installed a fresh M2 version I would suggest to observe these database tables: quote, quote_item and quote_item_option then add products to cart. The tables should reflect the added products and you may be able to notice if something is not registered as it should. If everything end up looking fine in the database it would suggest either a Magento 2 bug or a server misconfig causing cookie/session issues. May I know which Magento and php version are you currently using? Something also important, when intalling Magento did you chose file or database session storage?
    – ElGatito
    Commented Nov 14, 2016 at 15:55
  • Thank you, I'll have a look at the DB. I'm currently using: PHP 7.0.10 and Magento ver. 2.1.2. I'm not sure what session storage I chose. Is there a way to check now?
    – Mitch7663
    Commented Nov 14, 2016 at 16:06
  • I see that you are using the latest Magento 2 version and a stable php version. Yes, the easiest way to verify is by looking at the session variable in app/etc/env.php or if the var/session folder isn't empty then you are using the file system, otherwise the session table is used. It is recommanded to use the DB as it can store more sessions and comes with multiple advantages. Thinking about the Page Cache, have you tried disabling it? Without assumption, it is important to test the installation with different computers/browsers. It is often the source of this type of issues.
    – ElGatito
    Commented Nov 14, 2016 at 16:26
  • app/etc/env.php is session => array ( 'save' => 'files' ). I don't seem to have the var/session folder. I have all caches enabled except for full page cache, I disabled that as it was slowing me down whilst developing.
    – Mitch7663
    Commented Nov 14, 2016 at 16:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.