예제 #1
0
 public function matchEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (isset($data[self::EVENT_MATCH_RESULT_KEY])) {
         return $data[self::EVENT_MATCH_RESULT_KEY];
     }
     $entity = $event->getEntity();
     if ($entity == Mage_Core_Model_Store::ENTITY) {
         $store = $event->getDataObject();
         if ($store && ($store->isObjectNew() || $store->dataHasChangedFor('group_id'))) {
             $result = true;
         } else {
             $result = false;
         }
     } else {
         if ($entity == Mage_Core_Model_Store_Group::ENTITY) {
             $storeGroup = $event->getDataObject();
             $hasDataChanges = $storeGroup && ($storeGroup->dataHasChangedFor('root_category_id') || $storeGroup->dataHasChangedFor('website_id'));
             if ($storeGroup && !$storeGroup->isObjectNew() && $hasDataChanges) {
                 $result = true;
             } else {
                 $result = false;
             }
         } elseif ($entity == Mage_Catalog_Model_Product::ENTITY) {
             return true;
         } elseif ($entity == Mage_Catalog_Model_Category::ENTITY) {
             return true;
         } else {
             $result = parent::matchEvent($event);
         }
     }
     return $result;
 }
 /**
  * Modified to pull in all sibling associated products' tier prices and
  * to reindex child tier prices when a parent is saved.
  * 
  * Process product save.
  * Method is responsible for index support
  * when product was saved and changed attribute(s) has an effect on price.
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Price
  */
 public function catalogProductSave(Mage_Index_Model_Event $event)
 {
     $productId = $event->getEntityPk();
     $data = $event->getNewData();
     /**
      * Check if price attribute values were updated
      */
     if (!isset($data['reindex_price'])) {
         return $this;
     }
     $this->clearTemporaryIndexTable();
     $this->_prepareWebsiteDateTable();
     $indexer = $this->_getIndexer($data['product_type_id']);
     $processIds = array($productId);
     if ($indexer->getIsComposite()) {
         if ($this->getProductTypeById($productId) == 'configurable') {
             $children = $this->getChildIdsByParent($productId);
             $processIds = array_merge($processIds, array_keys($children));
             //Ignore tier and group price data for actual configurable product
             $tierPriceIds = array_keys($children);
         } else {
             $tierPriceIds = $productId;
         }
         $this->_copyRelationIndexData($productId);
         $this->_prepareTierPriceIndex($tierPriceIds);
         $this->_prepareGroupPriceIndex($tierPriceIds);
         $indexer->reindexEntity($productId);
     } else {
         $parentIds = $this->getProductParentsByChild($productId);
         if ($parentIds) {
             $processIds = array_merge($processIds, array_keys($parentIds));
             $siblingIds = array();
             foreach (array_keys($parentIds) as $parentId) {
                 $childIds = $this->getChildIdsByParent($parentId);
                 $siblingIds = array_merge($siblingIds, array_keys($childIds));
             }
             if (count($siblingIds) > 0) {
                 $processIds = array_unique(array_merge($processIds, $siblingIds));
             }
             $this->_copyRelationIndexData(array_keys($parentIds), $productId);
             $this->_prepareTierPriceIndex($processIds);
             $this->_prepareGroupPriceIndex($processIds);
             $indexer->reindexEntity($productId);
             $parentByType = array();
             foreach ($parentIds as $parentId => $parentType) {
                 $parentByType[$parentType][$parentId] = $parentId;
             }
             foreach ($parentByType as $parentType => $entityIds) {
                 $this->_getIndexer($parentType)->reindexEntity($entityIds);
             }
         } else {
             $this->_prepareTierPriceIndex($productId);
             $this->_prepareGroupPriceIndex($productId);
             $indexer->reindexEntity($productId);
         }
     }
     $this->_copyIndexDataToMainTable($processIds);
     return $this;
 }
예제 #3
0
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     Varien_Profiler::start(__METHOD__);
     $data = $event->getNewData();
     if (isset($data[self::EVENT_PRODUCT_IDS_KEY]) && is_array($data[self::EVENT_PRODUCT_IDS_KEY])) {
         $this->_startUpdate();
         foreach ($data[self::EVENT_PRODUCT_IDS_KEY] as $productId) {
             $this->_updateProduct($productId);
         }
         $this->_finishUpdate();
     }
     Varien_Profiler::stop(__METHOD__);
 }
