Exemple #1
0
 public function displayAjaxSearchBlocks($id_search, $hookName, $tplName, $with_product, $selected_criterion = array(), $selected_criterion_hidden = array(), $only_product = false)
 {
     ob_start();
     $json_return = array();
     $searchs = AdvancedSearchClass::getSearch($id_search, $this->_cookie->id_lang);
     $this->_addToFBLog("Retrieve searchs");
     $searchs = $this->getCriterionsGroupsAndCriterionsForSearch($searchs, $this->_cookie->id_lang, $selected_criterion, $selected_criterion_hidden, $with_product, false, true);
     $this->_addToFBLog("Retrieve criterons and results 2");
     $ajaxMode = Tools::getValue('ajaxMode', false);
     if ($ajaxMode) {
         $json_return['next_id_criterion_group'] = $this->getNextIdCriterionGroup($id_search);
     }
     $location_name = $this->getLocationName($this->_cookie->id_lang);
     if (preg_match('/displayHome/i', $hookName)) {
         $hookName = 'home';
     }
     if (Tools::getValue('id_seo')) {
         $needHiddenForm = false;
         if ($only_product && version_compare(_PS_VERSION_, '1.5.0.0', '>=') && (preg_match('/leftcolumn/i', $hookName) && !$this->context->controller->display_column_left || preg_match('/rightcolumn/i', $hookName) && !$this->context->controller->display_column_right)) {
             $needHiddenForm = true;
             $hookName = '';
         } else {
             if (isset($searchs[0]) && isset($searchs[0]['id_hook']) && $searchs[0]['id_hook'] == -1) {
                 $needHiddenForm = false;
                 $hookName = '';
             }
         }
         if (empty($hookName) && isset($searchs[0]) && isset($searchs[0]['id_hook']) && $searchs[0]['id_hook'] != -1 || $hookName == 'home') {
             $needHiddenForm = true;
         }
         $this->_smarty->assign(array('hideAS4Form' => $needHiddenForm, 'ajaxMode' => $ajaxMode, 'as_searchs' => $searchs, 'hookName' => $hookName, 'as_obj' => $this, 'as_path' => $this->_path, 'as_selected_criterion' => $selected_criterion, 'as_criteria_group_type_interal_name' => $this->criteria_group_type_interal_name, 'col_img_dir' => _PS_COL_IMG_DIR_, 'as_location_name' => $location_name));
         unset($_GET['ajaxMode']);
         if (!$only_product || $only_product && $needHiddenForm) {
             $json_return['html_block'] = $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/' : '') . $tplName);
         }
     } else {
         $this->_smarty->assign(array('hideAS4Form' => empty($hookName) && isset($searchs[0]) && isset($searchs[0]['id_hook']) && $searchs[0]['id_hook'] != -1 || $hookName == 'home' ? false : false, 'ajaxMode' => $ajaxMode, 'as_searchs' => $searchs, 'hookName' => $hookName, 'as_obj' => $this, 'as_path' => $this->_path, 'as_selected_criterion' => $selected_criterion, 'as_criteria_group_type_interal_name' => $this->criteria_group_type_interal_name, 'col_img_dir' => _PS_COL_IMG_DIR_, 'as_location_name' => $location_name));
         unset($_GET['ajaxMode']);
         if (!$only_product || $only_product && (empty($hookName) && isset($searchs[0]) && isset($searchs[0]['id_hook']) && $searchs[0]['id_hook'] != -1 || $hookName == 'home')) {
             $json_return['html_block'] = $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/' : '') . $tplName);
         }
     }
     if ($with_product) {
         $this->_assignForProductsResults();
         $this->_assignProductSort($searchs[0]['products_order_by'], $searchs[0]['products_order_way']);
         $this->_assignPagination($searchs[0]['products_per_page'], $searchs[0]['total_products']);
         if ($ajaxMode && !Tools::getIsset('back_from_redirect') && isset($searchs[0]['redirect_one_product']) && $searchs[0]['redirect_one_product'] && isset($searchs[0]['search_method']) && $searchs[0]['search_method'] == 2 && self::_isFilledArray($searchs[0]['products']) && sizeof($searchs[0]['products']) == 1) {
             self::_cleanBuffer();
             echo json_encode(array('html_products' => '', 'html_blocks' => '', 'redirect_to_product' => $searchs[0]['products'][0]['link']));
             die;
         }
         if ($this->MagicZoomInstance) {
             $initial_script_name = $GLOBALS['_SERVER']['SCRIPT_NAME'];
             $GLOBALS['_SERVER']['SCRIPT_NAME'] = '/category.php';
             $json_return['html_products'] = $this->MagicZoomInstance->hookHeader(array('cookie', $this->_cookie));
             $GLOBALS['_SERVER']['SCRIPT_NAME'] = $initial_script_name;
             $this->_smarty->assign('products', $searchs[0]['products']);
             ob_end_clean();
             if (!Configuration::get('PS_FORCE_SMARTY_2')) {
                 $this->_smarty->template_resource = 'category.tpl';
             } else {
                 $this->_smarty->currentTemplate = 'category';
             }
             $json_return['html_products'] .= $this->MagicZoomInstance->parseTemplateStandard($this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/' : '') . 'pm_advancedsearch_results.tpl'), $this->_smarty);
         } else {
             $json_return['html_products'] = $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/' : '') . 'pm_advancedsearch_results.tpl');
         }
         $json_return['html_products'] = $this->_fixPaginationLinks($json_return['html_products']);
     }
     self::_cleanBuffer();
     if ($ajaxMode) {
         $return = json_encode($json_return);
         if (function_exists('json_last_error') && json_last_error() == 5 && function_exists('mb_convert_encoding')) {
             foreach ($json_return as $k => $v) {
                 $json_return[$k] = mb_convert_encoding($json_return[$k], 'UTF-8', 'UTF-8');
             }
             $return = json_encode($json_return);
         }
         echo $return;
         unset($return);
     } else {
         $return = '';
         foreach ($json_return as $value) {
             $return .= $value;
         }
         return $return;
     }
     return false;
 }