2

I've a PHP script that import products from an external XML File using AWS Fast Simple Import, a magento extension.

Every X minutes it call the XML and check if the product is modified or is new, then it updates or create a new product.

The problem is when a product become unavailable. I've already set up the configuration of magento to NOT SHOW the unavailable products but every time the script goes the unavailable products appear on the catalog page.

So I tried to reindex manually the catalog_product_price and if I refresh the catalog page it works correctly.

But when I do it from PHP using this code:

$process = Mage::getModel('index/indexer')->getProcessByCode('catalog_product_price');
$process->reindexAll();

It doesn't work. I mean if I look at the latest index time it works but in the catalog view I still see the unavailable products.

4
  • First, that indexer deals with product price only. Second, by unavailable, do you mean disabled, out of stock or visibility hidden?
    – Prateek
    Commented Aug 7, 2015 at 14:18
  • I mean out of stock. I tried to use other indexer but the only one that works in my case is the price one.. I don't know why. Commented Aug 10, 2015 at 8:36
  • Try reindexEverything() instead of reindexAll() method call, that's what core system call when you trigger indexing from admin. reindexEverything() also calls reindexAll() at the end of execution, so I guess it will also perform some additional tasks. Reason behind this, "I'm still looking into that".
    – Prateek
    Commented Aug 10, 2015 at 16:07
  • tried reindexEverything and nothing happened.. it's really annoying this magento issue. Commented Aug 12, 2015 at 11:44

1 Answer 1

1

I'd the same problem and I change

$process->reindexAll();

for

$process->reindexEverything();

Here is my code

public function reindex($string = 'all')
{
    /** @var $indexer Mage_Index_Model_Indexer */
    $indexer = Mage::getModel('index/indexer');

    $processes = array();

    if ($string == 'all') {
        $processes = $indexer->getProcessesCollection();
    } else {
        $codes = explode(',', $string);
        foreach ($codes as $code) {
            $process = $indexer->getProcessByCode(trim($code));
            if ($process) {
                $processes[] = $process;
            }
        }
    }

    /** @var $process Mage_Index_Model_Process */
    foreach ($processes as $process) {

        $status = $process->getStatus();

        if (($status!=Mage_Index_Model_Process::STATUS_RUNNING) AND !($process->isLocked())){

            //$process->reindexAll();
            $process->reindexEverything();

        }

    }

}
1
  • Thanks Claudio, I'll try since I still haven't resolved the problem. Commented Jan 27, 2016 at 9:38

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.