public function displayContent() { if (!$this->id_seo && !$this->hookName || !$this->id_search) { die; } if (Tools::getValue('ajaxMode')) { $this->ajax = true; } $objPM_AdvancedSearch4 = new PM_AdvancedSearch4(); if (!Tools::getValue('ajaxMode')) { $_GET['only_products'] = 1; echo $objPM_AdvancedSearch4->displayAjaxSearchBlocks($this->id_search, $this->hookName, 'pm_advancedsearch.tpl', (int) Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden, true); unset($_GET['only_products']); } else { try { AdvancedSearchCoreClass::_hookExec('header'); } catch (SmartyException $e) { } $ajaxMode = true; if (Tools::getValue('only_products')) { $objPM_AdvancedSearch4->displayAjaxSearchBlocks($this->id_search, $this->hookName, 'pm_advancedsearch.tpl', (int) Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden, true); } else { if ($this->next_id_criterion_group && !$this->reset) { if (is_array($this->criterions) && sizeof($this->criterions)) { $objPM_AdvancedSearch4->displayAjaxSearchBlocks($this->id_search, $this->hookName, 'pm_advancedsearch.tpl', (int) Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden); } else { $objPM_AdvancedSearch4->displayNextStepSearch($this->id_search, $this->hookName, $this->next_id_criterion_group, (int) Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden); } } else { $objPM_AdvancedSearch4->displayAjaxSearchBlocks($this->id_search, $this->hookName, 'pm_advancedsearch.tpl', (int) Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden); } } } if ($this->ajax) { die; } }
public static function getCriterionsForSearchBloc($search, $id_criterion_group, $id_lang, $count_product = false, $selected_criterion = array(), $selected_criteria_groups_type = array(), $id_currency = false, $id_country = false, $id_group = false, $visible = false, $groupInfos = false, $base_selection = false, $criterion_groups) { if ($groupInfos['sort_by'] == '' || $groupInfos['sort_by'] == 'position' || !$id_lang) { $field_order_by = '`position`'; } elseif ($groupInfos['criterion_group_type'] == 'weight' || $groupInfos['criterion_group_type'] == 'width' || $groupInfos['criterion_group_type'] == 'height' || $groupInfos['criterion_group_type'] == 'depth') { $field_order_by = '`value`'; } elseif ($groupInfos['sort_by'] == 'numeric') { $field_order_by = 'CAST(REPLACE(IF(ac.`single_value` != "",ac.`single_value`,acl.`value`), ",", ".") AS DECIMAL(10,2))'; } elseif ($groupInfos['sort_by'] == 'nb_product') { $field_order_by = 'nb_product'; } else { $field_order_by = '`value`'; } $selected_criterion = PM_AdvancedSearch4::array_map_recursive('intval', $selected_criterion); $selected_criterion_copy = $selected_criterion; if (isset($selected_criterion[$id_criterion_group])) { unset($selected_criterion[$id_criterion_group]); } if (!$id_country) { $id_country = (int) (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Context::getContext()->country->id : Country::getDefaultCountryId()); } $now = date('Y-m-d H:i:s'); $cacheKey = sha1(serialize(func_get_args()) . $id_country); if (isset(self::$_getCriterionsForSearchBlocCache[$cacheKey])) { return self::$_getCriterionsForSearchBlocCache[$cacheKey]; } $leftJoinWhereCriterion = self::makeLeftJoinWhereCriterion('getCriterionsForSearchBloc', $search, $id_lang, $selected_criterion, $selected_criteria_groups_type, $id_criterion_group, $groupInfos['criterion_group_type'] == 'attribute', $id_currency, $id_country, $id_group, false, false, $groupInfos['criterion_group_type'], $criterion_groups); if ($groupInfos['criterion_group_type'] == 'category' && !$groupInfos['id_criterion_group_linked'] && !$groupInfos['show_all_depth']) { if (isset($selected_criterion_copy[$id_criterion_group]) && sizeof($selected_criterion_copy[$id_criterion_group])) { $current_level_depth = self::getAsCriterionCategoryHigherLevelDepth($search['id_search'], $selected_criterion_copy[$id_criterion_group]); $current_linked_categories = self::getIdLinkedFromCriterion($selected_criterion_copy[$id_criterion_group], $search['id_search'], $current_level_depth); $leftJoinWhereCriterion['where'][] = $leftJoinWhereCriterion['whereUnion'][] = '(ac.`id_criterion` IN (' . implode(',', $selected_criterion_copy[$id_criterion_group]) . ') OR (ac.`level_depth` = ' . ((int) $current_level_depth + 1) . ' AND ac.`id_parent` IN (' . implode(',', $current_linked_categories) . ')))'; } else { $leftJoinWhereCriterion['where'][] = $leftJoinWhereCriterion['whereUnion'][] = 'ac.`level_depth` = 1'; } } if ($search['filter_by_emplacement'] && Tools::getValue('id_seo') == false && (Tools::getValue('id_manufacturer', Tools::getValue('id_manufacturer_search')) || Tools::getValue('id_supplier', Tools::getValue('id_supplier')))) { $id_manufacturer = Tools::getIsset('id_manufacturer') ? (int) Tools::getValue('id_manufacturer') : (int) Tools::getValue('id_manufacturer_search'); $id_supplier = Tools::getIsset('id_supplier') ? (int) Tools::getValue('id_supplier') : (int) Tools::getValue('id_supplier_search'); $preSelectedCriterion = array(); if ($id_manufacturer) { $preSelectedCriterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('manufacturer', $id_manufacturer, (int) $search['id_search']); } else { if ($id_supplier) { $preSelectedCriterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('supplier', $id_supplier, (int) $search['id_search']); } } if (is_array($preSelectedCriterion) && isset($preSelectedCriterion[$id_criterion_group]) && AdvancedSearchCoreClass::_isFilledArray($preSelectedCriterion[$id_criterion_group])) { $leftJoinWhereCriterion['where'][] = $leftJoinWhereCriterion['whereUnion'][] = '(ac.`id_criterion` IN (' . implode(',', $preSelectedCriterion[$id_criterion_group]) . '))'; } } if ($search['filter_by_emplacement'] && Tools::getValue('id_seo') !== false && is_numeric(Tools::getValue('id_seo')) && Tools::getValue('id_seo') > 0) { $search['selected_criteres_seo'] = array(); $seo_search = new AdvancedSearchSeoClass((int) Tools::getValue('id_seo')); if (Validate::isLoadedObject($seo_search) && isset($seo_search->criteria) && !empty($seo_search->criteria)) { $criteres_seo = @unserialize($seo_search->criteria); if (AdvancedSearchCoreClass::_isFilledArray($criteres_seo)) { foreach ($criteres_seo as $critere_seo) { $critere_seo = explode('_', $critere_seo); $id_criterion_group_seo = (int) $critere_seo[0]; $id_criterion_value = (int) $critere_seo[1]; if (isset($selected_criterion[$id_criterion_group_seo])) { if (!in_array($id_criterion_value, $selected_criterion[$id_criterion_group_seo])) { $search['selected_criteres_seo'][$id_criterion_group_seo][] = $id_criterion_value; } } else { $search['selected_criteres_seo'][$id_criterion_group_seo][] = $id_criterion_value; } } } } } if (isset($search['selected_criteres_seo']) && AdvancedSearchCoreClass::_isFilledArray($search['selected_criteres_seo']) && $search['filter_by_emplacement'] && Tools::getValue('id_seo') !== false && is_numeric(Tools::getValue('id_seo')) && Tools::getValue('id_seo') > 0) { $leftJoinWhereCriterion['where'][] = $leftJoinWhereCriterion['whereUnion'][] = '(ac.`id_criterion` IN (' . implode(',', $search['selected_criteres_seo'][$id_criterion_group]) . '))'; } if (self::isCategoryGroup($search['id_search'], $id_criterion_group, true)) { $current_category_depth = $groupInfos['id_criterion_group_linked']; if (is_array($selected_criterion_copy) && sizeof($selected_criterion_copy)) { foreach ($selected_criterion_copy as $id_criterion_group2 => $criteria2) { if ($selected_criteria_groups_type[$id_criterion_group2]['criterion_group_type'] == 'category' && $id_criterion_group2 != $id_criterion_group && $selected_criteria_groups_type[$id_criterion_group2]['id_criterion_group_linked'] < $current_category_depth) { if (!isset($prev_category_depth) || $prev_category_depth < $selected_criteria_groups_type[$id_criterion_group2]['id_criterion_group_linked']) { $prev_category_depth = $selected_criteria_groups_type[$id_criterion_group2]['id_criterion_group_linked']; $criteria_category_parent = $criteria2; } } } if (isset($criteria_category_parent)) { $childsCategoriesId = self::getChildsCategoriesId(self::getIdLinkedFromCriterion($criteria_category_parent, $search['id_search'])); $leftJoinWhereCriterion['where'][] = '(aclink.`id_criterion_linked` IN(' . implode(', ', $childsCategoriesId) . '))'; } } } if ($groupInfos['criterion_group_type'] == 'category') { $groups = FrontController::getCurrentCustomerGroups(); $leftJoinWhereCriterion['join'][] = $leftJoinWhereCriterion['joinUnion'][] = 'LEFT JOIN `' . _DB_PREFIX_ . 'category_group` cg ON ( cg.`id_category` = aclink.`id_criterion_linked`)'; $leftJoinWhereCriterion['where'][] = $leftJoinWhereCriterion['whereUnion'][] = 'cg.`id_group` ' . (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1'); } $query = ''; if ($leftJoinWhereCriterion['make_union']) { if ($groupInfos['sort_by'] == 'numeric') { $field_order_by = 'CAST(REPLACE(IF(`single_value` != "",`single_value`,`value`), ",", ".") AS DECIMAL(10,2))'; } $query .= 'SELECT * FROM ('; } $query .= 'SELECT ac.*, aclink.`id_criterion_linked` ' . ((int) $id_lang ? ', acl.id_lang, acl.icon' : '') . ', IF(ac.`single_value` != "",ac.`single_value`,acl.`value`) AS `value`, (' . (AdvancedSearchCoreClass::_isFilledArray($leftJoinWhereCriterion['count']) ? 'COUNT(DISTINCT ' . implode(' + ', $leftJoinWhereCriterion['count']) . ')' : 'COUNT(DISTINCT acpc.`id_cache_product`)') . ') AS nb_product' . ' FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '` ac JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_link` aclink ON (ac.`id_criterion` = aclink.`id_criterion`) JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_list` aclist ON (ac.`id_criterion` = aclist.`id_criterion_parent`) ' . ($id_lang ? 'LEFT JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = ' . (int) $id_lang . ')' : '') . ($search['display_empty_criteria'] ? 'LEFT ' : '') . 'JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $search['id_search'] . '` acpc ON (aclist.`id_criterion` = acpc.`id_criterion`) LEFT JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_' . (int) $search['id_search'] . '` acp ON ( ' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' acp.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' acp.`id_cache_product` = acpc.`id_cache_product`) ' . (AdvancedSearchCoreClass::_isFilledArray($leftJoinWhereCriterion['join']) ? implode(' ', $leftJoinWhereCriterion['join']) : '') . 'WHERE ' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' acp.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' ac.`id_criterion_group` = ' . (int) $id_criterion_group . ($visible ? ' AND ac.`visible` = 1' : '') . ' AND ' . (AdvancedSearchCoreClass::_isFilledArray($leftJoinWhereCriterion['where']) ? implode(' AND ', $leftJoinWhereCriterion['where']) : '1') . ' GROUP BY ac.`id_criterion`' . ($leftJoinWhereCriterion['make_union'] ? '' : ' ORDER BY ' . $field_order_by . ' ' . $groupInfos['sort_way']); if ($leftJoinWhereCriterion['make_union']) { $query .= ' UNION SELECT ac.*, aclink.`id_criterion_linked`, acl.id_lang, acl.icon, IF(ac.`single_value` != "",ac.`single_value`,acl.`value`) AS `value`, 0 AS nb_product FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '` ac JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_link` aclink ON (ac.`id_criterion` = aclink.`id_criterion`) JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_list` aclist ON (ac.`id_criterion` = aclist.`id_criterion`) LEFT JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int) $search['id_search'] . '_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = ' . (int) $id_lang . ') ' . (AdvancedSearchCoreClass::_isFilledArray($leftJoinWhereCriterion['joinUnion']) ? implode(' ', $leftJoinWhereCriterion['joinUnion']) : '') . ($base_selection ? ' JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $search['id_search'] . '` acpc ON (aclist.`id_criterion` = acpc.`id_criterion`) JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_' . (int) $search['id_search'] . '` acp ON ( ' . (AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' acp.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' acp.`id_cache_product` = acpc.`id_cache_product`) JOIN `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int) $search['id_search'] . '` acpc2 ON ( acp.`id_cache_product` = acpc2.`id_cache_product` AND acpc2.`id_criterion` IN(' . implode(', ', $base_selection) . ')) ' : '') . ' WHERE ' . ($base_selection && AdvancedSearchCoreClass::_isFilledArray(PM_AdvancedSearch4::$productFilterList) ? ' acp.`id_product` IN (' . implode(',', PM_AdvancedSearch4::$productFilterList) . ') AND ' : '') . ' ac.`id_criterion_group` = ' . (int) $id_criterion_group . ($visible ? ' AND ac.`visible` = 1' : '') . ' AND ' . (AdvancedSearchCoreClass::_isFilledArray($leftJoinWhereCriterion['whereUnion']) ? implode(' AND ', $leftJoinWhereCriterion['whereUnion']) : '1') . ' GROUP BY ac.`id_criterion` ) as tmp GROUP BY `id_criterion` ORDER BY ' . $field_order_by . ' ' . $groupInfos['sort_way']; } self::$_getCriterionsForSearchBlocCache[$cacheKey] = Db::getInstance()->ExecuteS($query); return self::$_getCriterionsForSearchBlocCache[$cacheKey]; }
public function hookHeader() { if ($this->_isInMaintenance() || $this->_isMobileTheme()) { return; } if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { if (isset($_SERVER['PHP_SELF']) && preg_match('#' . preg_quote('best-sales.php') . '#', $_SERVER['PHP_SELF'])) { self::$productFilterListSource = 'best-sales'; } else { if (isset($_SERVER['PHP_SELF']) && preg_match('#' . preg_quote('new-products.php') . '#', $_SERVER['PHP_SELF'])) { self::$productFilterListSource = 'new-products'; } else { if (isset($_SERVER['PHP_SELF']) && preg_match('#' . preg_quote('prices-drop.php') . '#', $_SERVER['PHP_SELF'])) { self::$productFilterListSource = 'prices-drop'; } else { if (isset($_SERVER['PHP_SELF']) && preg_match('#' . preg_quote('search.php') . '#', $_SERVER['PHP_SELF']) && Tools::getIsset('q') && Tools::getValue('q')) { self::$productFilterListData = urldecode(Tools::getValue('q')); self::$productFilterListSource = 'search'; } } } } } else { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && isset($this->_context->controller) && is_object($this->_context->controller) && isset($this->_context->controller->php_self)) { if (in_array($this->_context->controller->php_self, array('best-sales', 'new-products', 'prices-drop', 'search'))) { self::$productFilterListSource = $this->_context->controller->php_self; if ($this->_context->controller->php_self == 'search' && Tools::getIsset('search_query') && Tools::getValue('search_query')) { self::$productFilterListData = Tools::replaceAccentedChars(urldecode(Tools::getValue('search_query'))); } } } } $this->setProductFilterContext(); $this->_addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/css/' . $this->name . '.css', 'all'); $this->_addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/' . self::DYN_CSS_FILE, 'all'); $this->_addCSS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jqueryui/ui_theme_front/theme1/jquery-ui-1.8.13.custom.css', 'all'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jquery.min.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jqueryui/1.8.9/jquery-ui-1.8.9.custom.min.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jqueryui/jquery.ui.touch-punch.min.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/loadjqPm.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jquery.actual.min.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jquery.history/jquery.history.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jquery.history/jquery.observehashchange.pack.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/pm_advancedsearch.js'); $this->_addJS(__PS_BASE_URI__ . 'modules/' . $this->name . '/js/jquery.form.js'); if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0) { $this->_addJS(_THEME_JS_DIR_ . 'products-comparison.js'); } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $ASSearchUrl = $this->_context->link->getModuleLink('pm_advancedsearch4', 'advancedsearch4'); } else { $ASSearchUrl = __PS_BASE_URI__ . 'modules/pm_advancedsearch4/advancedsearch4.php'; } $this->_smarty->assign('ASSearchUrlForm', $ASSearchUrl); if (!Tools::getValue('ajaxMode')) { $this->assignSearchVar(); } return $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/' : '') . 'pm_advancedsearch_header.tpl'); }
<?php include dirname(__FILE__) . '/../../config/config.inc.php'; include dirname(__FILE__) . '/../../init.php'; include dirname(__FILE__) . '/pm_advancedsearch4.php'; if (php_sapi_name() != 'cli') { if (isset($_GET['secure_key'])) { $secureKey = version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Configuration::getGlobalValue('PM_AS4_SECURE_KEY') : Configuration::get('PM_AS4_SECURE_KEY'); if (!empty($secureKey) and $secureKey === $_GET['secure_key']) { $PM_AdvancedSearch4 = new PM_AdvancedSearch4(); $PM_AdvancedSearch4->cronTask(); echo 'Reindexation done'; } } } else { $PM_AdvancedSearch4 = new PM_AdvancedSearch4(); $PM_AdvancedSearch4->cronTask(); echo 'Reindexation done via PHP Cli'; }