Détail du message 80090.3

Message numéro 3 dans le sujet Indexation Facette.

  • 80090.3 en réponse à 80090.2 écrit par Jean-Michel

    16/08/2013 16:33


    hioli01
    Rang : Adepte
    bonjour ,
    oui voila le code qui a été fait en spec pour l'affichage des produits par brand

        function getRequestModuleNames()
        {
            return array_merge(array('brand', 'ecomextended'), parent::getRequestModuleNames());
        }
        
    	/**
    	 * @param f_mvc_Request $request
    	 * @param Boolean $returnIds
    	 * @return catalog_persistentdocument_product[]
    	 */
    	protected function getProductArray($request, $returnIds = false)
    	{
    		$cfg = $this->getConfiguration();
    		$ctx = $this->getPage();
    		$showAll = $request->hasNonEmptyParameter('showAll') ? f_util_Convert::toBoolean($request->getParameter('showAll')) : false;
    		$primaryOnly = true;
    		$request->setAttribute('showAll', $showAll);
    		
    		$complQuery = null;
    
    		/** SPE **/
    		$brand = $this->getDocumentParameter();
    		if($brand instanceof brand_persistentdocument_brand)
    		{
    		    $queryString = new indexer_TermQuery(indexer_Field::getVolatileIntegerFieldName("brandId"), $brand->getId());
    		}
    		else
    		{
    		    return array();
    		}
    		/** SPE **/
    		
    		$currentPage = $this->getCurrentPageNumber();
    		$itemsPerPage = $this->getNbItemsPerPage();
    		
    		$op = $this->findLocalParameterValue('op', 'AND');
    		
    		$query = $this->getStandardQuery($request, $queryString, $currentPage, $itemsPerPage, $op);
    		$this->addFacets($query);
    		$filter = $this->createFilter($showAll, $primaryOnly);
    		$query->setFilterQuery($filter);
    		
    		$this->getPage()->setAttribute("ecomextended_BlockSearchresultsAction_queryNoFilter", clone ($query));
    		
    		$hasFilter = $this->applyFilters($query, $request);
    		$sort = $this->setSort($query);	
    		$searchResults = indexer_IndexService::getInstance()->search($query);
    		
    		// Error during search...
    		if ($searchResults === null)
    		{
    			$error = LocaleService::getInstance()->transFO('m.solrsearch.frontoffice.error-during-search', array('ucf', 'html'));
    			$this->addError($error);
    			return null;
    		}
    		
    		if ($complQuery !== null)
    		{
    			$complementaryResults = indexer_IndexService::getInstance()->search($complQuery);
    			if ($complementaryResults->getTotalHitsCount() > 0)
    			{
    				$request->setAttribute("complementaryResults", $complementaryResults);
    			}
    		}
    		
    		$this->completeSearchResults($searchResults);
    		
    		$totalHitsCount = $searchResults->getTotalHitsCount();
    		$pageHitsCount = $searchResults->count();
    		$request->setAttribute('searchResults', $searchResults);
    		$request->setAttribute('noHits', $pageHitsCount == 0);
    		$this->getContext()->setAttribute(ecomextended_BlockSearchresultsAction::SEARCHRESULTS_ATTR, $searchResults);
    		if ($totalHitsCount > 0)
    		{
    			$products = array();
    			$productIds = array();
    			$returnedMinOffset = $itemsPerPage*($currentPage-1);
    			$returnedMaxOffset = $returnedMinOffset + $itemsPerPage;
    			$optimizeQuery = $this->getConfiguration()->getOptimizeQuery();
    			$i = $optimizeQuery ?  $returnedMinOffset : 0;
    			
    			foreach ($searchResults as $searchResult)
    			{
    				if (($i < $returnedMinOffset || $i >= $returnedMaxOffset))
    				{
    					if (!$optimizeQuery)
    					{
    						$productIds[] = intval($searchResult->getProductId());
    					}
    				}
    				else 
    				{
    					if ($returnIds)
    					{
    						$products[] = intval($searchResult->getProductId());
    					}
    					else
    					{
    						$products[] = DocumentHelper::getDocumentInstance(intval($searchResult->getProductId())); 
    					}
    					$productIds[] = intval($searchResult->getProductId());
    				}
    				$i++;
    			}
    
    			$paginator = new paginator_Paginator('ecomextended', $currentPage, $products, $itemsPerPage);
    			$paginator->setPageCount((int) ceil($totalHitsCount / $itemsPerPage));
    			$paginator->setCurrentPageNumber($currentPage);			
    			$request->setAttribute('blockTitle', $this->getBlockTitle());
    			$request->setAttribute('blockView', $this->getDisplayMode($request));
    			$request->setAttribute('productIds', $productIds);
    			
    			$formaters = array('ucf', 'html');
    		
    			$request->setAttribute("sortOptions", $this->getSortOptions($formaters));
    			return $paginator;
    		}
    		return $hasFilter ? array() : null;
    	}
    	
    	protected function createFilter($showAll = false, $primaryOnly = true)
    	{
    		$website = website_WebsiteModuleService::getInstance()->getCurrentWebsite();
    		$filter = indexer_QueryHelper::andInstance();
    		$filter->add(indexer_QueryHelper::websiteIdRestrictionInstance($website->getId()));
    		if (!$primaryOnly)
    		{
    			$filter->add(indexer_QueryHelper::accessRestrictionInstance(array(-1)));
    		}
    		if (!$showAll)
    		{
    			$filter->add(new indexer_TermQuery("documentModel", "modules_catalog/compiledproduct"));
    		}
    		return $filter;
    	}
    


    Ce n'est pas très évident de comprendre un code qui a été fait en spec surtout quand il y n'a pas de commentaires.
    Merci d'avance.
    Bien Cordialement.

    Développeur et intégrateur web
    RBSChange V 3.5.2 e-commerce
 
1372 membres
Aucun membre connecté