예제 #1
0
파일: Url.php 프로젝트: aiesh/magento2
 /**
  * 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);
         }
     }
 }
예제 #2
0
 /**
  * Register data required by catatalog product process in event object
  *
  * @param Event $event
  * @return $this
  */
 protected function _registerCatalogProductEvent(Event $event)
 {
     switch ($event->getType()) {
         case Event::TYPE_SAVE:
             /* @var $product Product */
             $product = $event->getDataObject();
             $event->addNewData('catalogsearch_update_product_id', $product->getId());
             break;
         case Event::TYPE_DELETE:
             /* @var $product Product */
             $product = $event->getDataObject();
             $event->addNewData('catalogsearch_delete_product_id', $product->getId());
             break;
         case Event::TYPE_MASS_ACTION:
             /* @var $actionObject \Magento\Framework\Object */
             $actionObject = $event->getDataObject();
             $reindexData = array();
             $rebuildIndex = false;
             // check if status changed
             $attrData = $actionObject->getAttributesData();
             if (isset($attrData['status'])) {
                 $rebuildIndex = true;
                 $reindexData['catalogsearch_status'] = $attrData['status'];
             }
             // check changed websites
             if ($actionObject->getWebsiteIds()) {
                 $rebuildIndex = true;
                 $reindexData['catalogsearch_website_ids'] = $actionObject->getWebsiteIds();
                 $reindexData['catalogsearch_action_type'] = $actionObject->getActionType();
             }
             $searchableAttributes = array();
             if (is_array($attrData)) {
                 $searchableAttributes = array_intersect($this->_getSearchableAttributes(), array_keys($attrData));
             }
             if (count($searchableAttributes) > 0) {
                 $rebuildIndex = true;
                 $reindexData['catalogsearch_force_reindex'] = true;
             }
             // register affected products
             if ($rebuildIndex) {
                 $reindexData['catalogsearch_product_ids'] = $actionObject->getProductIds();
                 foreach ($reindexData as $k => $v) {
                     $event->addNewData($k, $v);
                 }
             }
             break;
         default:
             break;
     }
     return $this;
 }