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 and all categories and update index settings
*/
if (!empty($data['algoliasearch_reindex_all'])) {
$process = $event->getProcess();
$process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
} else {
/*
* Clear indexer for the deleted category including all children categories and update index for the related products.
*/
if (!empty($data['catalogsearch_delete_category_id'])) {
$categoryIds = $data['catalogsearch_delete_category_id'];
$this->engine->removeCategories(null, $categoryIds);
/*
* Change indexer status as need to reindex related products to update the list of categories.
* It's low priority so no need to automatically reindex all related products after deleting each category.
* Do not reindex all if affected products are given or product count is not indexed.
*/
if (!isset($data['catalogsearch_update_product_id'])) {
$process = $event->getProcess();
$process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
}
}
}
/*
* Reindex categories.
* Category products are tracked separately. The specified categories are active. See _registerCatalogCategoryEvent().
*/
if (!empty($data['catalogsearch_update_category_id'])) {
$this->reindexSpecificCategories($data['catalogsearch_update_category_id']);
}
/*
* If we have added any new products to a category then we need to
* update these products in Algolia indices.
*/
if (!empty($data['catalogsearch_update_product_id'])) {
$this->reindexSpecificProducts($data['catalogsearch_update_product_id']);
}
}