Exemplo n.º 1
0
 /**
  * Register event
  * @see Mage_Index_Model_Indexer_Abstract::_registerEvent()
  * @param Mage_Index_Model_Event $event
  * @return void
  */
 protected function _registerEvent(Mage_Index_Model_Event $event)
 {
     $process = $event->getProcess();
     if ($process->getMode() == Mage_Index_Model_Process::MODE_MANUAL) {
         $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
     }
 }
Exemplo n.º 2
0
 protected function _registerEvent(Mage_Index_Model_Event $event)
 {
     $event->addNewData(self::EVENT_MATCH_RESULT_KEY, true);
     $entity = $event->getEntity();
     switch ($entity) {
         case Mage_Core_Model_Store::ENTITY:
         case Mage_Core_Model_Store_Group::ENTITY:
             $process = $event->getProcess();
             $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
             break;
     }
     return $this;
 }
Exemplo n.º 3
0
 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);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Register data required by process in event object
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _registerEvent(Mage_Index_Model_Event $event)
 {
     $event->addNewData(self::EVENT_MATCH_RESULT_KEY, true);
     $entity = $event->getEntity();
     if ($entity == Mage_Core_Model_Config_Data::ENTITY || $entity == Mage_Customer_Model_Group::ENTITY) {
         $process = $event->getProcess();
         $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
     } else {
         if ($entity == Mage_Catalog_Model_Convert_Adapter_Product::ENTITY) {
             $event->addNewData('catalog_product_price_reindex_all', true);
         } else {
             if ($entity == Mage_Catalog_Model_Product::ENTITY) {
                 switch ($event->getType()) {
                     case Mage_Index_Model_Event::TYPE_DELETE:
                         $this->_registerCatalogProductDeleteEvent($event);
                         break;
                     case Mage_Index_Model_Event::TYPE_SAVE:
                         $this->_registerCatalogProductSaveEvent($event);
                         break;
                     case Mage_Index_Model_Event::TYPE_MASS_ACTION:
                         $this->_registerCatalogProductMassActionEvent($event);
                         break;
                     case self::EVENT_TYPE_REINDEX_PRICE:
                         $event->addNewData('id', $event->getDataObject()->getId());
                         break;
                 }
                 // call product type indexers registerEvent
                 $indexers = $this->_getResource()->getTypeIndexers();
                 foreach ($indexers as $indexer) {
                     $indexer->registerEvent($event);
                 }
             }
         }
     }
 }
 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 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 {
         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'])) {
         $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);
     }
 }
 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']);
     }
 }
Exemplo n.º 7
0
 protected function _skipReindex(Mage_Index_Model_Event $event)
 {
     $process = $event->getProcess();
     $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
 }
Exemplo n.º 8
0
 protected function _registerBrandProductsEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getDataObject()->getData();
     $attributeCode = Mage::helper('shopbybrand/brand')->getAttributeCode();
     if (isset($data['attributes_data'][$attributeCode]) && $data['attributes_data'][$attributeCode]) {
         if (is_array($data['product_ids']) && count($data['product_ids'])) {
             $process = $event->getProcess();
             $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
         }
     }
     return $this;
 }
