protected function _rebuildCategoryIndex($storeId, $categoryIds = null) { if ($categoryIds == null || count($categoryIds) == 0) { $size = $this->category_helper->getCategoryCollectionQuery($storeId, $categoryIds)->getSize(); $by_page = $this->config->getNumberOfElementByPage(); $nb_page = ceil($size / $by_page); for ($i = 1; $i <= $nb_page; $i++) { $data = array('store_id' => $storeId, 'category_ids' => $categoryIds, 'page_size' => $by_page, 'page' => $i); $this->addToQueue('algoliasearch/observer', 'rebuildCategoryIndex', $data, $by_page); } } else { $this->addToQueue('algoliasearch/observer', 'rebuildCategoryIndex', array('store_id' => $storeId, 'category_ids' => $categoryIds), count($categoryIds)); } return $this; }
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; }
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); } }
public function getRootCategoryId() { if (-1 === self::$_rootCategoryId) { $collection = Mage::getResourceModel('catalog/category_collection'); $collection->addFieldToFilter('parent_id', 0); $collection->getSelect()->limit(1); $rootCategory = $collection->getFirstItem(); self::$_rootCategoryId = $rootCategory->getId(); } return self::$_rootCategoryId; }