public function hookLeftColumn() { if (get_class($this->context->controller) == 'ConvermaxSearchModuleFrontController') { $this->context->smarty->assign(array('pagesize' => abs((int) Tools::getValue('n', Configuration::get('PS_PRODUCTS_PER_PAGE'))))); return $this->display(__FILE__, 'views/templates/hook/facets.tpl'); } $home_category = Configuration::get('PS_HOME_CATEGORY'); $id_category = (int) Tools::getValue('id_category', Tools::getValue('id_category_layered', $home_category)); if ($id_category != $home_category) { $category = new Category($id_category); $categories = $category->getParentsCategories(); $category_full = array(); foreach ($categories as $cat) { if ($cat['id_category'] != $home_category) { $category_full[] = $cat['name']; } } if (!empty($category_full)) { $category_full = implode('>', array_reverse($category_full)); } $facet = array('category_full' => array($category_full)); $n = abs((int) Tools::getValue('n', isset($this->context->cookie->nb_item_per_page) ? (int) $this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'))); $search = Cmsearch::find($this->context->language->id, ' ', 1, $n, 'position', 'desc', false, true, null, $facet); if ($search) { $facets_params = ''; $is_ranged = 'IsRanged'; $field_name = 'FieldName'; $values = 'Values'; $display_name = 'DisplayName'; foreach ($search['cm_result']->Facets as $facet) { if ($facet->{$is_ranged}) { $rangemin = preg_replace('|TO .*\\]|', '', $facet->{$values}[0]->Term); $rangemax = preg_replace('|\\[.*? |', '', $facet->{$values}[count($facet->{$values}) - 1]->Term); $facets_params .= 'cm_params.sliders.' . $facet->{$field_name} . ' = []' . ";\r\n"; $facets_params .= 'cm_params.sliders.' . $facet->{$field_name} . '[0] = "' . $rangemin . $rangemax . "\";\r\n"; } else { $values_count = count($facet->{$values}); for ($i = 0; $i < $values_count; $i++) { if ($facet->{$values}[$i]->Selected == true) { $facets_params .= 'cm_params.facets.' . $facet->{$field_name} . ' = []' . ";\r\n"; $facets_params .= 'cm_params.facets.' . $facet->{$field_name} . '[' . $i . '] = "' . $facet->{$values}[$i]->Term . "\";\r\n"; $facets_params .= 'cm_params.facets_display.' . $facet->{$field_name} . ' = "' . $facet->{$display_name} . "\";\r\n"; } } } } $this->context->smarty->assign(array('facets' => $search['cm_result']->Facets, 'query' => ' ', 'pagenumber' => 1, 'pagesize' => $n, 'facets_params' => isset($facets_params) ? $facets_params : false)); return $this->display(__FILE__, 'views/templates/hook/facets.tpl'); } } return ''; }
public function displayAjax() { $query = Tools::getValue('search_query'); $original_query = $query; $query = Tools::replaceAccentedChars(urldecode($query)); $this->productSort(); $this->n = abs((int) Tools::getValue('n', isset($this->context->cookie->nb_item_per_page) ? (int) $this->context->cookie->nb_item_per_page : Configuration::get('PS_PRODUCTS_PER_PAGE'))); $this->p = abs((int) Tools::getValue('p', 1)); $facets = Tools::getValue('cm_select'); $search = Cmsearch::find($this->context->language->id, $query, $this->p, $this->n, $this->orderBy, $this->orderWay, false, true, null, $facets); if ($search) { $position = 1; foreach ($search['result'] as &$product) { $product['link'] .= (strpos($product['link'], '?') === false ? '?' : '&') . 'search_query=' . urlencode($query) . '&results=' . (int) $search['total'] . '&pid=' . (int) $product['id_product'] . '&position=' . $position . '&page=' . $this->p . '&num=' . $this->n; $position++; } Hook::exec('actionSearch', array('expr' => $query, 'total' => $search['total'])); $nbProducts = $search['total']; $this->pagination($nbProducts); if (version_compare(_PS_VERSION_, '1.6.0', '>=') === true) { $this->addColorsToProductList($search['result']); } if (stripos($search['cm_result']->State, 'nothing')) { $cm_message = 'nothing found'; } elseif (!empty($search['cm_result']->Corrections) && $search['cm_result']->Corrections[0]->Apply) { if (!empty($search['cm_result']->Query)) { $cm_message = 'your request has been corrected to ' . $search['cm_result']->Query; } else { $cm_message = 'nothing found'; } } else { $cm_message = false; } $this->context->smarty->assign(array('search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => !empty($search['cm_result']->OriginalQuery) ? $search['cm_result']->OriginalQuery : ' ', 'cm_message' => $cm_message, 'homeSize' => Image::getSize(ImageType::getFormatedName('home')), 'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'), 'comparator_max_item' => Configuration::get('PS_COMPARATOR_MAX_ITEM'))); $list = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/front/search.tpl'); $this->context->smarty->assign(array('facets' => $search['cm_result']->Facets, 'query' => $search['cm_result']->Query, 'pagenumber' => $this->p, 'pagesize' => $this->n, 'col_img_dir' => _PS_COL_IMG_DIR_)); $facets = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/hook/facet.tpl'); $vars = array('productList' => utf8_encode($list), 'facets' => $facets, 'redirect_url' => isset($search['cm_result']->Actions[0]->RedirectUrl) ? $search['cm_result']->Actions[0]->RedirectUrl : false); } else { $this->context->smarty->assign(array('search_products' => $search['result'], 'nbProducts' => $search['total'], 'search_query' => !empty($original_query) ? $original_query : ' ', 'homeSize' => Image::getSize(ImageType::getFormatedName('home')))); $list = $this->context->smarty->fetch(_PS_MODULE_DIR_ . 'convermax/views/templates/front/search.tpl'); $vars = array('productList' => utf8_encode($list), 'facets' => array(), 'redirect_url' => false); } echo Tools::jsonEncode($vars); }