cancel
Showing results for 
Search instead for 
Did you mean: 

Indexing oh Indexing...Why have you forsaken me?

Indexing oh Indexing...Why have you forsaken me?

I'm having a lttle trouble understanding the indexing schema I've put in place.  The behaviour is not what I expected...perhaps someone can shed a little light?

 

I have an auto load feature that uses MAGMI to load CSV files of inventory quantities for several locations...no problem, everything loads as expected.  Once the CSV load is complete I programmatically reindex everything...I've used two methods:

 

1) 

$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_attribute');$indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_url'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_flat'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_category_flat'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalog_category_product'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('catalogsearch_fulltext'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('cataloginventory_stock'); $indexer->reindexEverything();
$indexer = Mage::getModel('index/indexer')->getProcessByCode('tag_summary'); $indexer->reindexEverything();

 

2) 

$indexCollection = Mage::getModel('index/process')->getCollection();
  foreach ($indexCollection as $index) {
  /* @var $index Mage_Index_Model_Process */
  $index->reindexAll();
}

 

Both work fine, and the reindex can be verified by checking the index management page.  After the reindex I also clear the cache with:

 

  Mage::app()->getCacheInstance()->flush();

  Mage::app()->cleanCache();

 

All is gravy up until this point...inventories are updated and show up on the front end as expected, the issue is the following:

 

Out-of-stock items, quantity=0, items ALSO show up, even though the settings in the back-end are to hide out-of stock items.  What really confuses me though is, if I go to the index manager and reindex the "Product Prices" by hand the "Product Prices" and "Stock Status" are reindexed and all is well; the out-of-stock items are once again hidden.  Apparently, "Product Prices" has a dependency on "Stock Status," or vise-versa.

 

I tried to call the "Product Price" reindex a second time programmatically to emulate what I was doing, but the out-of-stock items still show up.  Needless to say, this behavior is aggravating...please help if you have insight.  I simply want to load inventory, reindex, clear cache, then have out-of-stock items hidden...easy peasy...

 

Thanks a bunch-

DraftAssassin

 

4 REPLIES

Re: Indexing oh Indexing...Why have you forsaken me?

If you don't have shell_exec disabled in your php.ini, then try this:

 

<?php
$storePath = '/var/www/yourstorepath';
$command = '/usr/bin/php ' . $storePath . '/shell/indexer.php --reindex all';
shell_exec($command);
?>

You can replace "all" onto:

catalog_product_attribute
catalog_product_price
catalog_url
catalog_product_flat
catalog_category_flat
catalog_category_product
catalogsearch_fulltext
cataloginventory_stock
tag_summary

-------Store Manager for Magento 1.x and 2.x - enhances the functionality of default admin web interface, speeds up inventory management, automates daily tasks.

Re: Indexing oh Indexing...Why have you forsaken me?

Unfortunately, the shell_exec is disabled on this server.  Any other hints would be greatly appreciated, and thanks for the response.

 

DraftAssassin

Re: Indexing oh Indexing...Why have you forsaken me?

Try this

 

<?php
require_once 'app/Mage.php';
$app = Mage::app('admin');
umask(0);

$ids = array(1,2,3,4,5,6,7,8,9);

// admin panel-> System-> Index Management
// admin/process/some_id/......

foreach($ids as $id)
{
    try
    {
        $process = Mage::getModel('index/process')->load($id);
        $process->reindexAll();
        echo "Indexing for Process ID # ".$id." Done<br />";
    }
    catch(Exception $e)
    {
        echo $e->getMessage();
    }
}
?>

 

-------Store Manager for Magento 1.x and 2.x - enhances the functionality of default admin web interface, speeds up inventory management, automates daily tasks.

Re: Indexing oh Indexing...Why have you forsaken me?

This is the way to go (without hardcoded id's, codes or shell_exec):

<?php
/* @var $indexer Mage_Index_Model_Indexer */
$indexer = Mage::getSingleton('index/indexer');

foreach ($indexer->getProcessesCollection() as $process) {
    $process->reindexEverything();
}

?>