Magento – Products not showing up in frontend or backend but are enabled and stored correctly in flat table

import

Magento 1.5.1.0

We have a store with about 70,000 active products. Some of the products are showing up in the frontend, but not in the backend. When trying to access one of those products in the backend using its id (see "hack" below), I was told the product no longer existed.

Products may have been deleted using the admin import option for deleting. But I don't think so.

I came upon the problem while trying to update a bunch of products. I received the following error:

Product Type is invalid or not supported in rows: 

with a list of about 500 rows.

The whole csv was formatted the same way. I cannot find any problems with the sku field, but it appears that the system is not recognizing them as existing products.

I tried searching for one of those products in the backend and got no results, whether using sku, name, or id range. I tried this backend "hack" where you click on a product, then replace the id in the url with the id of the product you want to see. But submitting that url resulted in this error:

This product no longer exists.

But the product is searchable on the front end and appears in the catalog and product page.

I traced the This product no longer exists. error to this file, where $product->getId() is returning false.:

app/code/core/Mage/Adminhtml/controllers/Catalog/ProductController.php

Here's the first part of the function where the error is generated:

public function editAction()
    {
        $productId  = (int) $this->getRequest()->getParam('id');
        $product = $this->_initProduct();

        if ($productId && !$product->getId()) {
            $this->_getSession()->addError(Mage::helper('catalog')->__('This product no longer exists.'));
            $this->_redirect('*/*/');
            return;
        }

The Product Type is invalid or not supported in rows error is generated in this file:

/app/code/core/Mage/ImportExport/Import/Entity/Product.php

in public function validateRow around line 1433, with this code:

if (!isset($rowData[self::COL_TYPE])
                    || !isset($this->_productTypeModels[$rowData[self::COL_TYPE]])
                ) {
                    $this->addRowError(self::ERROR_INVALID_TYPE, $rowNum);

which is itself contained inside the else statement of this if block:

if (isset($this->_oldSku[$sku])) { 

And what that apparently means is that the code did not locate the sku in that array (where skus are keys).

But the product appears in the product flat table, even after reindex.
A query for the all ghost items' status shows they are all enabled:

SELECT value, COUNT(*) FROM catalog_product_entity_int WHEREattribute_id = 84 AND entity_id IN (75962, … etc)
) GROUP BY value

Any ideas?

Best Answer

Since the flat table is generated from eav tables as a way speed up the frontend, it's possible that there is a discrepancy between that and the original tables. The next step for debugging would probably be to do a search for a sku where you know this problem is occurring in the catalog_product_entity table. If it's not there, it was probably deleted in one way or another.

If you don't have a recent db backup and want those products back, your best bet is probably to use a previous import file or to salvage what you can from the flat table.