Magento Database – Simple Way to Re-Save All Products

categorydatabaseproduct

I imported a complete magento database. Every product and category is shown as it should in the backend. But, when trying to open a category in the storefront the end-user gets the "there are no products matching the selection" error, and no product is displayed.

I also tried re-indexing, and clearing the cache without solving the problem. And I did what other questioners did (There are no products matching the selection)

In my case the solution is to to go to the product-page in the backend. Make a little change, and to save the product. By doing this the product will be shown in the category.

The problem is that I have thousands of products.

What's the most fast way to re-save all products?

Best Answer

As Sander has mentioned, you're likely missing some data (unclear what importing a complete magento database entails). One option is to just run through all of the products and save them programmatically. This should work. Save your DB before running it. It is a Magento shell script, so you need to place it at shell/my_script.php and run it from the CLI. Increase runtime PHP memory if necessary.

require_once 'abstract.php';

class Resave_Products extends Mage_Shell_Abstract
{
    public function run()
    {
        $collection = Mage::getModel('catalog/product')->getCollection()
            ->addAttributeToSelect('id');

        foreach ($collection as $product) {
            $product = Mage::getModel('catalog/product')->load($product->getId())
            $product->save();
        }
    }
}

$shell = new Resave_Products();
$shell->run();
Related Topic