Algolia_Algoliasearch_Helper_Data::rebuildStoreProductIndex PHP Méthode

rebuildStoreProductIndex() public méthode

public rebuildStoreProductIndex ( $storeId, $productIds )
    public function rebuildStoreProductIndex($storeId, $productIds)
    {
        if ($this->config->isEnabledBackend($storeId) === false) {
            $this->logger->log('INDEXING IS DISABLED FOR ' . $this->logger->getStoreName($storeId));
            return;
        }
        $emulationInfo = $this->startEmulation($storeId);
        try {
            $collection = $this->product_helper->getProductCollectionQuery($storeId, $productIds, false);
            $size = $collection->getSize();
            if (!empty($productIds)) {
                $size = max(count($productIds), $size);
            }
            $this->logger->log('Store ' . $this->logger->getStoreName($storeId) . ' collection size : ' . $size);
            if ($size > 0) {
                $pages = ceil($size / $this->config->getNumberOfElementByPage());
                $page = 1;
                $collection->clear();
                while ($page <= $pages) {
                    $this->rebuildStoreProductIndexPage($storeId, $collection, $page, $this->config->getNumberOfElementByPage(), $emulationInfo, $productIds);
                    $page++;
                }
            }
        } catch (Exception $e) {
            $this->stopEmulation($emulationInfo);
            throw $e;
        }
        $this->stopEmulation($emulationInfo);
    }

Usage Example

 public function rebuildProductIndex(Varien_Object $event)
 {
     $storeId = $event->getStoreId();
     $productIds = $event->getProductIds();
     $page = $event->getPage();
     $pageSize = $event->getPageSize();
     $useTmpIndex = (bool) $event->getUseTmpIndex();
     if (is_null($storeId) && !empty($productIds)) {
         foreach (Mage::app()->getStores() as $storeId => $store) {
             if (!$store->getIsActive()) {
                 continue;
             }
             $this->helper->rebuildStoreProductIndex($storeId, $productIds);
         }
     } else {
         if (!empty($page) && !empty($pageSize)) {
             $collection = $this->product_helper->getProductCollectionQuery($storeId, $productIds, $useTmpIndex);
             $this->helper->rebuildStoreProductIndexPage($storeId, $collection, $page, $pageSize, null, $productIds, $useTmpIndex);
         } else {
             $this->helper->rebuildStoreProductIndex($storeId, $productIds);
         }
     }
     return $this;
 }