0

I am trying to test custom layered navigation filter (catalogsearch controller) functions and creating bulk products like this in my test:

    for ($i = 0; $i < $productNumber; $i++) {
            // random data generation
            $productInstance->setData($conditionsData);
            $productInstance->setName($randomTitle)
                ->setTypeId('virtual')
                ->setDescription($randomDesc)
                ->setSku($randomDesc)
                ->setAttributeSetId(4)
                ->setStatus(96)
                ->setVisibity(4)
                ->setPrice(rand(777,999))
                ->save();

            Mage::getModel('catalog/product_website')->addProducts(array(1), array($productInstance->getId()));
            Mage::getSingleton('catalogsearch/fulltext')->rebuildIndex(1, $productInstance->getId());
        }

I noticted when dispatching a catalogsearch/result/index request it is making query to catalog_category_product_index and catalog_product_index_price but this is a test case and these tables are empty, so i am trying to build index like following:

      $indexCodes = array('catalog_product_attribute',
        'catalog_product_price',
        'catalog_url',
        'catalog_product_flat',
        'catalog_category_flat',
        'catalog_category_product',
        'cataloginventory_stock',
        'filter_attribute',
        'tag_summary');


    foreach ($indexCodes as $indexCodeSingle) {
                $index = Mage::getSingleton('index/indexer')->getProcessByCode($indexCodeSingle);
                $index->reindexEverything();
            }

But after running indexing code my catalog_category_product_index and catalog_product_index_price are empty, why ? Maybe I forgot to add some attributes to to products while creating them ?

1 Answer 1

0

In this case I was required to have catalog_product_price index built, so far it depends on cataloginventory_stock which required stock parameters in product creation:

productInstance->setName($randomTitle)
                    ->setDescription($randomDesc)
                    ->setWebsiteIds(array(1))
                    ->setStoreId(1)
                    ->setTypeId('virtual')
                    ->setOriginalLanguage(array_rand($langs))
                    ->setSku($randomDesc)
                    ->setStockData(array(
                            'use_config_manage_stock' => 1, // 'Use config settings' checkbox
                            'is_in_stock' => 1, //Stock Availability
                            'qty' => 1
                        )
                    )
                    ->setAttributeSetId(4)
                    ->setStatus(1)
                    ->setVisibity(4)
                    ->setPrice(rand(777, 999))
                    ->save();

Seems like virtual product stock also required to be configured.

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.