예제 #4
0
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['udreindex_product_ids'])) {
         $this->_getResource()->reindexProducts($data['udreindex_product_ids']);
     }
     if (!empty($data['udreindex_vendor_ids'])) {
         $this->_getResource()->reindexVendors($data['udreindex_vendor_ids']);
     }
     if (empty($data['catalog_product_price_skip_call_event_handler'])) {
         $this->callEventHandler($event);
     }
 }
 /**
  * match whether the reindexing should be fired
  * @param Mage_Index_Model_Event $event
  * @return bool
  */
 public function matchEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (isset($data[self::EVENT_MATCH_RESULT_KEY])) {
         return $data[self::EVENT_MATCH_RESULT_KEY];
     }
     $entity = $event->getEntity();
     $result = true;
     if ($entity != Mage_Catalog_Model_Product::ENTITY) {
         return;
     }
     $event->addNewData(self::EVENT_MATCH_RESULT_KEY, $result);
     return $result;
 }
예제 #6
0
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['amconf_update_product_id'])) {
         $this->doSomethingOnUpdateEvent($data['amconf_update_product_id']);
     } else {
         if (!empty($data['amconf_delete_product_id'])) {
             $this->doSomethingOnDeleteEvent($data['amconf_delete_product_id']);
         } else {
             if (!empty($data['amconf_mass_action_product_ids'])) {
                 $this->doSomethingOnMassActionEvent($data['amconf_mass_action_product_ids']);
             }
         }
     }
 }
예제 #7
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_url_reindex_all'])) {
         $this->reindexAll();
         return $this;
     }
     // Force rewrites history saving
     $dataObject = $event->getDataObject();
     if ($dataObject instanceof Varien_Object && $dataObject->hasData('save_rewrites_history')) {
         $this->_getResource()->isSaveHistory($dataObject->getData('save_rewrites_history'));
     }
     if (isset($data['rewrite_category_ids']) || isset($data['rewrite_product_ids'])) {
         $this->callEventHandler($event);
     }
     $this->_getResource()->resetSaveHistory();
     return $this;
 }
예제 #8
0
파일: Url.php 프로젝트: santhosh400/ecart
 public function matchEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (isset($data[self::EVENT_MATCH_RESULT_KEY])) {
         return $data[self::EVENT_MATCH_RESULT_KEY];
     }
     $entity = $event->getEntity();
     if ($entity == Mage_Core_Model_Store::ENTITY) {
         $store = $event->getDataObject();
         if ($store && $store->isObjectNew()) {
             $result = true;
         } else {
             $result = false;
         }
     } else {
         $result = parent::matchEvent($event);
     }
     $event->addNewData(self::EVENT_MATCH_RESULT_KEY, $result);
     return $result;
 }
예제 #9
0
 /**
  * Process event based on event state data
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData('indexers');
     $object = $event->getDataObject();
     /** @var $object Mage_Core_Model_Abstract */
     foreach ($data['indexers'] as $indexer) {
         try {
             switch ($event->getType()) {
                 case Mage_Index_Model_Event::TYPE_SAVE:
                     $this->_getResource()->updateIndex($indexer, $object);
                     break;
                 case Mage_Index_Model_Event::TYPE_DELETE:
                     $this->_getResource()->removeIndex($indexer, $object->getId());
                     break;
                 case Mage_Index_Model_Event::TYPE_MASS_ACTION:
                 case Mage_Index_Model_Event::TYPE_REINDEX:
                     $indexerIds = (array) $object->getIndexerIds();
                     if (!empty($indexerIds)) {
                         $actionType = $object->getActionType() == self::ACTION_TYPE_REMOVE ? self::ACTION_TYPE_REMOVE : self::ACTION_TYPE_UPDATE;
                         switch ($actionType) {
                             case self::ACTION_TYPE_UPDATE:
                                 $collection = $object->getCollection();
                                 /** @var $collection Cm_Mongo_Model_Resource_Collection_Abstract */
                                 $collection->addFieldToFilter('_id', 'in', $indexerIds);
                                 foreach ($collection as $item) {
                                     $this->_getResource()->updateIndex($indexer, $item);
                                 }
                                 break;
                             case self::ACTION_TYPE_REMOVE:
                                 $this->_getResource()->removeIndex($indexer, $indexerIds);
                                 break;
                         }
                     }
                     break;
             }
         } catch (Exception $e) {
             Mage::logException($e);
         }
     }
 }
