public function searchLogDestroy($id)
 {
     $input = Input::all();
     $sessionId = Common::checkSessionLogin($input);
     Search::find($id)->delete();
     return Common::returnData(200, DELETE_SUCCESS, $input['user_id'], $sessionId);
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     $original_query = Tools::getValue('q');
     $query = Tools::replaceAccentedChars(urldecode($original_query));
     if ($this->ajax_search) {
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         if (is_array($searchResults)) {
             foreach ($searchResults as &$product) {
                 $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
             }
             Hook::exec('actionSearch', array('expr' => $query, 'total' => count($searchResults)));
         }
         $this->ajaxDie(Tools::jsonEncode($searchResults));
     }
     //Only controller content initialization when the user use the normal search
     parent::initContent();
     $product_per_page = isset($this->context->cookie->nb_item_per_page) ? (int) $this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE');
     if ($this->instant_search && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', $product_per_page));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', $product_per_page));
         $this->p = abs((int) Tools::getValue('p', 1));
         $original_query = $query;
         $query = Tools::replaceAccentedChars(urldecode($query));
         $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         if (is_array($search['result'])) {
             foreach ($search['result'] as &$product) {
                 $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
             }
         }
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) {
         $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result)));
         $this->addColorsToProductList($result);
         $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } else {
         $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl');
 }
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
     if ($this->ajax_search) {
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         foreach ($searchResults as &$product) {
             $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
         }
         die(Tools::jsonEncode($searchResults));
     }
     if ($this->instant_search && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize('home_default')));
     } else {
         if (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
             $this->productSort();
             $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
             $this->p = abs((int) Tools::getValue('p', 1));
             $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
             Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
             $nbProducts = $search['total'];
             $this->pagination($nbProducts);
             $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'homeSize' => Image::getSize('home_default')));
         } else {
             if (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) {
                 $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true);
                 $this->pagination($nbProducts);
                 $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
                 Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result)));
                 $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home_default')));
             } else {
                 $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
             }
         }
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl');
 }
 public function preProcess()
 {
     parent::preProcess();
     $query = urldecode(Tools::getValue('q'));
     if ($this->ajaxSearch) {
         self::$link = new Link();
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         if (is_array($searchResults)) {
             foreach ($searchResults as &$product) {
                 $product['product_link'] = self::$link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
             }
         }
         die(Tools::jsonEncode($searchResults));
     } elseif ($this->instantSearch && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'instantSearch' => $this->instantSearch, 'homeSize' => Image::getSize('home')));
     } elseif ($query = Tools::getValue('search_query', Tools::getValue('ref')) and !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'homeSize' => Image::getSize('home')));
     } elseif ($tag = urldecode(Tools::getValue('tag')) and !is_array($tag)) {
         $this->productSort();
         $nbProducts = (int) Search::searchTag((int) self::$cookie->id_lang, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag((int) self::$cookie->id_lang, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result)));
         self::$smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home')));
     } else {
         self::$smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'));
 }
 /**
  * Management of search
  *
  */
 public function manage()
 {
     if (!isset($this->wsObject->urlFragments['query']) || !isset($this->wsObject->urlFragments['language'])) {
         throw new WebserviceException('You have to set both the \'language\' and \'query\' parameters to get a result', array(100, 400));
     }
     $objects_products = array();
     $objects_categories = array();
     $objects_products['empty'] = new Product();
     $objects_categories['empty'] = new Category();
     $this->_resourceConfiguration = $objects_products['empty']->getWebserviceParameters();
     if (!$this->wsObject->setFieldsToDisplay()) {
         return false;
     }
     $results = Search::find($this->wsObject->urlFragments['language'], $this->wsObject->urlFragments['query'], 1, 1, 'position', 'desc', true, false);
     $categories = array();
     foreach ($results as $result) {
         $current = new Product($result['id_product']);
         $objects_products[] = $current;
         $categories_result = $current->getWsCategories();
         foreach ($categories_result as $category_result) {
             foreach ($category_result as $id) {
                 $categories[] = $id;
             }
         }
     }
     $categories = array_unique($categories);
     foreach ($categories as $id) {
         $objects_categories[] = new Category($id);
     }
     $this->output .= $this->objOutput->getContent($objects_products, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
     // @todo allow fields of type category and product
     // $this->_resourceConfiguration = $objects_categories['empty']->getWebserviceParameters();
     // if (!$this->setFieldsToDisplay())
     // return false;
     $this->output .= $this->objOutput->getContent($objects_categories, null, $this->wsObject->fieldsToDisplay, $this->wsObject->depth, WebserviceOutputBuilder::VIEW_LIST, false);
 }
    /**
     * Assign template vars related to page content
     * @see FrontController::initContent()
     */
    public function initContent()
    {
        $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
        $query_loc = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_loc')));
        $query_state = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_state')));
        $query_city = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_city')));
        $query_cat = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_cat')));
        $query_words = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_words')));
        $original_query = Tools::getValue('q');
        $original_query_loc = Tools::getValue('search_original');
        $query_original = Tools::getValue('search_original');
        $original_query_cat = Tools::getValue('search_cat');
        $original_query_words = Tools::getValue('search_words');
        if ($this->ajax_search) {
            // die(Tools::jsonEncode(array('key' => 'value')));
            $searchresult = array();
            $sqlcountry = 'SELECT *, country as countryflg FROM ' . _DB_PREFIX_ . 'product_lang where country LIKE "' . $query . '%" Group by country';
            $resultcountry = Db::getInstance()->ExecuteS($sqlcountry);
            $sqlstate = 'SELECT *, state as stateflg FROM ' . _DB_PREFIX_ . 'product_lang where state LIKE "' . $query . '%" Group by state';
            $resultstate = Db::getInstance()->ExecuteS($sqlstate);
            $sqlcity = 'SELECT *, city as cityflg FROM ' . _DB_PREFIX_ . 'product_lang where city LIKE "' . $query . '%" Group by city ';
            $resultcity = Db::getInstance()->ExecuteS($sqlcity);
            array_push($searchresult, $resultcountry);
            array_push($searchresult, $resultstate);
            array_push($searchresult, $resultcity);
            if ($resultcity == null && $resultstate == null && $resultcountry == null) {
                $sqlplace = 'SELECT *, concat_ws(" ",country,state) as allflg,country as country FROM ' . _DB_PREFIX_ . 'product_lang	
					where concat_ws(" ",country,state) LIKE "' . $query . '%" AND id_lang = 1 Group by state limit 5 ';
                $resultplace = Db::getInstance()->ExecuteS($sqlplace);
                $sqlplacecity = 'SELECT *, city as cityflg,country as country FROM ' . _DB_PREFIX_ . 'product_lang	
					where concat_ws(" ",country,city) LIKE "' . $query . '%" AND id_lang = 1 Group by city limit 5 ';
                $resultplacecity = Db::getInstance()->ExecuteS($sqlplacecity);
                array_push($searchresult, $resultplace);
                array_push($searchresult, $resultplacecity);
            }
            $searchresult = array_filter($searchresult);
            $searchresult = array_values($searchresult);
            // foreach ($results as $key => $values){
            // 	$results[$key]['cityflag'] = $resultscity;
            // }
            die(Tools::jsonEncode($searchresult));
            // die('<pre>'.print_r($searchresult,true));
        }
        //Only controller content initialization when the user use the normal search
        parent::initContent();
        if ($this->instant_search && !is_array($query)) {
            $this->productSort();
            $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
            $this->p = abs((int) Tools::getValue('p', 1));
            $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
            Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
            $nbProducts = $search['total'];
            $this->pagination($nbProducts);
            $this->addColorsToProductList($search['result']);
            $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
        } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
            $this->productSort();
            $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
            $this->p = abs((int) Tools::getValue('p', 1));
            $original_query = $query;
            $query = Tools::replaceAccentedChars(urldecode($query));
            $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
            foreach ($search['result'] as &$product) {
                $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
            }
            Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
            $nbProducts = $search['total'];
            $this->pagination($nbProducts);
            $this->addColorsToProductList($search['result']);
            $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
        } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) {
            $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true);
            $this->pagination($nbProducts);
            $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
            Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result)));
            $this->addColorsToProductList($result);
            $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
        } elseif ($query_loc !== "" || $query_cat !== "" || $query_words !== "" || $query_state !== "" || $query_city !== "" || $query_original !== "") {
            $this->productSort();
            $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
            $this->p = abs((int) Tools::getValue('p', 1));
            $query_arr = array('words' => $query_words, 'location' => $query_loc, 'city' => $query_city, 'state' => $query_state, 'original' => $query_original, 'category' => $query_cat);
            $search = Search::find($this->context->language->id, $query_arr, $this->p, $this->n, $this->orderBy, $this->orderWay);
            foreach ($search['result'] as &$product) {
                $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
            }
            Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
            $nbProducts = $search['total'];
            $this->pagination($nbProducts);
            /*foreach($search['result'] as $k => $v) {
            			$country = $v['country'];
            			$flagId = Country::getIdByName(1, $country);
            			$search['result'][$k]['img_exist']	= file_exists(_PS_ROOT_DIR_ . DS . 'flag' . DS . 'mini'. DS . $flagId . '.jpg')? 1 : 0;
            			$search['result'][$k]['img_name']	= $flagId . '.jpg';
            		}*/
            foreach ($search['result'] as $key => $value) {
                $seller_id = $value['id_seller'];
                $flagIds = self::getFlagsId($seller_id);
                foreach ($flagIds as $k => $flgId) {
                    $search['result'][$key]['img_exist'][$k] = file_exists(_PS_ROOT_DIR_ . DS . 'flag' . DS . 'mini' . DS . $flgId . '.jpg') ? 1 : 0;
                    $search['result'][$key]['img_name'][$k] = $flgId . '.jpg';
                }
            }
            // die('<pre>' . print_r($search['result'], true));
            $this->addColorsToProductList($search['result']);
            $original_query = array();
            if ($query_loc != "") {
                array_push($original_query, $query_original);
            }
            if ($query_words != "") {
                array_push($original_query, $query_words);
            }
            $original_query_text = implode(" ", $original_query);
            $cat_name = $original_query_cat == 0 ? 'All Categories' : self::getCategoryName($original_query_cat);
            $this->context->smarty->assign(array('products' => $search['result'], 'search_words' => $original_query_words, 'search_products' => $search['result'], 'cat_id' => $original_query_cat, 'cat_name' => $cat_name, 'nbProducts' => $search['total'], 'search_query' => @$query_loc . ' ' . @$query_state . ' ' . @$query_city, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
        } else {
            $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
        }
        $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
        $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl');
    }
Example #7
0
function parseSearch($intElmntId, $strCommand)
{
    global $_PATHS, $objLang, $DBAConn;
    $objTpl = new HTML_Template_IT($_PATHS['templates']);
    $objTpl->loadTemplatefile("search.tpl.htm");
    $objTpl->setVariable("TITLE", $objLang->get("pageTitle"));
    $objTpl->setVariable("MAINTITLE", $objLang->get("pcmsSearch", "menu"));
    $objTpl->setVariable("BUTTON_INDEX_HREF", "?cid=" . NAV_PCMS_SEARCH . "&amp;cmd=" . CMD_BUILD_INDEX);
    $objTpl->setVariable("BUTTON_INDEX", $objLang->get("searchIndex", "button"));
    $objTpl->setVariable("SEARCH_BUTTON", $objLang->get("search", "button"));
    $objTpl->setVariable("SEARCH_ALL", $objLang->get("searchall", "label"));
    //*** Perform query if submitted.
    $objSearch = new Search();
    $strQuery = request('query');
    $strExact = request('search_all');
    $strCache = request('cache');
    $intPosition = request("pos");
    $blnExact = false;
    $blnCache = false;
    if ($strExact == 'on') {
        $blnExact = true;
    }
    if ($strCache == 'true') {
        $blnCache = true;
    }
    if ($strCommand == CMD_BUILD_INDEX) {
        //*** Rebuild search index.
        set_time_limit(60 * 60);
        $objSearch->clearIndex();
        $objSearch->updateIndex();
        $objTpl->setVariable("SEARCH_DESCRIPTION", $objLang->get("searchIndexed", "form"));
    }
    if (!empty($strQuery)) {
        $objResults = $objSearch->find($strQuery, $blnExact);
        //*** Cache results in the current session.
        $_SESSION["searchresult"] = serialize($objResults);
    } else {
        if ($blnCache && isset($_SESSION["searchresult"]) && is_object(unserialize($_SESSION["searchresult"]))) {
            $objResults = unserialize($_SESSION["searchresult"]);
        }
    }
    if (isset($objResults) && is_object($objResults)) {
        $objTpl->setVariable("RESULT_LABEL", $objLang->get("searchresult", "label"));
        $objTpl->setVariable("SEARCH_STRING", $objResults->getQuery());
        if ($objResults->count() > 0) {
            $listCount = 0;
            $intPosition = !empty($intPosition) && is_numeric($intPosition) ? $intPosition : 0;
            $intPosition = floor($intPosition / $_SESSION["listCount"]) * $_SESSION["listCount"];
            $objResults->seek($intPosition);
            //*** Render results.
            foreach ($objResults as $objResult) {
                $objElement = Element::selectByPK($objResult->id);
                if (is_object($objElement)) {
                    $strPath = "<b>" . $objLang->get("path", "label") . "</b>" . Element::recursivePath($objElement->getParentId());
                } else {
                    $strPath = "";
                }
                $objTpl->setCurrentBlock("searchresult");
                $objTpl->setVariable("EID", $objResult->id);
                $objTpl->setVariable("CID", NAV_PCMS_ELEMENTS);
                $objTpl->setVariable("CMD", CMD_EDIT);
                $objTpl->setVariable("RESULT_NAME", $objResult->name);
                $objTpl->setVariable("RESULT_RATIO", $objResult->ratio);
                $strValue = strip_tags($objResult->value);
                if (!empty($strValue)) {
                    $objTpl->setVariable("RESULT_VALUE", $strValue);
                }
                if (!empty($strPath)) {
                    $objTpl->setVariable("RESULT_PATH", $strPath);
                }
                $objTpl->parseCurrentBlock();
            }
            //*** Render page navigation.
            $pageCount = ceil($objResults->count() / $_SESSION["listCount"]);
            if ($pageCount > 0) {
                $currentPage = ceil(($intPosition + 1) / $_SESSION["listCount"]);
                $previousPos = $intPosition - $_SESSION["listCount"] > 0 ? $intPosition - $_SESSION["listCount"] : 0;
                $nextPos = $intPosition + $_SESSION["listCount"] < $objResults->count() ? $intPosition + $_SESSION["listCount"] : $intPosition;
                $objTpl->setVariable("PAGENAV_PAGE", sprintf($objLang->get("pageNavigation", "label"), $currentPage, $pageCount));
                $objTpl->setVariable("PAGENAV_PREVIOUS", $objLang->get("previous", "button"));
                $objTpl->setVariable("PAGENAV_PREVIOUS_HREF", "?cid=" . NAV_PCMS_SEARCH . "&amp;pos={$previousPos}&amp;cache=true");
                $objTpl->setVariable("PAGENAV_NEXT", $objLang->get("next", "button"));
                $objTpl->setVariable("PAGENAV_NEXT_HREF", "?cid=" . NAV_PCMS_SEARCH . "&amp;pos={$nextPos}&amp;cache=true");
                //*** Bottom page navigation.
                for ($intCount = 0; $intCount < $pageCount; $intCount++) {
                    $objTpl->setCurrentBlock("pagenavitem");
                    $position = $intCount * $_SESSION["listCount"];
                    if ($intCount != $intPosition / $_SESSION["listCount"]) {
                        $objTpl->setVariable("PAGENAV_HREF", "href=\"?cid=" . NAV_PCMS_SEARCH . "&amp;pos={$position}&amp;cache=true\"");
                    }
                    $objTpl->setVariable("PAGENAV_VALUE", $intCount + 1);
                    $objTpl->parseCurrentBlock();
                }
            }
        } else {
            $objTpl->setCurrentBlock("searchresult");
            $objTpl->setVariable("RESULT_VALUE", $objLang->get("search_noresult", "label"));
            $objTpl->parseCurrentBlock();
        }
    }
    $objTpl->setVariable("CID", NAV_PCMS_SEARCH);
    $strReturn = $objTpl->get();
    return $strReturn;
}
<?php

if (isset($_GET['q'])) {
    require_once 'config.php';
    define('ID_LANG', 1);
    $q = $_GET['q'];
    $results = Search::find($q);
    $response = "";
    foreach ($results as $result) {
        $response .= '<a href="index.php?page=bookings&id=' . $result->id . '">Reserva: #' . $result->id . '&nbsp;- ' . $result->name . '&nbsp;' . $result->email . '&nbsp;' . $result->dni . '</a><br>';
    }
    if ($response == "") {
        $response = "no encontrado";
    }
    echo $response;
}
Example #9
0
 public static function searchFormData($searchId = 0)
 {
     $priceArray = self::priceFormArray();
     $categoryArray = self::categoryFormArray();
     // $categoryArray = CommonCategory::categoryArray();
     // $typeArray = selectProductType();
     $typeArray = CommonCategory::typeArray();
     $timeArray = CommonCategory::timeArray();
     $cityArray = Common::listCity();
     $id = null;
     $name = null;
     $lat = null;
     $long = null;
     $price_id = null;
     $category_id = null;
     $type_id = null;
     $time_id = null;
     $city_id = null;
     if ($searchId > 0) {
         $search = Search::find($searchId);
         if (count($search) > 0) {
             $id = $searchId;
             $name = $search->name;
             $lat = $search->lat;
             $long = $search->long;
             $city_id = $search->city_id;
             $price_id = $search->price_id;
             $category_id = $search->category_id;
             $type_id = $search->type_id;
             $time_id = $search->time_id;
             $city = $search->city;
         }
     }
     $data = array('id' => $id, 'name' => $name, 'lat' => $lat, 'long' => $long, 'city_id' => $city_id, 'price_id' => $price_id, 'category_id' => $category_id, 'type_id' => $type_id, 'time_id' => $time_id, 'categoryArray' => $categoryArray, 'typeArray' => $typeArray, 'timeArray' => $timeArray, 'cityArray' => $cityArray);
     return $data;
 }
Example #10
0
<?php

include dirname(__FILE__) . '/config/config.inc.php';
if (Tools::getValue('ajaxSearch') and $query = urldecode(Tools::getValue('q')) and !is_array($query)) {
    include dirname(__FILE__) . '/init.php';
    $link = new Link();
    $search = Search::find(intval(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true);
    foreach ($search as $product) {
        echo $product['id_product'] . '|' . $product['pname'] . '|' . $product['cname'] . '|' . $link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']) . "\n";
    }
    die;
}
include dirname(__FILE__) . '/header.php';
include dirname(__FILE__) . '/product-sort.php';
if ($query = Tools::getValue('search_query', Tools::getValue('tag', Tools::getValue('ref'))) and !is_array($query)) {
    $n = abs(intval(Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'))));
    $p = abs(intval(Tools::getValue('p', 1)));
    $search = Search::find(intval($cookie->id_lang), $query, $p, $n, $orderBy, $orderWay);
    $nbProducts = $search['total'];
    include dirname(__FILE__) . '/pagination.php';
    $smarty->assign(array('products' => $search['result'], 'nbProducts' => $search['total'], 'query' => $query));
} else {
    $smarty->assign(array('products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
}
$smarty->display(_PS_THEME_DIR_ . 'search.tpl');
include dirname(__FILE__) . '/footer.php';
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $this->context->smarty->assign(array('HOOK_LEFT_COLUMN' => Hook::exec('displayLeftColumn')));
     $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
     $original_query = Tools::getValue('q');
     if ($this->ajax_search) {
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         foreach ($searchResults as &$product) {
             $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
         }
         die(Tools::jsonEncode($searchResults));
     }
     if ($this->instant_search && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         $products = $search['result'];
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $original_query = $query;
         $query = Tools::replaceAccentedChars(urldecode($query));
         $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         foreach ($search['result'] as &$product) {
             $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
         }
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         $this->addColorsToProductList($search['result']);
         $products = $search['result'];
         $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($tag = urldecode(Tools::getValue('tag'))) && !is_array($tag)) {
         $nbProducts = (int) Search::searchTag($this->context->language->id, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag($this->context->language->id, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Hook::exec('actionSearch', array('expr' => $tag, 'total' => count($result)));
         $this->addColorsToProductList($result);
         $products = $result;
         $this->context->smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } else {
         $products = array();
         $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     if ($this->ajax) {
         $product_list = $this->context->smarty->fetch(_PS_THEME_DIR_ . 'product-list.tpl');
         $pagination = $this->context->smarty->fetch(_PS_THEME_DIR_ . 'pagination.tpl');
         $nbLeftProducts = $nbProducts - ($this->n * ($this->p - 1) + count($products));
         $nbLeftProductsPercentage = ($nbProducts - $nbLeftProducts) / $nbProducts * 100;
         echo Tools::jsonEncode(array('productList' => utf8_encode($product_list), 'pagination' => $pagination, 'nbRenderedProducts' => $nbProducts, 'nbLeftProducts' => $nbLeftProducts, 'nbLeftProductsPercentage' => $nbLeftProductsPercentage));
         die;
     } else {
         $this->setTemplate(_PS_THEME_DIR_ . 'search.tpl');
     }
 }
Example #12
0
<?php

//namespace Klarschiff;
require_once dirname(__FILE__) . "/conf/config.php";
require_once dirname(__FILE__) . "/Search.php";
$search = new Search($solrConf);
$result = $search->find(isset($_GET["searchtext"]) ? $_GET["searchtext"] : "*");
$backend = isset($_GET["backend"]) && strtolower($_GET["backend"]) === 'true';
$resultJson = array("result" => "", "array" => array());
function generateHtml($href, $name, $type, $title, $backend)
{
    $class = $backend ? "resultElement" : "result-element";
    return '<div class="' . $class . '">&nbsp;<a href="' . $href . '" name="' . $name . '" class="gotoBBOX">' . $title . '</a><span>' . $type . '</span></div>';
}
function generateJson($bbox_array, $type, $title)
{
    return array("label" => $title, "bbox" => $bbox_array);
}
foreach ($result->documents as $doc) {
    $data = json_decode($doc->json, true);
    $type = strtolower($data["type"]);
    $bbox_array = array();
    if (substr($data['geom'], 0, 3) == "BOX") {
        foreach (explode(",", substr($data['geom'], 4, -1)) as $i) {
            foreach (explode(" ", $i) as $j) {
                $bbox_array[] = $j;
            }
        }
    }
    if ($type === "ort") {
        $title = $data['ort_name'];
Example #13
0
 /**
  * Assign search template
  */
 public function assign()
 {
     $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
     $original_query = Tools::getValue('q');
     $id_category = Tools::getValue('id_category');
     if (Tools::getValue('ajax_Search')) {
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, (int) Tools::getValue('limit', 10), 'position', 'desc', true);
         $results = array();
         foreach ($searchResults as $product) {
             $cover = Product::getCover($product['id_product']);
             $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
             $product['product_image'] = $this->context->link->getImageLink($product['prewrite'], $cover['id_image'], 'home_default');
             $product['id_category'] = $id_category;
             $product['categories'] = Product::getProductCategories($product['id_product']);
             if ($id_category == 'all' || in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                 $results[] = $product;
             }
         }
         die(Tools::jsonEncode($results));
     }
     if (Tools::getValue('instantSearch') && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find($this->context->language->id, $query, 1, 10, 'position', 'desc');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $results = array();
         $index = 0;
         foreach ($search['result'] as $product) {
             $categories_id = Product::getProductCategories($product['id_product']);
             if (in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                 if (($this->p - 1) * $this->n <= $index && $index < $this->p * $this->n) {
                     $results[] = $product;
                 }
                 $index++;
             }
         }
         $nbProducts = $index;
         $this->pagination($nbProducts);
         $this->addColorsToProductList($results);
         $this->context->smarty->assign(array('products' => $results, 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $original_query, 'instant_search' => $this->instant_search, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch'), 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
     } elseif (($query = Tools::getValue('search_query', Tools::getValue('ref'))) && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $original_query = $query;
         $query = Tools::replaceAccentedChars(urldecode($query));
         $search = Search::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay);
         //if($this->orderBy == 'price') $search['result'] = Tools::orderbyPrice($search['result'], $this->orderWay);
         //print_r($search['result']);
         //die;
         foreach ($search['result'] as &$product) {
             $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'];
         }
         $results = array();
         $id_category = Tools::getValue('search_category', 'all');
         Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->context->smarty->assign(array('search_query' => $original_query, 'homeSize' => Image::getSize(ImageType::getFormatedName('home'))));
         if ($id_category == 'all') {
             $this->pagination($nbProducts);
             $this->addColorsToProductList($search['result']);
             $this->context->smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'nbp' => $this->p, 'nbn' => $this->n, 'orderby' => $this->orderBy, 'orderWay' => $this->orderWay, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch')));
         } else {
             $search = Search::find($this->context->language->id, $query, 1, $nbProducts, $this->orderBy, $this->orderWay);
             $results = array();
             $index = 0;
             foreach ($search['result'] as $product) {
                 $categories_id = Product::getProductCategories($product['id_product']);
                 if (in_array((int) $id_category, Product::getProductCategories($product['id_product']))) {
                     if (($this->p - 1) * $this->n <= $index && $index < $this->p * $this->n) {
                         $results[] = $product;
                     }
                     $index++;
                 }
             }
             $nbProducts = $index;
             foreach ($results as &$product) {
                 $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $nbProducts;
             }
             $this->pagination($nbProducts);
             $this->addColorsToProductList($results);
             $this->context->smarty->assign(array('products' => $results, 'search_products' => $results, 'nbProducts' => $nbProducts, 'nbp' => $this->p, 'nbn' => $this->n, 'orderby' => $this->orderBy, 'orderWay' => $this->orderWay, 'request' => $this->context->link->getModuleLink('categorysearch', 'catesearch')));
         }
     } else {
         $this->context->smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     $this->context->smarty->assign(array('add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM')));
     $this->setTemplate('searchresult.tpl');
 }
 public function preProcess()
 {
     parent::preProcess();
     $query = urldecode(Tools::getValue('q'));
     if ($this->ajaxSearch) {
         self::$link = new Link();
         $searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
         foreach ($searchResults as &$product) {
             $product['product_link'] = self::$link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
         }
         die(Tools::jsonEncode($searchResults));
     }
     if ($this->instantSearch && !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         $search = Search::find((int) self::$cookie->id_lang, $query, $this->p, $this->n, 'position', 'desc');
         Module::hookExec('search', array('expr' => $query, 'total' => $search['total']));
         $nbProducts = $search['total'];
         $this->pagination($nbProducts);
         self::$smarty->assign(array('products' => $search['result'], 'search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => $query, 'instantSearch' => $this->instantSearch, 'homeSize' => Image::getSize('home')));
     } elseif ($query = Tools::getValue('search_query', Tools::getValue('ref')) and !is_array($query)) {
         $this->productSort();
         $this->n = abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE')));
         $this->p = abs((int) Tools::getValue('p', 1));
         //$search = Search::find((int)(self::$cookie->id_lang), $query, $this->p, $this->n, 'position', 'desc');
         $other_results = false;
         try {
             //get the right address for this cart
             global $cart, $cookie;
             $id_country = (int) Country::getDefaultCountryId();
             if ($cart->id_address_delivery) {
                 $address = new Address($cart->id_address_delivery);
                 if ($address->id_country) {
                     $id_country = $address->id_country;
                 } elseif (isset($cookie->id_country)) {
                     $id_country = (int) $cookie->id_country;
                 }
             }
             self::$smarty->assign('price_tax_country', $id_country);
             $resultSet = Search::searchProducts($query, $this->p, $this->n, $other_results);
             $products = $resultSet->getData();
             $products = $products['response']['docs'];
             $total_results = $resultSet->getNumFound();
         } catch (Exception $e) {
             self::$smarty->assign('fetch_error', 1);
         }
         Module::hookExec('search', array('expr' => $query, 'total' => $total_results));
         $this->pagination($total_results);
         self::$smarty->assign(array('products' => $products, 'search_products' => $products, 'nbProducts' => $total_results, 'search_query' => $query, 'homeSize' => Image::getSize('home'), 'ssResults' => $other_results));
         $generic_description = "Buy the widest range of sarees, salwar kameez, kurtis, tunics and ghaghra cholis by shopping online at IndusDiva.com, India's leading online store for buying #phrase#. All products are double-checked for quality before they get shipped and we take extra care to ensure the safety of your order. We deliver products all over the world through leading courier service providers to ensure timely and hassle-free deliveries.\n\t\t\t\t\t\t\t\t\t<br><br>\n\t\t\t\t\t\t\t\t\tTo buy #phrase#, all you need to do is review your shopping cart and provide the address details and phone number at checkout. IndusDiva.com offers the best available price across all online shopping sites and provides the best collection of Indian wear online. Shopping for Indian saris, blouse and salwar kurta online just turned more fun as getting your hands on #phrase# has never been so easy.";
         $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS("select description from ps_seo_keywords where keyword = '" . $query . "'");
         if (count($res) > 0) {
             self::$smarty->assign('search_description', str_replace('#phrase#', $query, $res[0]['description']));
         } else {
             self::$smarty->assign('search_description', str_replace('#phrase#', $query, $generic_description));
         }
     } elseif ($tag = urldecode(Tools::getValue('tag')) and !is_array($tag)) {
         $nbProducts = (int) Search::searchTag((int) self::$cookie->id_lang, $tag, true);
         $this->pagination($nbProducts);
         $result = Search::searchTag((int) self::$cookie->id_lang, $tag, false, $this->p, $this->n, $this->orderBy, $this->orderWay);
         Module::hookExec('search', array('expr' => $tag, 'total' => sizeof($result)));
         self::$smarty->assign(array('search_tag' => $tag, 'products' => $result, 'search_products' => $result, 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home')));
     } else {
         self::$smarty->assign(array('products' => array(), 'search_products' => array(), 'pages_nb' => 1, 'nbProducts' => 0));
     }
     self::$smarty->assign('add_prod_display', Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'));
     self::$smarty->assign('lazy', 1);
 }
Example #15
0
 function process_ticket()
 {
     $this->load->model('search');
     $data['main_content'] = 'backend/bookings/process_ticket';
     $data['title'] = 'Book a ticket';
     $data['db_data'] = Search::find($this->input->get());
     $data['get_data'] = $this->input->get();
     $this->load->view('includes/template', $data);
 }
Example #16
0
 public function find($strQuery, $arrFilters = array(), $blnExact = FALSE, $arrAllowedTypes = array())
 {
     /* Search for elements containing keywords
      *
      * Filters may look like this:
      * array("element.Shops", "template.HomePage > element.Misc > templates.Banner", "element:1399")
      *
      * Allowed types may look like this:
      * array("element.Shops", "template.HomePage", "element:1399")
      *
      */
     $objReturn = new SearchResults();
     if (!empty($strQuery)) {
         $objSearch = new Search();
         $objReturn = $objSearch->find($strQuery, $blnExact);
         //*** Filters.
         if (count($arrFilters) > 0) {
             //*** Parse filters.
             $arrElementIds = array();
             foreach ($arrFilters as $strFilter) {
                 $arrRecursive = explode(">", $strFilter);
                 $objElement = $this;
                 foreach ($arrRecursive as $strRecursive) {
                     $arrFilter = explode(".", trim($strRecursive));
                     if (!empty($arrFilter[1])) {
                         switch ($arrFilter[0]) {
                             case "element":
                                 if (is_numeric($arrFilter[1])) {
                                     $objElement = $this->getElementById($arrFilter[1]);
                                 } else {
                                     $objElement = $objElement->get($arrFilter[1]);
                                 }
                                 break;
                             case "elements":
                                 if (is_numeric($arrFilter[1])) {
                                     $objElement = $this->getElementById($arrFilter[1])->getElements();
                                 } else {
                                     $objElement = $objElement->getElements($arrFilter[1]);
                                 }
                                 break;
                             case "template":
                                 if (is_numeric($arrFilter[1])) {
                                     $objElement = $objElement->getElementByTemplateId($arrFilter[1]);
                                 } else {
                                     $objElement = $objElement->getElementByTemplate($arrFilter[1]);
                                 }
                                 break;
                             case "templates":
                                 if (is_numeric($arrFilter[1])) {
                                     $objElement = $objElement->getElementsByTemplateId($arrFilter[1]);
                                 } else {
                                     $objElement = $objElement->getElementsByTemplate($arrFilter[1]);
                                 }
                                 break;
                         }
                     }
                 }
                 if (method_exists($objElement, "count")) {
                     $objElements = $objElement;
                     foreach ($objElements as $objElement) {
                         array_push($arrElementIds, $objElement->getElement()->getId());
                     }
                 } else {
                     array_push($arrElementIds, $objElement->getElement()->getId());
                 }
             }
             //*** Apply filters.
             $objResults = new SearchResults();
             $objResults->setQuery($objReturn->getQuery());
             foreach ($objReturn as $objResult) {
                 foreach ($arrElementIds as $intElementId) {
                     $objElement = $this->getElementById($objResult->id);
                     if (is_object($objElement) && $objElement->hasParentId($intElementId)) {
                         if (count($arrAllowedTypes) > 0) {
                             foreach ($arrAllowedTypes as $allowedType) {
                                 $arrFilter = explode(".", trim($allowedType));
                                 if (!empty($arrFilter[1])) {
                                     switch ($arrFilter[0]) {
                                         case "element":
                                             if (is_numeric($arrFilter[1])) {
                                                 if ($objElement->getId() == $arrFilter[1]) {
                                                     $objResults->addObject($objResult);
                                                 }
                                             } else {
                                                 if ($objElement->getName() == $arrFilter[1]) {
                                                     $objResults->addObject($objResult);
                                                 }
                                             }
                                             break;
                                         case "template":
                                             if ($objElement->getTemplateName() == $arrFilter[1]) {
                                                 $objResults->addObject($objResult);
                                             }
                                             break;
                                     }
                                 }
                             }
                         } else {
                             $objResults->addObject($objResult);
                         }
                     }
                 }
             }
             $objReturn = $objResults;
         }
     }
     return $objReturn;
 }
<?php

include_once '../../config/config.inc.php';
include_once '../../init.php';
//$this->instant_search = Tools::getValue('instantSearch');
//$this->ajax_search = Tools::getValue('ajaxSearch');
//parent::initContent();
$query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q')));
$original_query = Tools::getValue('q');
$searchResults = Search::find((int) Tools::getValue('id_lang'), $query, 1, 10, 'position', 'desc', true);
foreach ($searchResults as &$product) {
    //$product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
    $links = new Link();
    $product['product_link'] = $links->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']);
    /**
                *Get product cover
                */
    $tdgetpover = Product::getCover($product['id_product']);
    $cproduct_image = new Image($tdgetpover['id_image']);
    $cproductimg_url = $cproduct_image->getExistingImgPath() . '-small_default.jpg';
    $product['ajaxsearchimage'] = $cproductimg_url;
}
die(Tools::jsonEncode($searchResults));
Example #18
0
 public function search()
 {
     if (func_num_args() != 0) {
         return false;
     }
     // Check that the function is called with correct number of arguments
     if (Tools::illegalRequest(array("keywords"))) {
         return false;
     }
     if ($_SERVER['REQUEST_METHOD'] == 'POST') {
         new View('search.tpl', array('hits' => Search::find($_POST['keywords'])));
         return true;
     }
     new View('search.tpl');
     return true;
 }