Algolia_Algoliasearch_Helper_Data::rebuildStoreCategoryIndexPage PHP Method

rebuildStoreCategoryIndexPage() public method

public rebuildStoreCategoryIndexPage ( $storeId, $collectionDefault, $page, $pageSize, $emulationInfo = null )
    public function rebuildStoreCategoryIndexPage($storeId, $collectionDefault, $page, $pageSize, $emulationInfo = null)
    {
        if ($this->config->isEnabledBackend($storeId) === false) {
            $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
            return;
        }
        $emulationInfoPage = null;
        if ($emulationInfo === null) {
            $emulationInfoPage = $this->startEmulation($storeId);
        }
        $collection = clone $collectionDefault;
        $collection->setCurPage($page)->setPageSize($pageSize);
        $collection->load();
        $index_name = $this->category_helper->getIndexName($storeId);
        $indexData = array();
        /** @var $category Mage_Catalog_Model_Category */
        foreach ($collection as $category) {
            if (!$this->category_helper->isCategoryActive($category->getId(), $storeId)) {
                continue;
            }
            $category->setStoreId($storeId);
            $category_obj = $this->category_helper->getObject($category);
            if ($category_obj['product_count'] > 0) {
                array_push($indexData, $category_obj);
            }
        }
        if (count($indexData) > 0) {
            $this->algolia_helper->addObjects($indexData, $index_name);
        }
        unset($indexData);
        $collection->walk('clearInstance');
        $collection->clear();
        unset($collection);
        if ($emulationInfo === null) {
            $this->stopEmulation($emulationInfoPage);
        }
    }

Usage Example

 public function rebuildCategoryIndex(Varien_Object $event)
 {
     $storeId = $event->getStoreId();
     $categoryIds = $event->getCategoryIds();
     $page = $event->getPage();
     $pageSize = $event->getPageSize();
     if (is_null($storeId) && !empty($categoryIds)) {
         foreach (Mage::app()->getStores() as $storeId => $store) {
             if (!$store->getIsActive()) {
                 continue;
             }
             $this->helper->rebuildStoreCategoryIndex($storeId, $categoryIds);
         }
     } else {
         if (!empty($page) && !empty($pageSize)) {
             $this->helper->rebuildStoreCategoryIndexPage($storeId, $this->category_helper->getCategoryCollectionQuery($storeId, $categoryIds), $page, $pageSize);
         } else {
             $this->helper->rebuildStoreCategoryIndex($storeId, $categoryIds);
         }
     }
     return $this;
 }