예제 #10
0
파일: Price.php 프로젝트: okite11/frames21
 /**
  * Process product mass update action
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Price
  */
 public function catalogProductMassAction(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['reindex_price_product_ids'])) {
         return $this;
     }
     $processIds = $data['reindex_price_product_ids'];
     $write = $this->_getWriteAdapter();
     $select = $write->select()->from($this->getTable('catalog/product'), 'COUNT(*)');
     $pCount = $write->fetchOne($select);
     // if affected more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds)) {
         return $this->reindexAll();
     }
     // calculate relations
     $select = $write->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)')->where('child_id IN(?)', $processIds);
     $aCount = $write->fetchOne($select);
     $select = $write->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)')->where('parent_id IN(?)', $processIds);
     $bCount = $write->fetchOne($select);
     // if affected with relations more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) {
         return $this->reindexAll();
     }
     $this->reindexProductIds($processIds);
     return $this;
 }
예제 #11
0
 /**
  * Process product massaction
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Tag_Model_Resource_Indexer_Summary
  */
 public function catalogProductMassAction(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['tag_reindex_tag_ids'])) {
         return $this;
     }
     return $this->aggregate($data['tag_reindex_tag_ids']);
 }
예제 #12
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_product_eav_reindex_all'])) {
         $this->reindexAll();
     }
     if (empty($data['catalog_product_eav_skip_call_event_handler'])) {
         $this->callEventHandler($event);
     }
 }
예제 #13
0
 /**
  * Process product mass update action
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Eav_Mysql4_Product_Indexer_Price
  */
 public function catalogProductMassAction(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['reindex_price_product_ids'])) {
         return $this;
     }
     $processIds = $data['reindex_price_product_ids'];
     $write = $this->_getWriteAdapter();
     $select = $write->select()->from($this->getTable('catalog/product'), 'COUNT(*)');
     $pCount = $write->fetchOne($select);
     // if affected more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds)) {
         return $this->reindexAll();
     }
     // calculate relations
     $select = $write->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)')->where('child_id IN(?)', $processIds);
     $aCount = $write->fetchOne($select);
     $select = $write->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)')->where('parent_id IN(?)', $processIds);
     $bCount = $write->fetchOne($select);
     // if affected with relations more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) {
         return $this->reindexAll();
     }
     $this->clearTemporaryIndexTable();
     // retrieve products types
     $select = $write->select()->from($this->getTable('catalog/product'), array('entity_id', 'type_id'))->where('entity_id IN(?)', $processIds);
     $pairs = $write->fetchPairs($select);
     $byType = array();
     foreach ($pairs as $productId => $productType) {
         $byType[$productType][$productId] = $productId;
     }
     $compositeIds = array();
     $notCompositeIds = array();
     foreach ($byType as $productType => $entityIds) {
         $indexer = $this->_getIndexer($productType);
         if ($indexer->getIsComposite()) {
             $compositeIds += $entityIds;
         } else {
             $notCompositeIds += $entityIds;
         }
     }
     if (!empty($notCompositeIds)) {
         $select = $write->select()->from(array('l' => $this->getTable('catalog/product_relation')), 'parent_id')->join(array('e' => $this->getTable('catalog/product')), 'e.entity_id = l.parent_id', array('type_id'))->where('l.child_id IN(?)', $notCompositeIds);
         $pairs = $write->fetchPairs($select);
         foreach ($pairs as $productId => $productType) {
             if (!in_array($productId, $processIds)) {
                 $processIds[] = $productId;
                 $byType[$productType][$productId] = $productId;
                 $compositeIds[$productId] = $productId;
             }
         }
     }
     if (!empty($compositeIds)) {
         $this->_copyRelationIndexData($compositeIds, $notCompositeIds);
     }
     $indexers = $this->getTypeIndexers();
     foreach ($indexers as $indexer) {
         if (!empty($byType[$indexer->getTypeId()])) {
             $indexer->reindexEntity($byType[$indexer->getTypeId()]);
         }
     }
     $this->_copyIndexDataToMainTable($processIds);
     return $this;
 }
예제 #14
0
파일: Eav.php 프로젝트: relue/magento2
 /**
  * Process Catalog Eav Attribute Save
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_Catalog_Model_Resource_Product_Indexer_Eav
  */
 public function catalogEavAttributeSave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['reindex_attribute'])) {
         return $this;
     }
     $indexer = $this->getIndexer($data['attribute_index_type']);
     $indexer->reindexAttribute($event->getEntityPk(), !empty($data['is_indexable']));
     return $this;
 }
예제 #15
0
파일: Product.php 프로젝트: quyip8818/Mag
 /**
  * Process category index after category save
  *
  * @param Mage_Index_Model_Event $event
  */
 public function catalogCategorySave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     $checkRootCategories = false;
     $processRootCategories = false;
     $affectedRootCategoryIds = array();
     $rootCategories = $this->_getRootCategories();
     /**
      * Check if we have reindex category move results
      */
     if (isset($data['affected_category_ids'])) {
         $categoryIds = $data['affected_category_ids'];
         $checkRootCategories = true;
     } else {
         if (isset($data['products_was_changed'])) {
             $categoryIds = array($event->getEntityPk());
             if (isset($rootCategories[$event->getEntityPk()])) {
                 $processRootCategories = true;
                 $affectedRootCategoryIds[] = $event->getEntityPk();
             }
         } else {
             return;
         }
     }
     $select = $this->_getWriteAdapter()->select()->from($this->_categoryTable, 'path')->where('entity_id IN (?)', $categoryIds);
     $paths = $this->_getWriteAdapter()->fetchCol($select);
     $allCategoryIds = array();
     foreach ($paths as $path) {
         if ($checkRootCategories) {
             foreach ($rootCategories as $rootCategoryId => $rootCategoryPath) {
                 if (strpos($path, sprintf('%d/', $rootCategoryPath)) === 0 || $path == $rootCategoryPath) {
                     $affectedRootCategoryIds[$rootCategoryId] = $rootCategoryId;
                 }
             }
         }
         $allCategoryIds = array_merge($allCategoryIds, explode('/', $path));
     }
     $allCategoryIds = array_unique($allCategoryIds);
     if ($checkRootCategories && count($affectedRootCategoryIds) > 1) {
         $processRootCategories = true;
     }
     /**
      * retrieve anchor category id
      */
     $anchorInfo = $this->_getAnchorAttributeInfo();
     $bind = array('attribute_id' => $anchorInfo['id'], 'store_id' => Mage_Catalog_Model_Abstract::DEFAULT_STORE_ID, 'e_value' => 1);
     $select = $this->_getReadAdapter()->select()->distinct(true)->from(array('ce' => $this->_categoryTable), array('entity_id'))->joinInner(array('dca' => $anchorInfo['table']), "dca.entity_id=ce.entity_id AND dca.attribute_id=:attribute_id AND dca.store_id=:store_id", array())->where('dca.value=:e_value')->where('ce.entity_id IN (?)', $allCategoryIds);
     $anchorIds = $this->_getWriteAdapter()->fetchCol($select, $bind);
     /**
      * delete only anchor id and category ids
      */
     $deleteCategoryIds = array_merge($anchorIds, $categoryIds);
     $this->_getWriteAdapter()->delete($this->getMainTable(), $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds));
     $directIds = array_diff($categoryIds, $anchorIds);
     if ($anchorIds) {
         $this->_refreshAnchorRelations($anchorIds);
     }
     if ($directIds) {
         $this->_refreshDirectRelations($directIds);
     }
     /**
      * Need to re-index affected root category ids when its are not anchor
      */
     if ($processRootCategories) {
         $reindexRootCategoryIds = array_diff($affectedRootCategoryIds, $anchorIds);
         if ($reindexRootCategoryIds) {
             $this->_refreshNotAnchorRootCategories($reindexRootCategoryIds);
         }
     }
 }
