3

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?

2
  • Actually it is not about the change you make but about the products that is missing data when imported and the save action adding that data. I would guess the import listes store IDs that don't exist in the current store or something along those lines Commented Apr 28, 2015 at 21:07
  • 1
    The root cause is one of three things: 1) contents of the table catalog_category_product is bogus. 2) flat products is enabled but it doesn't reindex properly. 3) No products are saleable, meaning you have no stock and stock management is on or they are disabled for the storeview. You can diagnose nr.3 by enabling flat products for a given storeview and building the index. If no products are entered in that table (catalog_product_flat_store_X where X is the number of the storeview) then no products are saleable.
    – user4351
    Commented Apr 28, 2015 at 21:54

1 Answer 1

6

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();
6
  • 3
    This won't do anything without at least calling one magic "set" method, preferably setIsChanged(true) as that is the flag magento uses to see if anything changed at all. Secondly, you will want to set all indexes to manual before starting this and that can be done in this script. Last but certainly not least, you will be breaking more then you fix with only this code. addAttributeToSelect() is not enough to trigger _afterLoad() which setups various links so your save (and _afterSave()) will be incomplete. You will need to call $product->load($product->getId()) to do this.
    – user4351
    Commented Apr 28, 2015 at 21:42
  • 1
    3. Good catch. I forgot to include that (that's why i said to increase memory limit).
    – laketuna
    Commented Apr 28, 2015 at 22:05
  • 1
    I've written something similar (synchronizing URL keys for mobile and desktop storeview) and for large catalog ended up using the collection iterator as I busted through 4G php memory loading that collection. Since you have to ->load() anyway, you can save some by not adding any attributes in the collection (entity_id should be added by getCollection() regardless, but do verify). See Mage_Core_Model_Resource_Iterator.
    – user4351
    Commented Apr 28, 2015 at 22:15
  • stackoverflow.com/questions/12440047/…
    – Julian
    Commented Apr 29, 2015 at 8:51
  • And if you want to trigger event you can put it after $product->save();. Mage::dispatchEvent('catalog_product_prepare_save', array('product' => $product)); Commented Jan 26, 2016 at 11:32

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.