2

Been stuck on this for hours spinning my wheels. I have script that builds some products based off a CSV. First it builds a few simple products, then a configurable product with those simple products assigned to it. Everything works fine, except the configurable product will not show up on the frontend without either opening it and saving it in the admin after the script, or running an re-index. Here are the facts so far:

The simple products show up fine.

The configurable product WILL show up correctly if I assign it to simple products previously created instead of the simple products in the same script run. This includes simple products created B

I am using the admin store set

Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);

I did try changing the index setting before and then after the script

$processes = Mage::getSingleton('index/indexer')->getProcessesCollection();
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_MANUAL));
$processes->walk('save');
script
$processes->walk('reindexAll');
$processes->walk('setMode', array(Mage_Index_Model_Process::MODE_REAL_TIME));
$processes->walk('save');

So the only thing left I can think to do is add a button that the user can press when they're all done that starts the indexing process, but that takes for ever with the product database that we have now, so I was really hoping to avoid having to do that.

3

My guess is that in System > Configuration > Catalog > Frontend you have turned on Use flat catalog?

Because Magento uses a lot of tables to store product data is generates flat tables so frontend rendering gets a bit faster. This means that if your product isn't indexed into the flat table yet it won't show up on frontend.

When you're saving a product in the backend Magento will automatically reindex for you. If you go to System > Index management you'll see the mode is set to Update on save. This means everytime you change a product Magento will reindex. If you're changing a lot of products on a daily basis from the backend it might be smart to change this to manual update which will make Magento save products a lot faster.

enter image description here

To answer your question, the fact that your products don't show up after importing only AFTER reindexing is not a bug, it's a feature.

Take a look at this comment on how to refresh your indexes programmaticaly. In your case refreshing index 4 and 5, the flat indexes, would be enough I guess

$process = Mage::getModel('index/indexer')->load(4);
$process->reindexAll();
$process = Mage::getModel('index/indexer')->load(5);
$process->reindexAll();
  • Ah thanks for the info. I do have them all set to Update on save, and Use flat catalog was not enabled. Knowing at least which indexes to update and how to would still actually help me out a lot, so I tried what you wrote there but got the error: Fatal error: Call to undefined method Mage_Index_Model_Indexer::load() in /public_html/productadmin/addproduct.php on line 286 – jron Sep 5 '13 at 12:51
  • sorry, my mistake, it's not load but getProcessById -.- Or get all of them by calling getProcessesCollection – Sander Mangel Sep 5 '13 at 12:53
  • Ok, that worked, and I know it ran because it took about 5 minutes to finish, but the configurable product still didn't show up :( could it be a different index? – jron Sep 5 '13 at 13:01
  • 1
    Ok, it looks like I lied. Apparently the code setting the indexer to manual mode, and then back to real time, prior to reindexing all, was preventing it from working. Thanks! I'll keep tweaking this then. I was still hoping to do it without having to reindex at all, but I'll just have to create a button for them to push when they're all done adding products it looks like. – jron Sep 5 '13 at 14:20
  • 1
    Agh, unfortunately this doesn't always seem to be reliable either, ran again and got Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error: 1205 Lock wait timeout exceeded; try restarting transaction' Do you think this should all be working without having to bother with indexing and that it's a problem with the import? I've looked through several tutorials the best that I could on saving products this way... it's so weird that it will work fine if I attach the configurable to already-made products, but not ones made in the same run. – jron Sep 5 '13 at 14:38

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.