Exemplo n.º 9
0
 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']);
     }
 }
 /**
  * Process event based on event state data
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $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 {
         if (!empty($data['algoliasearch_update_settings'])) {
             $this->_getIndexer()->updateIndexSettings($data['algoliasearch_update_settings']);
         } else {
             if (!empty($data['catalogsearch_delete_product_id'])) {
                 $productId = $data['catalogsearch_delete_product_id'];
                 if (!$this->_isProductComposite($productId)) {
                     $parentIds = $this->_getResource()->getRelationsByChild($productId);
                     if (!empty($parentIds)) {
                         $this->_getIndexer()->rebuildProductIndex(NULL, $parentIds);
                     }
                 }
                 $this->_getIndexer()->cleanProductIndex(NULL, $productId);
                 /*
                  * Change indexer status as need to reindex related categories to update product count.
                  * It's low priority so no need to automatically reindex all related categories after deleting each product.
                  * Do not reindex all if affected categories are given or product count is not indexed.
                  */
                 if (!isset($data['catalogsearch_update_category_id']) && Mage::helper('algoliasearch')->isIndexProductCount()) {
                     $process = $event->getProcess();
                     $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
                 }
             } else {
                 if (!empty($data['catalogsearch_delete_category_id'])) {
                     $categoryIds = $data['catalogsearch_delete_category_id'];
                     $this->_getIndexer()->cleanCategoryIndex(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']) && Mage::helper('algoliasearch')->isIndexProductCount()) {
                         $process = $event->getProcess();
                         $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
                     }
                 } else {
                     if (!empty($data['catalogsearch_product_ids'])) {
                         $productIds = $data['catalogsearch_product_ids'];
                         if (!empty($data['catalogsearch_website_ids'])) {
                             $websiteIds = $data['catalogsearch_website_ids'];
                             $actionType = $data['catalogsearch_action_type'];
                             foreach ($websiteIds as $websiteId) {
                                 foreach (Mage::app()->getWebsite($websiteId)->getStoreIds() as $storeId) {
                                     if ($actionType == 'remove') {
                                         $this->_getIndexer()->cleanProductIndex($storeId, $productIds);
                                     } else {
                                         if ($actionType == 'add') {
                                             $this->_getIndexer()->rebuildProductIndex($storeId, $productIds);
                                         }
                                     }
                                 }
                             }
                         } else {
                             if (isset($data['catalogsearch_status'])) {
                                 $status = $data['catalogsearch_status'];
                                 if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
                                     $this->_getIndexer()->rebuildProductIndex(NULL, $productIds);
                                 } else {
                                     $this->_getIndexer()->cleanProductIndex(NULL, $productIds);
                                 }
                             } else {
                                 if (isset($data['catalogsearch_force_reindex'])) {
                                     $this->_getIndexer()->rebuildProductIndex(NULL, $productIds);
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     /*
      * Reindex products.
      * The products are enabled and visible for search so no need to reindex related categories after reindexing 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);
                 }
             }
         }
         $this->_getIndexer()->rebuildProductIndex(NULL, $productIds);
     }
     /*
      * Reindex categories.
      * Category products are tracked separately. The specified categories are active. See _registerCatalogCategoryEvent().
      */
     if (!empty($data['catalogsearch_update_category_id'])) {
         $updateCategoryIds = $data['catalogsearch_update_category_id'];
         $updateCategoryIds = is_array($updateCategoryIds) ? $updateCategoryIds : array($updateCategoryIds);
         $this->_getIndexer()->rebuildCategoryIndex(NULL, $updateCategoryIds);
     }
 }
Exemplo n.º 11
0
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     if (!$this->config->getApplicationID() || !$this->config->getAPIKey() || !$this->config->getSearchOnlyAPIKey()) {
         Mage::getSingleton('adminhtml/session')->addError('Algolia indexing failed: You need to configure your Algolia credentials in System > Configuration > Algolia Search.');
         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 {
         if (!empty($data['catalogsearch_delete_product_id'])) {
             $productId = $data['catalogsearch_delete_product_id'];
             if (!$this->_isProductComposite($productId)) {
                 $parentIds = $this->_getResource()->getRelationsByChild($productId);
                 if (!empty($parentIds)) {
                     $this->engine->rebuildProductIndex(null, $parentIds);
                 }
             }
             $this->engine->removeProducts(null, $productId);
             /*
              * Change indexer status as need to reindex related categories to update product count.
              * It's low priority so no need to automatically reindex all related categories after deleting each product.
              * Do not reindex all if affected categories are given or product count is not indexed.
              */
             if (!isset($data['catalogsearch_update_category_id'])) {
                 $process = $event->getProcess();
                 $process->changeStatus(Mage_Index_Model_Process::STATUS_REQUIRE_REINDEX);
             }
         } else {
             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);
                 }
             } else {
                 if (!empty($data['catalogsearch_product_ids'])) {
                     $productIds = $data['catalogsearch_product_ids'];
                     if (!empty($data['catalogsearch_website_ids'])) {
                         $websiteIds = $data['catalogsearch_website_ids'];
                         $actionType = $data['catalogsearch_action_type'];
                         foreach ($websiteIds as $websiteId) {
                             foreach (Mage::app()->getWebsite($websiteId)->getStoreIds() as $storeId) {
                                 if ($actionType == 'remove') {
                                     $this->engine->removeProducts($storeId, $productIds);
                                 } else {
                                     if ($actionType == 'add') {
                                         $this->engine->rebuildProductIndex($storeId, $productIds);
                                     }
                                 }
                             }
                         }
                     } else {
                         if (isset($data['catalogsearch_status'])) {
                             $status = $data['catalogsearch_status'];
                             if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
                                 $this->engine->rebuildProductIndex(null, $productIds);
                             } else {
                                 $this->engine->removeProducts(null, $productIds);
                             }
                         } else {
                             if (isset($data['catalogsearch_force_reindex'])) {
                                 $this->engine->rebuildProductIndex(null, $productIds);
                             }
                         }
                     }
                 }
             }
         }
     }
     /*
      * Reindex products.
      * The products are enabled and visible for search so no need to reindex related categories after reindexing 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);
                 }
             }
         }
         $this->engine->rebuildProductIndex(null, $productIds);
     }
     /*
      * Reindex categories.
      * Category products are tracked separately. The specified categories are active. See _registerCatalogCategoryEvent().
      */
     if (!empty($data['catalogsearch_update_category_id'])) {
         $updateCategoryIds = $data['catalogsearch_update_category_id'];
         $updateCategoryIds = is_array($updateCategoryIds) ? $updateCategoryIds : array($updateCategoryIds);
         $this->engine->rebuildCategoryIndex(null, $updateCategoryIds);
     }
 }