protected function _processEvent(Mage_Index_Model_Event $event) { if (!$this->config->getApplicationID() || !$this->config->getAPIKey() || !$this->config->getSearchOnlyAPIKey()) { if (self::$credential_error === false) { Mage::getSingleton('adminhtml/session')->addError('Algolia indexing failed: You need to configure your Algolia credentials in System > Configuration > Algolia Search.'); self::$credential_error = true; } return; } $data = $event->getNewData(); /* * Reindex all products */ if (!empty($data['algoliasearch_reindex_all'])) { $process = $event->getProcess(); $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); } if (!empty($data['catalogsearch_update_category_id'])) { $updateCategoryIds = $data['catalogsearch_update_category_id']; $updateCategoryIds = is_array($updateCategoryIds) ? $updateCategoryIds : array($updateCategoryIds); foreach ($updateCategoryIds as $id) { $categories = Mage::getModel('catalog/category')->getCategories($id); foreach ($categories as $category) { $updateCategoryIds[] = $category->getId(); } } $this->engine->rebuildCategoryIndex(null, $updateCategoryIds); } /* * Reindex products. */ if (!empty($data['catalogsearch_update_product_id'])) { $updateProductIds = $data['catalogsearch_update_product_id']; $updateProductIds = is_array($updateProductIds) ? $updateProductIds : array($updateProductIds); $productIds = $updateProductIds; foreach ($updateProductIds as $updateProductId) { if (!$this->_isProductComposite($updateProductId)) { $parentIds = $this->_getResource()->getRelationsByChild($updateProductId); if (!empty($parentIds)) { $productIds = array_merge($productIds, $parentIds); } } } if (!empty($productIds)) { $this->engine->removeProducts(null, $productIds); $this->engine->rebuildProductIndex(null, $productIds); } } }
protected function _processEvent(Mage_Index_Model_Event $event) { if (!$this->config->getApplicationID() || !$this->config->getAPIKey() || !$this->config->getSearchOnlyAPIKey()) { if (self::$credential_error === false) { /** @var Mage_Adminhtml_Model_Session $session */ $session = Mage::getSingleton('adminhtml/session'); $session->addError('Algolia indexing failed: You need to configure your Algolia credentials in System > Configuration > Algolia Search.'); self::$credential_error = true; } return; } $data = $event->getNewData(); /* * Reindex all products */ if (!empty($data['algoliasearch_reindex_all'])) { $process = $event->getProcess(); $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX); } if (!empty($data['catalogsearch_update_category_id'])) { $this->reindexSpecificCategories($data['catalogsearch_update_category_id']); } /* * Reindex products. */ if (!empty($data['catalogsearch_update_product_id'])) { $this->reindexSpecificProducts($data['catalogsearch_update_product_id']); } }