rebuildProductIndex() публичный Метод

public rebuildProductIndex ( $storeId = null, $productIds = null )
Пример #1
0
 /**
  * This function will update all the requested products and their parent
  * products in Algolia. You can provide either a single product ID or an
  * array of product IDs. A product ID should be either a string or an
  * integer.
  *
  * @param array|string|int $updateProductIds
  */
 public function reindexSpecificProducts($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->rebuildProductIndex(null, $productIds);
     }
 }
 /**
  * Rebuild index for the specified products
  *
  * @param null|int       $storeId
  * @param null|int|array $productIds
  * @return Algolia_Algoliasearch_Model_Resource_Fulltext
  */
 public function rebuildProductIndex($storeId = NULL, $productIds = NULL)
 {
     if ($this->_helper->isEnabled($storeId) && is_object($this->_engine) && is_callable(array($this->_engine, 'rebuildProductIndex'))) {
         $this->_engine->rebuildProductIndex($storeId, $productIds);
     }
     return $this;
 }
Пример #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);
         }
     }
 }
Пример #4
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);
     }
 }