Magento API: Rebuild Indexes after adding new products -


i writing script lets me import multiple products in magento.

$product = mage::getmodel('catalog/product'); $product->setsku($data['sku']); //etc etc $product->save(); 

the product gets created won't show in frontend until either save in backend (without changing anything!) or rebuild indexes in backend.

i did diff on relevant database tables see what's changing when save product , added fields import script, did not have effect. imported product has ok since shows when rebuild indexes via backend manually.

caching disabled.

now question is: how can rebuild indexes after importing products?

you can use such model in index module.

$processes = mage::getsingleton('index/indexer')->getprocessescollection(); $processes->walk('reindexall'); 

since need rebuild indexes, there no filters aplied collection. can filter index processes list set of parameters (code, last time re-indexed, etc) via addfieldtofilter($field, $condition) method.

small suggestion

would great set indexes manual mode while importing products, speed import process, because of them observe product saving event , takes time. can in following way:

$processes = mage::getsingleton('index/indexer')->getprocessescollection(); $processes->walk('setmode', array(mage_index_model_process::mode_manual)); $processes->walk('save'); // here goes // importing process // ................ $processes->walk('reindexall'); $processes->walk('setmode', array(mage_index_model_process::mode_real_time)); $processes->walk('save'); 

Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -