Example #1
0
 /**
  * Process Catalog Eav Attribute Save
  *
  * @param \Magento\Index\Model\Event $event
  * @return $this
  */
 public function catalogEavAttributeSave(\Magento\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;
 }
Example #2
0
 /**
  * Process event
  *
  * @param \Magento\Index\Model\Event $event
  * @return void
  */
 protected function _processEvent(\Magento\Index\Model\Event $event)
 {
     $data = $event->getNewData();
     if (!empty($data['catalog_url_reindex_all'])) {
         $this->reindexAll();
     }
     // Force rewrites history saving
     $dataObject = $event->getDataObject();
     if ($dataObject instanceof \Magento\Framework\Object && $dataObject->hasData('save_rewrites_history')) {
         $this->_catalogUrl->setShouldSaveRewritesHistory($dataObject->getData('save_rewrites_history'));
     }
     if (isset($data['rewrite_product_ids'])) {
         $this->_catalogUrl->clearStoreInvalidRewrites();
         // Maybe some products were moved or removed from website
         foreach ($data['rewrite_product_ids'] as $productId) {
             $this->_catalogUrl->refreshProductRewrite($productId);
         }
     }
     if (isset($data['rewrite_category_ids'])) {
         $this->_catalogUrl->clearStoreInvalidRewrites();
         // Maybe some categories were moved
         foreach ($data['rewrite_category_ids'] as $categoryId) {
             $this->_catalogUrl->refreshCategoryRewrite($categoryId, null, true, true);
         }
     }
 }
Example #3
0
 /**
  * Process event
  *
  * @param Event $event
  * @return void
  */
 protected function _processEvent(Event $event)
 {
     $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)->getResource()->resetSearchResults(null, $productId);
         } elseif (!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);
         } 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 ($this->_storeManager->getWebsite($websiteId)->getStoreIds() as $storeId) {
                             if ($actionType == 'remove') {
                                 $this->_getIndexer()->cleanIndex($storeId, $productIds)->getResource()->resetSearchResults($storeId, $productIds);
                             } elseif ($actionType == 'add') {
                                 $this->_getIndexer()->rebuildIndex($storeId, $productIds);
                             }
                         }
                     }
                 }
                 if (isset($data['catalogsearch_status'])) {
                     $status = $data['catalogsearch_status'];
                     if ($status == \Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED) {
                         $this->_getIndexer()->rebuildIndex(null, $productIds);
                     } else {
                         $this->_getIndexer()->cleanIndex(null, $productIds)->getResource()->resetSearchResults(null, $productIds);
                     }
                 }
                 if (isset($data['catalogsearch_force_reindex'])) {
                     $this->_getIndexer()->rebuildIndex(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);
                 }
             }
         }
     }
 }