6

We've created an additional indexer that is started by using the backend indexer functions. We have flat tables enabled. We have multiple storeviews that correspond to different languages.

The following code is an excerpt from the indexer code.

public function rebuildIndex ($productIds) {
  $stores = Mage::app()->getStores();
  foreach ($stores AS $store) {
    Mage::app()->setCurrentStore($store);
    $products = Mage::getModel('catalog/product')
      ->getCollection()
      ->setStore($store)
      ->addAttributeToFilter('status', 1)
      ->addAttributeToFilter('visibility', array ('in' => array (Mage_Catalog_Model_Product_Visibility::VISIBILITY_IN_SEARCH, Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH)))
      ->addAttributeToSelect('*')
      ->setPageSize(1000)
      ->setCurPage(++$page);
  }
}

The problem is that for the second and third store, the products loaded use the language of the first storeview.

We've tried finding out what the problem is. So far, we've seen that when using flat tables, the product flat tables created are these:

  • catalog_product_flat_1
  • catalog_product_flat_2
  • catalog_product_flat_3

The number at the end corresponds to the storeview (and therefor the language). However, in all cases, the generated SELECT statement selects from the first table, making the language of the products loaded in all 3 storeviews the language of the first storeview.

We can't disable flat tables (which we tried, and that fixes the problem). Is there any way to load the products for each of the storeviews?

  • Try adding addStoreFilter() to your product collection after you set the store. I've not seen setStore($store) used before, but I have seen setStoreId($store->getId()) - Not sure if there's gonna be a difference. – pspahn Aug 1 '14 at 18:05
  • Added setStoreId(...) followed by addStoreFilter() to the building of the collection. No change. – 0xCAFEBABE Aug 4 '14 at 6:14
  • @0xCAFEBABE were you able to solve this problem? If so, how? – 7ochem Mar 8 '16 at 13:41
  • 4
    We determined it to be a problem of the flat tables. We inserted a Mage::unregister('_resource_singleton/catalog/product_flat'); right before doing the collection gathering, so the indexing would work around the flat tables. It's usually executed from the command line anyway, so performance wasn't critical. – 0xCAFEBABE Mar 9 '16 at 8:03
  • @0xCAFEBABE, thanks, this solution works fine – Andy Webov Jul 6 '18 at 7:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.