Magento is a deep, sophisticated e-commerce platform capable of enterprise level performance. While no system could ever be deemed perfect, Magento is a very well designed system that gives any organization the ability to set up elaborate product configurations. But that complexity can also make bug hunting a little tricky sometimes. Here's a recent case where figuring out why products were disappearing from the front end of a Magento site after updating them took some real work.
Last week we got a call from a business owner frustrated with a chain of events that forced him to change web hosts. In the process of migrating his site, something went wrong. Once the site was up on the new host's server, any time he changed and updated any of the products through the Magento control panel the products would disappear on the front of the site. By the time he'd come to us with his problem, he'd worked with a handful of people to troubleshoot the issue but no one could determine what was wrong.
The problem, simply put, is that when products were updated or reindexed in the Magento control panel, they would disappear from the front of the site when browsing by category. You could navigate to items and see them by entering a specific item's URL, but they weren't appearing in their respective categories. We tried many tips and bits of advice. We:
- Checked inventory levels
- Reindexed our product lists
- Flushed the caches through the control panel
- Emptied the /var/ cache files on server
- Ensured the products were enabled in the product configuration
- Ensured the products were visible in the product configuration
- Checked that products were in the right categories in the cp
Nothing. Damn it, we were thinking, how far are we going to have to go to find this one?
Chris Boyd, Factory's systems engineer, embarked on a trace/reduction style process that involved the following steps. He:
- Drilled down to the first SQL statement and found it was indeed returning the correct number of products
- Determined that the SQL for filtering the products was completely filtering out all the results
- Looked at the SQL a little closer and noticed it was JOINing based on customer group "0"
- Removed the JOIN we discovered that the products showed up as they were supposed to. Restored the JOIN
- Checked the customer groups to ensure that there was, in fact, a group with an ID of "0". No group with ID = 0
- Saw that "not logged in" had an ID of "4"
- Compared "not logged in" ID to other Magento installations and discovered it was "0"
- Updated "not logged in" group ID to "0" on our problem site and everything returned to normal
We're not exactly sure what caused the problem in the first place since the data we were working with had already been exported from the original working site's database before migration.
The final word: if all other troubleshooting efforts fail, check to see that the "not logged in" group ID matches the JOIN in the product lists generated by the SQL query.
The files & methods
Here's list of the files and methods checked in the process outlined earlier: Magento ver. 18.104.22.168
- app/code/core/Mage/Catalog/Model/Layer.php getProductCollection() method, line 101 // gets the products for the current category
- app/code/core/Mage/Catalog/Model/Category.php applyProductLimitations() // gets the product collection for the current category
- app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Collection.php, line 1283