예제 #16
0
 /**
  * Process category index after category save
  *
  * @param Mage_Index_Model_Event $event
  */
 public function catalogCategorySave(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     /**
      * Check if we have reindex category move results
      */
     if (isset($data['affected_category_ids'])) {
         $categoryIds = $event->getNewData('affected_category_ids');
     } else {
         if (isset($data['products_was_changed'])) {
             $categoryIds = array($event->getEntityPk());
         } else {
             return;
         }
     }
     $select = $this->_getWriteAdapter()->select()->from($this->_categoryTable, 'path')->where('entity_id IN (?)', $categoryIds);
     $paths = $this->_getWriteAdapter()->fetchCol($select);
     $allCategoryIds = array();
     foreach ($paths as $path) {
         $allCategoryIds = array_merge($allCategoryIds, explode('/', $path));
     }
     $allCategoryIds = array_unique($allCategoryIds);
     /**
      * retrieve anchor category id
      */
     $anchorInfo = $this->_getAnchorAttributeInfo();
     $select = $this->_getReadAdapter()->select()->distinct(true)->from(array('ce' => $this->_categoryTable), array('entity_id'))->joinInner(array('dca' => $anchorInfo['table']), "dca.entity_id=ce.entity_id AND dca.attribute_id={$anchorInfo['id']} AND dca.store_id=0", array())->where('dca.value=1')->where('ce.entity_id IN (?)', $allCategoryIds);
     $anchorIds = $this->_getWriteAdapter()->fetchCol($select);
     /**
      * delete only anchor id and category ids
      */
     $deleteCategoryIds = array_merge($anchorIds, $categoryIds);
     $this->_getWriteAdapter()->delete($this->getMainTable(), $this->_getWriteAdapter()->quoteInto('category_id IN(?)', $deleteCategoryIds));
     $anchorIds = array_diff($anchorIds, $categoryIds);
     $this->_refreshAnchorRelations($anchorIds);
     $this->_refreshDirectRelations($categoryIds);
 }
예제 #17
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_category_flat_reindex_all'])) {
         $this->reindexAll();
     } else {
         if (!empty($data['catalog_category_flat_category_id'])) {
             // catalog_product save
             $categoryId = $data['catalog_category_flat_category_id'];
             $this->_getIndexer()->synchronize($categoryId);
         } else {
             if (!empty($data['catalog_category_flat_affected_category_ids'])) {
                 $categoryIds = $data['catalog_category_flat_affected_category_ids'];
                 $this->_getIndexer()->move($categoryIds);
             } else {
                 if (!empty($data['catalog_category_flat_delete_store_id'])) {
                     $storeId = $data['catalog_category_flat_delete_store_id'];
                     $this->_getIndexer()->deleteStores($storeId);
                 }
             }
         }
     }
 }
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_url_reindex_all'])) {
         $this->reindexAll();
     }
     if (isset($data['rewrite_product_ids'])) {
         foreach ($data['rewrite_product_ids'] as $productId) {
             Mage::getSingleton('catalog/url')->refreshProductRewrite($productId);
         }
     }
     if (isset($data['rewrite_category_ids'])) {
         foreach ($data['rewrite_category_ids'] as $categoryId) {
             Mage::getSingleton('catalog/url')->refreshCategoryRewrite($categoryId);
         }
     }
 }
예제 #19
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if ($event->getType() == self::EVENT_TYPE_REINDEX_PRICE) {
         $this->_getResource()->reindexProductIds($data['id']);
         return;
     }
     if (!empty($data['catalog_product_price_reindex_all'])) {
         $this->reindexAll();
     }
     if (empty($data['catalog_product_price_skip_call_event_handler'])) {
         $this->callEventHandler($event);
     }
 }
 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']);
     }
 }
예제 #21
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_product_flat_reindex_all'])) {
         $this->reindexAll();
     } else {
         if (!empty($data['catalog_product_flat_product_id'])) {
             // catalog_product save
             $productId = $data['catalog_product_flat_product_id'];
             $this->_getIndexer()->saveProduct($productId);
         } else {
             if (!empty($data['catalog_product_flat_product_ids'])) {
                 // catalog_product mass_action
                 $productIds = $data['catalog_product_flat_product_ids'];
                 if (!empty($data['catalog_product_flat_website_ids'])) {
                     $websiteIds = $data['catalog_product_flat_website_ids'];
                     foreach ($websiteIds as $websiteId) {
                         $website = Mage::app()->getWebsite($websiteId);
                         foreach ($website->getStores() as $store) {
                             if ($data['catalog_product_flat_action_type'] == 'remove') {
                                 $this->_getIndexer()->removeProduct($productIds, $store->getId());
                             } else {
                                 $this->_getIndexer()->updateProduct($productIds, $store->getId());
                             }
                         }
                     }
                 }
                 if (isset($data['catalog_product_flat_status'])) {
                     $status = $data['catalog_product_flat_status'];
                     $this->_getIndexer()->updateProductStatus($productIds, $status);
                 }
             } else {
                 if (!empty($data['catalog_product_flat_delete_store_id'])) {
                     $this->_getIndexer()->deleteStore($data['catalog_product_flat_delete_store_id']);
                 }
             }
         }
     }
 }
 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);
     }
 }
