/**
  * Search for $term with shopware default search object
  * @param $term
  * @return bool Successfully ?
  */
 public function doSearch($term)
 {
     $adapter = Enlight()->Events()->filter('Shopware_Controllers_Frontend_Search_SelectAdapter', null);
     if (empty($adapter)) {
         $adapter = new Shopware_Components_Search_Adapter_Default(Shopware()->Db(), Shopware()->Cache(), new Shopware_Components_Search_Result_Default(), Shopware()->Config());
     }
     $search = new Shopware_Components_Search($adapter);
     $searchResults = $search->search($term, $this->getConfig());
     if ($searchResults !== false) {
         $resultCount = $searchResults->getResultCount();
         $resultArticles = $searchResults->getResult();
     } else {
         return false;
     }
     $basePath = $this->Request()->getScheme() . '://' . $this->Request()->getHttpHost() . $this->Request()->getBasePath();
     if (!empty($resultArticles)) {
         foreach ($resultArticles as &$result) {
             if (empty($result['type'])) {
                 $result['type'] = 'article';
             }
             if (!empty($result["mediaId"])) {
                 /**@var $mediaModel \Shopware\Models\Media\Media*/
                 $mediaModel = Shopware()->Models()->find('Shopware\\Models\\Media\\Media', $result["mediaId"]);
                 if ($mediaModel != null) {
                     $result["thumbNails"] = array_values($mediaModel->getThumbnails());
                     //deprecated just for the downward compatibility use the thumbNail Array instead
                     $result["image"] = $result["thumbNails"][1];
                 }
             }
             $result['link'] = $this->Front()->Router()->assemble(array('controller' => 'detail', 'sArticle' => $result['articleID'], 'title' => $result['name']));
         }
     }
     // Set result & count of result
     $this->setResults($resultArticles);
     $this->setCountResults($resultCount);
     return true;
 }
Exemple #2
0
    /**
     * Default search
     */
    public function defaultSearchAction()
    {
        $term = urldecode(trim(strip_tags(htmlspecialchars_decode(stripslashes($this->Request()->sSearch)))));

        // Load search configuration
        $config = $this->getSearchConfiguration($term);

        // Check if we have a one to one match for ordernumber, then redirect
        $location = $this->searchFuzzyCheck($term);
        if (!empty($location)) {
            return $this->redirect($location);
        }

        $this->View()->loadTemplate('frontend/search/fuzzy.tpl');

        // Prepare links for template
        $links = $this->searchDefaultPrepareLinks($config);

        $minLengthSearchTerm = Shopware()->Config()->sMINSEARCHLENGHT;

        // Check if search term met minimum length
        if (strlen($term) >= (int)$minLengthSearchTerm) {
            // Configure search adapter
            $adapter = Enlight()->Events()->filter('Shopware_Controllers_Frontend_Search_SelectAdapter',null);
            if (empty($adapter)){
                $adapter = new Shopware_Components_Search_Adapter_Default(Shopware()->Db(), Shopware()->Cache(), new Shopware_Components_Search_Result_Default(), Shopware()->Config());
            }

            $search = new Shopware_Components_Search($adapter);
            // Submit search request
            $searchResults = $search->search($term, $config);
            // Initiate variables
            $resultCount = 0;
            $resultArticles = array();
            $resultSuppliersAffected = array();
            $resultPriceRangesAffected = array();
            $resultCurrentCategory = array();

            // If search has results
            if ($searchResults !== false) {
                $resultCount = $searchResults->getResultCount();
                $resultArticles = $searchResults->getResult();
                $resultSuppliersAffected = $searchResults->getAffectedSuppliers();
                $resultPriceRangesAffected = $searchResults->getAffectedPriceRanges();
                $resultAffectedCategories = $searchResults->getAffectedCategories();
                $resultCurrentCategory = $searchResults->getCurrentCategoryFilter();
            }

            // Update search statistics
            $this->updateSearchStatistics($term, $resultCount);

            // Generate page array
            $sPages = $this->generatePagesResultArray($resultCount, $config['resultsPerPage'], $config["currentPage"]);

            // Get additional information for each search result
            $articles = array();
            foreach ($resultArticles as $article) {
                $article = Shopware()->Modules()->Articles()->sGetPromotionById('fix', 0, (int)$article["articleID"]);
                if (!empty($article['articleID'])) {
                    $articles[] = $article;
                }
            }

            // todo@all Build old template base compatibility array
            $resultSmartyArray = array(
                'sArticles' => $articles,
                'sArticlesCount' => $resultCount,
                'sSuppliers' => $resultSuppliersAffected,
                'sPrices' => $resultPriceRangesAffected,
                'sCategories' => $resultAffectedCategories,
                'sLastCategory' => $resultCurrentCategory
            );


            // Assign result to template
            $this->View()->sRequests = $config;
            $this->View()->sSearchResults = $resultSmartyArray;
            $this->View()->sPerPage = array_values(explode("|", Shopware()->Config()->sFUZZYSEARCHSELECTPERPAGE));
            $this->View()->sLinks = $links;
            $this->View()->sPages = $sPages;
            $this->View()->sPriceFilter = $search->getAdapter()->getPriceRanges();

            Enlight()->Events()->notify('Shopware_Controllers_Frontend_Search_ModifySearchResult',array("subject" => $this,"search"=>$search,"result"=>$searchResults));

            $this->View()->sCategoriesTree = $this->getCategoryTree(
                $resultCurrentCategory, $config['restrictSearchResultsToCategory']
            );
        }
    }
Exemple #3
0
    /**
     * Search for $term with shopware default search object
     * @param $term
     * @return bool Successfully ?
     */
    public function doSearch($term)
    {
        $adapter = Enlight()->Events()->filter('Shopware_Controllers_Frontend_Search_SelectAdapter',null);
        if (empty($adapter)){
            $adapter = new Shopware_Components_Search_Adapter_Default(Shopware()->Db(), Shopware()->Cache(), new Shopware_Components_Search_Result_Default(), Shopware()->Config());
        }
        $search = new Shopware_Components_Search($adapter);
        $searchResults = $search->search($term, $this->getConfig());

        if ($searchResults !== false) {
            $resultCount = $searchResults->getResultCount();
            $resultArticles = $searchResults->getResult();
        } else {
            return false;
        }

        $basePath = $this->Request()->getScheme() . '://' . $this->Request()->getHttpHost() . $this->Request()->getBasePath();

        if (!empty($resultArticles)) {
            foreach ($resultArticles as &$result) {
                if (empty($result['type'])) $result['type'] = 'article';
                if (!empty($result['image'])) {
                    $result['image'] = $basePath
                                     . '/media/image/thumbnail/' . $result['image']
                                     . '_57x57.'
                                     . $result['extension'];
                }
                $result['link'] = $this->Front()->Router()->assemble(array('controller' => 'detail', 'sArticle' => $result['articleID'], 'title' => $result['name']));
            }
        }

        // Set result & count of result
        $this->setResults($resultArticles);
        $this->setCountResults($resultCount);
        return true;
    }