/** * 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')); }
/** * 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'); }
public function initContent() { include _PS_MODULE_DIR_ . 'blocksearch_mod' . DIRECTORY_SEPARATOR . 'IqitSearch.php'; $query = Tools::replaceAccentedChars(urldecode(Tools::getValue('q'))); $original_query = Tools::getValue('q'); $search_query_cat = (int) Tools::getValue('search_query_cat'); if ($this->ajax_search) { self::$link = new Link(); $image = new Image(); $searchResults = IqitSearch::find((int) Tools::getValue('id_lang'), $query, $search_query_cat, 1, 10, 'position', 'desc', true); $taxes = Product::getTaxCalculationMethod(); $currency = (int) Context::getContext()->currency->id; $iso_code = $this->context->language->iso_code; if (is_array($searchResults)) { foreach ($searchResults as &$product) { $imageID = $image->getCover($product['id_product']); if (isset($imageID['id_image'])) { $imgLink = $this->context->link->getImageLink($product['prewrite'], (int) $product['id_product'] . '-' . $imageID['id_image'], 'small_default'); } else { $imgLink = _THEME_PROD_DIR_ . $iso_code . "-default-small_default.jpg"; } $product['product_link'] = $this->context->link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); $product['obr_thumb'] = $imgLink; $product['product_price'] = Product::getPriceStatic((int) $product['id_product'], false, NULL, 2); if ($taxes == 0 or $taxes == 2) { $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], true), $currency); } elseif ($taxes == 1) { $product['product_price'] = Tools::displayPrice(Product::getPriceStatic((int) $product['id_product'], false), $currency); } } } $this->ajaxDie(Tools::jsonEncode($searchResults)); } // 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', $product_per_page)); $this->p = abs((int) Tools::getValue('p', 1)); $search = IqitSearch::find($this->context->language->id, $query, $search_query_cat, 1, 10, 'position', 'desc'); Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); $this->addColorsToProductList($search['result']); if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($search['result'][$i]['id_product'])) { $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } $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 = IqitSearch::find($this->context->language->id, $query, $search_query_cat, $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']); /************************* /Images Array ******************************/ if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($search['result'][$i]['id_product'])) { $image_array[$search['result'][$i]['id_product']] = Product::getProductsImgs($search['result'][$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } /************************* /Images Array ******************************/ $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); /************************* /Images Array ******************************/ if (method_exists('Product', 'getProductsImgs')) { $image_array = array(); for ($i = 0; $i < $nbProducts; $i++) { if (isset($result[$i]['id_product'])) { $image_array[$result[$i]['id_product']] = Product::getProductsImgs($result[$i]['id_product']); } } $this->context->smarty->assign('productimg', (isset($image_array) and $image_array) ? $image_array : NULL); } /************************* /Images Array ******************************/ $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(); $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'); } }
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); }
<?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(); $searchResults = Search::find(intval(Tools::getValue('id_lang')), $query, 1, 10, 'position', 'desc', true); foreach ($searchResults as &$product) { $product['product_link'] = $link->getProductLink($product['id_product'], $product['prewrite'], $product['crewrite']); } die(json_encode($searchResults)); } include dirname(__FILE__) . '/header.php'; include dirname(__FILE__) . '/product-sort.php'; if ($query = Tools::getValue('search_query', 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'], 'search_query' => $query, 'homeSize' => Image::getSize('home'))); } elseif ($tag = Tools::getValue('tag') and !is_array($tag)) { $nbProducts = intval(Search::searchTag(intval($cookie->id_lang), $tag, true)); include dirname(__FILE__) . '/pagination.php'; $smarty->assign(array('search_tag' => $tag, 'products' => Search::searchTag(intval($cookie->id_lang), $tag, false, $p, $n, $orderBy, $orderWay), 'nbProducts' => $nbProducts, 'homeSize' => Image::getSize('home'))); } else { $smarty->assign(array('products' => array(), 'pages_nb' => 1, 'nbProducts' => 0)); } $smarty->display(_PS_THEME_DIR_ . 'search.tpl'); include dirname(__FILE__) . '/footer.php';