예제 #23
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);
         }
     }
 }
 /**
  * Process event based on event state data
  *
  * @param   Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $this->process($event->getNewData());
 }
예제 #25
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     if (!$this->_allowTableChanges && is_callable(array($this->_getIndexer(), 'setAllowTableChanges'))) {
         $this->_getIndexer()->setAllowTableChanges(false);
     }
     $data = $event->getNewData();
     if (!empty($data['catalogsearch_fulltext_reindex_all'])) {
         $this->reindexAll();
     } 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()->rebuildIndex(null, $parentIds);
                 }
             }
             $this->_getIndexer()->cleanIndex(null, $productId)->resetSearchResults();
         } else {
             if (!empty($data['catalogsearch_update_product_id'])) {
                 $productId = $data['catalogsearch_update_product_id'];
                 $productIds = array($productId);
                 if (!$this->_isProductComposite($productId)) {
                     $parentIds = $this->_getResource()->getRelationsByChild($productId);
                     if (!empty($parentIds)) {
                         $productIds = array_merge($productIds, $parentIds);
                     }
                 }
                 $this->_getIndexer()->rebuildIndex(null, $productIds)->resetSearchResults();
             } else {
                 if (!empty($data['catalogsearch_product_ids'])) {
                     // mass action
                     $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()->cleanIndex($storeId, $productIds)->resetSearchResults();
                                 } else {
                                     if ($actionType == 'add') {
                                         $this->_getIndexer()->rebuildIndex($storeId, $productIds)->resetSearchResults();
                                     }
                                 }
                             }
                         }
                     }
                     if (isset($data['catalogsearch_status'])) {
                         $status = $data['catalogsearch_status'];
                         if ($status == Mage_Catalog_Model_Product_Status::STATUS_ENABLED) {
                             $this->_getIndexer()->rebuildIndex(null, $productIds)->resetSearchResults();
                         } else {
                             $this->_getIndexer()->cleanIndex(null, $productIds)->resetSearchResults();
                         }
                     }
                 } else {
                     if (isset($data['catalogsearch_category_update_product_ids'])) {
                         $productIds = $data['catalogsearch_category_update_product_ids'];
                         $categoryIds = $data['catalogsearch_category_update_category_ids'];
                         $this->_getIndexer()->updateCategoryIndex($productIds, $categoryIds);
                     }
                 }
             }
         }
     }
     if (!$this->_allowTableChanges && is_callable(array($this->_getIndexer(), 'setAllowTableChanges'))) {
         $this->_getIndexer()->setAllowTableChanges(true);
     }
 }
예제 #26
0
 /**
  * Process event based on event state data
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     switch ($event->getType()) {
         case self::EVENT_TYPE_REINDEX_PRODUCTS:
             switch ($event->getEntity()) {
                 case self::ENTITY_PRODUCT:
                     $data = $event->getNewData();
                     if (!empty($data['product'])) {
                         $this->_reindex($data['product']);
                     }
                     break;
             }
             break;
         case self::EVENT_TYPE_CLEAN_TARGETRULES:
             switch ($event->getEntity()) {
                 case self::ENTITY_TARGETRULE:
                     $data = $event->getNewData();
                     if (!empty($data['params'])) {
                         $params = $data['params'];
                         $this->_cleanIndex($params->getTypeId(), $params->getStore());
                     }
                     break;
             }
             break;
     }
 }
예제 #27
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_url_reindex_all'])) {
         $this->reindexAll();
     }
     /* @var $urlModel Mage_Catalog_Model_Url */
     $urlModel = Mage::getSingleton('catalog/url');
     // Force rewrites history saving
     $dataObject = $event->getDataObject();
     if ($dataObject instanceof Varien_Object && $dataObject->hasData('save_rewrites_history')) {
         $urlModel->setShouldSaveRewritesHistory($dataObject->getData('save_rewrites_history'));
     }
     if (isset($data['rewrite_product_ids'])) {
         $urlModel->clearStoreInvalidRewrites();
         // Maybe some products were moved or removed from website
         foreach ($data['rewrite_product_ids'] as $productId) {
             $urlModel->refreshProductRewrite($productId);
         }
     }
     if (isset($data['rewrite_category_ids'])) {
         $urlModel->clearStoreInvalidRewrites();
         // Maybe some categories were moved
         foreach ($data['rewrite_category_ids'] as $categoryId) {
             $urlModel->refreshCategoryRewrite($categoryId);
         }
     }
 }
예제 #28
0
파일: Points.php 프로젝트: rajarshc/Rooja
 /**
  * Process event
  * @param Mage_Index_Model_Event $event
  * @return void
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     $event_model = $event->getDataObject();
     if (!empty($data['rewards_customer_points_match_result'])) {
         try {
             if ($event->getEntity() == self::REWARDS_TRANSFER_ENTITY) {
                 if ($event_model) {
                     $transfer = $event_model;
                     $this->_getResource()->reindexUpdate($transfer->getCustomerId());
                 }
             } elseif ($event->getEntity() == self::REWARDS_CUSTOMER_ENTITY) {
                 if ($event_model) {
                     $customer = $event_model;
                     $this->_getResource()->reindexUpdate($customer->getId());
                 }
             } else {
                 // Model entity type was not recognized
             }
         } catch (Exception $e) {
             Mage::logException($e);
             Mage::helper('rewards/debug')->logException($e);
             $this->reindexAll();
         }
     }
 }
예제 #29
0
 /**
  * Process product mass update action
  *
  * @param Mage_Index_Model_Event $event
  * @return Mage_CatalogInventory_Model_Resource_Indexer_Stock
  */
 public function catalogProductMassAction(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (empty($data['reindex_stock_product_ids'])) {
         return $this;
     }
     $adapter = $this->_getWriteAdapter();
     $processIds = $data['reindex_stock_product_ids'];
     $select = $adapter->select()->from($this->getTable('catalog/product'), 'COUNT(*)');
     $pCount = $adapter->fetchOne($select);
     // if affected more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds)) {
         return $this->reindexAll();
     }
     // calculate relations
     $select = $adapter->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT parent_id)')->where('child_id IN(?)', $processIds);
     $aCount = $adapter->fetchOne($select);
     $select = $adapter->select()->from($this->getTable('catalog/product_relation'), 'COUNT(DISTINCT child_id)')->where('parent_id IN(?)', $processIds);
     $bCount = $adapter->fetchOne($select);
     // if affected with relations more 30% of all products - run reindex all products
     if ($pCount * 0.3 < count($processIds) + $aCount + $bCount) {
         return $this->reindexAll();
     }
     // retrieve affected parent relation products
     $parentIds = $this->getRelationsByChild($processIds);
     if ($parentIds) {
         $processIds = array_merge($processIds, $parentIds);
     }
     // retrieve products types
     $select = $adapter->select()->from($this->getTable('catalog/product'), array('entity_id', 'type_id'))->where('entity_id IN(?)', $processIds);
     $query = $select->query(Zend_Db::FETCH_ASSOC);
     $byType = array();
     while ($row = $query->fetch()) {
         $byType[$row['type_id']][] = $row['entity_id'];
     }
     $adapter->beginTransaction();
     try {
         $indexers = $this->_getTypeIndexers();
         foreach ($indexers as $indexer) {
             if (!empty($byType[$indexer->getTypeId()])) {
                 $indexer->reindexEntity($byType[$indexer->getTypeId()]);
             }
         }
     } catch (Exception $e) {
         $adapter->rollback();
         throw $e;
     }
     $adapter->commit();
     return $this;
 }
예제 #30
0
 /**
  * Process event
  *
  * @param Mage_Index_Model_Event $event Index Event Model
  */
 protected function _processEvent(Mage_Index_Model_Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['dynamiccategory_save_category_id'])) {
         $this->getIndexer()->rebuildIndex(null, $data['dynamiccategory_save_category_id']);
     }
 }