* @copyright Presta-Module 2014 * @version 4.10.5 * * ____ __ __ * | _ \ | \/ | * | |_) | | |\/| | * | __/ | | | | * |_| |_| |_| * * ************************************* ** AdvancedSearch_4 * ** http://www.presta-module.com * ** V 4.10.5 * ************************************* * + * + Multi-layered search engine and search by steps * + Languages: EN, FR * + PS version: 1.4, 1.5, 1.6 * ****/ include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/classes/ShopOverrided.php'); include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/classes/AdvancedSearchClass.php'); include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/classes/AdvancedSearchCriterionGroupClass.php'); include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/classes/AdvancedSearchCriterionClass.php'); include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/classes/AdvancedSearchSeoClass.php'); include_once (_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/AdvancedSearchCoreClass.php'); class PM_AdvancedSearch4 extends AdvancedSearchCoreClass { protected $errors = array(); private $gradient_separator = '-'; private $options_show_hide_crit_method; private $options_remind_selection; private $options_launch_search_method; private $orderByValues = array (0 => 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity', 7 => 'reference'); private $orderWayValues = array (0 => 'asc', 1 => 'desc' ); private $options_defaut_order_by; private $options_defaut_order_way; private $options_criteria_group_type; private $allowFileExtension = array ('gif', 'jpg', 'jpeg', 'png' ); private $sortableCriterion = array ('attribute', 'feature', 'manufacturer', 'supplier', 'category', 'weight', 'width', 'weight', 'height', 'depth', 'condition'); private $criteriaGroupLabels; private $criterionGroupIsTemplatisable = array ('attribute', 'feature', 'manufacturer', 'supplier', 'category' ); private $keepVarForCache = array ('id_category', 'id_product', 'id_manufacturer', 'id_supplier', 'id_cms', 'id_search' ); private $display_horizontal_search_block = array (8, 14, '-1'); private $productLinksNCIsInstalled; public $_require_maintenance = true; public static $_module_prefix = 'as4'; /*Debug*/ private $bench = false; protected $_debug_mode = false; private $bench_output = array(); private $bench_start; private $bench_step; private $MagicZoomInstance = false; private $_htFile; protected $_copyright_link = array( 'link' => '', 'img' => '//www.presta-module.com/img/logo-module.JPG' ); protected $_support_link = false; protected $_css_js_to_load = array ('jquery', 'jquerytiptip', 'jqueryui', 'admincore', 'adminmodule', 'codemirrorcore', 'codemirrorcss', 'colorpicker', 'datatables', 'jgrowl', 'multiselect', 'scrolltofixed', 'uploadify', 'tiny_mce', 'form', 'selectmenu'); //Array of all dyn tables to make change on protected $_dyn_tables = array ('pm_advancedsearch_product_price_ID_SEARCH', 'pm_advancedsearch_cache_product_ID_SEARCH', 'pm_advancedsearch_cache_product_criterion_ID_SEARCH', 'pm_advancedsearch_criterion_ID_SEARCH', 'pm_advancedsearch_criterion_ID_SEARCH_lang', 'pm_advancedsearch_criterion_group_ID_SEARCH', 'pm_advancedsearch_criterion_group_ID_SEARCH_lang'); //Array of all static tables to make change on protected $_static_tables = array ( 'pm_advancedsearch', 'pm_advancedsearch_category', 'pm_advancedsearch_cms', 'pm_advancedsearch_lang', 'pm_advancedsearch_seo', 'pm_advancedsearch_seo_crosslinks', 'pm_advancedsearch_seo_lang'); //Files and directory to check protected $_file_to_check = array('css','css/pm_advancedsearch4_dynamic.css','search_files', 'search_files/criterions', 'search_files/criterions_group', 'seositemap.xml', 'uploads/temp' ); public static $productFilterList = array(); public static $productFilterListData = false; public static $productFilterListSource = false; const INSTALL_SQL_BASE_FILE = 'install_base.sql'; const INSTALL_SQL_DYN_FILE = 'install_dyn.sql'; const DYN_CSS_FILE = 'css/pm_advancedsearch4_dynamic.css'; const ADVANCED_CSS_FILE = 'css/pm_advancedsearch4_advanced.css'; public function __construct() { if (!$this->_debug_mode) $this->bench = false; $this->_addToFBLog("Start"); $this->name = 'pm_advancedsearch4'; if (version_compare(_PS_VERSION_, '1.4.0.0', '<')) $this->tab = 'Presta Module'; else { $this->author = 'Presta-Module'; $this->tab = 'search_filter'; $this->need_instance = 0; $this->module_key = 'e0578dd1826016f7acb8045ad15372b4'; } $this->version = '4.10.5'; $this->controllers = array('advancedsearch4'); parent::__construct(); $this->criteriaGroupLabels = array('category'=>$this->l('category'),'feature'=>$this->l('feature'),'attribute'=>$this->l('attribute'),'supplier'=>$this->l('supplier'),'manufacturer'=>$this->l('manufacturer'),'price'=>$this->l('price'),'weight'=>$this->l('product properties'),'on_sale'=>$this->l('product properties'),'stock'=>$this->l('product properties'),'available_for_order'=>$this->l('product properties'),'online_only'=>$this->l('product properties'),'condition'=>$this->l('product properties'),'width'=>$this->l('product properties'),'height'=>$this->l('product properties'),'depth'=>$this->l('product properties')); $this->criteria_group_type_interal_name = array (1 => 'select', 3 => 'link', 4 => 'checkbox', 5 => 'slider', 6 => 'searchbox', 2 => 'image', 7 => 'colorsquare' ); //Check if magiczoom module is installed if (file_exists(dirname(__FILE__) . '/../magiczoomplus/magiczoomplus.php') && self::moduleIsInstalled('magiczoomplus')) { include_once (_PS_ROOT_DIR_ . '/modules/magiczoomplus/magiczoomplus.php'); if (method_exists('magiczoomplus','hookHeader') && method_exists('magiczoomplus','parseTemplateStandard')) $this->MagicZoomInstance = new MagicZoomPlus(); else $this->MagicZoomInstance = false; } elseif (file_exists(dirname(__FILE__) . '/../magiczoom/magiczoom.php') && self::moduleIsInstalled('magiczoom')) { include_once (_PS_ROOT_DIR_ . '/modules/magiczoom/magiczoom.php'); if (method_exists('magiczoom','hookHeader') && method_exists('magiczoom','parseTemplateStandard')) $this->MagicZoomInstance = new MagicZoom(); else $this->MagicZoomInstance = false; } //Check if productlinksnc module is installed if (file_exists(dirname(__FILE__) . '/../productlinksnc/productlinksnc.php') && self::moduleIsInstalled('productlinksnc')) $this->productLinksNCIsInstalled = true; if ($this->_onBackOffice()) { $this->displayName = $this->l('Advanced Search 4'); $this->description = $this->l('Multi-layered search engine and search by steps'); $this->options_remind_selection = array (0 => $this->l('Don\'t show selection'), 1 => $this->l('Show selection over product\'s results'), 2 => $this->l('Show selection on search block'), 3 => $this->l('Show selection over product\'s results and on search block') ); $this->options_show_hide_crit_method = array (1 => $this->l('On mouse over'), 2 => $this->l('On click'), 3 => $this->l('In an overflow block') ); $this->options_launch_search_method = array (1 => $this->l('Instant search'), 2 => $this->l('Search on submit') ); $this->options_defaut_order_by = array (0 => $this->l('Product name'), 1 => $this->l('Product price'), 2 => $this->l('Product added date') .' ('.$this->l('Recommended for heavy catalog').')', 4 => $this->l('Position inside category'), 5 => $this->l('Manufacturer'), 3 => $this->l('Product modified date').' ('.$this->l('Recommended for heavy catalog').')' ); $this->options_defaut_order_way = array (0 => $this->l('Ascending'), 1 => $this->l('Descending') ); $this->options_criteria_group_type = array (1 => $this->l('Selectbox'), 3 => $this->l('Link'), 4 => $this->l('Checkbox'), 5 => $this->l('Slider')/*, 8 => $this->l('Range')*/, //6 => $this->l('Search box'), 2 => $this->l('Image') ); //Set htfile path $this->_htFile = dirname(__FILE__) . '/../../.htaccess'; $doc_url_tab['fr'] = 'http://www.presta-module.com/docs/fr/advancedsearch4/'; $doc_url_tab['en'] = 'http://www.presta-module.com/docs/en/advancedsearch4/'; $doc_url = $doc_url_tab['en']; if ($this->_iso_lang == 'fr') $doc_url = $doc_url_tab['fr']; $forum_url_tab['fr'] = 'http://www.prestashop.com/forums/topic/113804-module-pm-advanced-search-4-elu-meilleur-module-2012/'; $forum_url_tab['en'] = 'http://www.prestashop.com/forums/topic/113831-module-pm-advancedsearch-4-winner-at-the-best-module-awards-2012/'; $forum_url = $forum_url_tab['en']; if ($this->_iso_lang == 'fr') $forum_url = $forum_url_tab['fr']; $this->_support_link = array( array('link' => $forum_url, 'target' => '_blank', 'label' => $this->l('Forum topic')), array('link' => 'http://addons.prestashop.com/contact-community.php?id_product=2778', 'target' => '_blank', 'label' => $this->l('Support contact')), ); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $this->display_horizontal_search_block = array('-1'); foreach (array('displayHome', 'displayTop') as $hookName) if (Hook::getIdByName($hookName) !== false) $this->display_horizontal_search_block[] = Hook::getIdByName($hookName); } } } private function _getBestSellersProductsIds() { $sqlGroups = ''; if ((version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive()) && version_compare(_PS_VERSION_, '1.6.0.0', '<')) { $currentGroups = FrontController::getCurrentCustomerGroups(); $sqlGroups = 'AND cg.`id_group` '.(is_array($currentGroups) && sizeof($currentGroups) ? 'IN ('.implode(',', $currentGroups).')' : '= 1'); } Db::getInstance()->Execute('SET group_concat_max_len := @@max_allowed_packet'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT GROUP_CONCAT(p.id_product) as pid_list FROM `'._DB_PREFIX_.'product_sale` ps JOIN `'._DB_PREFIX_.'product` p ON (ps.`id_product` = p.`id_product`) '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlAssociation('product', 'p') : '').' WHERE '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`active` = 1 AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sqlGroups.' )'); if ($result && isset($result['pid_list']) && !empty($result['pid_list'])) return explode(',', $result['pid_list']); return array(); } private function _getNewProductsIds() { $sqlGroups = ''; if ((version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive()) && version_compare(_PS_VERSION_, '1.6.0.0', '<')) { $currentGroups = FrontController::getCurrentCustomerGroups(); $sqlGroups = 'AND cg.`id_group` '.(is_array($currentGroups) && sizeof($currentGroups) ? 'IN ('.implode(',', $currentGroups).')' : '= 1'); } Db::getInstance()->Execute('SET group_concat_max_len := @@max_allowed_packet'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT GROUP_CONCAT(p.id_product) as pid_list FROM `'._DB_PREFIX_.'product` p '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlAssociation('product', 'p') : '').' WHERE '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`active` = 1 AND DATEDIFF('.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`date_add`, DATE_SUB(NOW(), INTERVAL '.(Validate::isUnsignedInt(Configuration::get('PS_NB_DAYS_NEW_PRODUCT')) ? Configuration::get('PS_NB_DAYS_NEW_PRODUCT') : 20).' DAY)) > 0 '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND product_shop.`visibility` IN ("both", "catalog") ' : '').' AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sqlGroups.' )'); if ($result && isset($result['pid_list']) && !empty($result['pid_list'])) return explode(',', $result['pid_list']); return array(); } private function _getPricesDropProductsIds() { $sqlGroups = ''; if ((version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive()) && version_compare(_PS_VERSION_, '1.6.0.0', '<')) { $currentGroups = FrontController::getCurrentCustomerGroups(); $sqlGroups = 'AND cg.`id_group` '.(is_array($currentGroups) && sizeof($currentGroups) ? 'IN ('.implode(',', $currentGroups).')' : '= 1'); } $currentDate = date('Y-m-d H:i:s'); if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { global $cookie, $cart; $id_group = $cookie->id_customer ? (int)(Customer::getDefaultGroupId((int)($cookie->id_customer))) : _PS_DEFAULT_CUSTOMER_GROUP_; $id_address = $cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $ids = Address::getCountryAndState($id_address); $id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT')); $ids_product = SpecificPrice::getProductIdByDate((int)(Shop::getCurrentShop()), (int)($cookie->id_currency), $id_country, $id_group, $currentDate, $currentDate); } else { $id_address = $this->_context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')}; $ids = Address::getCountryAndState($id_address); $id_country = (int)($ids['id_country'] ? $ids['id_country'] : Configuration::get('PS_COUNTRY_DEFAULT')); $ids_product = SpecificPrice::getProductIdByDate($this->_context->shop->id, $this->_context->currency->id, $id_country, $this->_context->customer->id_default_group, $currentDate, $currentDate, 0, false); } $tab_id_product = array(); foreach ($ids_product as $product) { if (is_array($product)) $tab_id_product[] = (int)$product['id_product']; else $tab_id_product[] = (int)$product; } Db::getInstance()->Execute('SET group_concat_max_len := @@max_allowed_packet'); $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow(' SELECT GROUP_CONCAT(p.id_product) as pid_list FROM `'._DB_PREFIX_.'product` p '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlAssociation('product', 'p') : '').' WHERE '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`active` = 1 AND '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`show_price` = 1 '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND product_shop.`visibility` IN ("both", "catalog") ' : '').' AND '.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? 'product_shop' : 'p').'.`id_product` IN ('.((is_array($tab_id_product) && count($tab_id_product)) ? implode(', ', $tab_id_product) : 0).') AND p.`id_product` IN ( SELECT cp.`id_product` FROM `'._DB_PREFIX_.'category_group` cg LEFT JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_category` = cg.`id_category`) WHERE cg.`id_group` '.$sqlGroups.' )'); if ($result && isset($result['pid_list']) && !empty($result['pid_list'])) return explode(',', $result['pid_list']); return array(); } // Une recherche est en cours... public function hookSearch($params) { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) return; if (isset($params['expr']) && !empty($params['expr']) && strlen(trim($params['expr'])) > 0) { self::$productFilterListData = $params['expr']; self::$productFilterListSource = 'search'; $this->setProductFilterContext(); } } private function _getProductsByNativeSearch($expr) { $db = Db::getInstance(_PS_USE_SQL_SLAVE_); $intersectArray = array(); $scoreArray = array(); $words = explode(' ', Search::sanitize($expr, (int)$this->_cookie->id_lang)); foreach ($words AS $key => $word) if (!empty($word) AND strlen($word) >= (int)Configuration::get('PS_SEARCH_MINWORDLEN')) { $word = str_replace('%', '\\%', $word); $word = str_replace('_', '\\_', $word); if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) $word = Tools::replaceAccentedChars($word); $intersectArray[] = 'SELECT id_product FROM '._DB_PREFIX_.'search_word sw LEFT JOIN '._DB_PREFIX_.'search_index si ON sw.id_word = si.id_word WHERE sw.id_lang = '.(int)$this->_cookie->id_lang. (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND sw.id_shop = '.Context::getContext()->shop->id.' ' : ''). ' AND sw.word LIKE '.($word[0] == '-' ? ' \''.pSQL(Tools::substr($word, 1, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' : '\''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\'' ); if ($word[0] != '-') $scoreArray[] = 'sw.word LIKE \''.pSQL(Tools::substr($word, 0, PS_SEARCH_MAX_WORD_LENGTH)).'%\''; } else unset($words[$key]); if (!sizeof($words)) return array(); $sqlGroups = ''; if ((version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive()) && version_compare(_PS_VERSION_, '1.6.0.0', '<')) { $currentGroups = FrontController::getCurrentCustomerGroups(); $sqlGroups = 'AND cg.`id_group` '.(is_array($currentGroups) && sizeof($currentGroups) ? 'IN ('.implode(',', $currentGroups).')' : '= 1'); } $result = $db->ExecuteS(' SELECT DISTINCT cp.`id_product` FROM `'._DB_PREFIX_.'category_product` cp '.((version_compare(_PS_VERSION_, '1.6.0.0', '>=') && Group::isFeatureActive()) && version_compare(_PS_VERSION_, '1.6.0.0', '<') ? 'INNER JOIN `'._DB_PREFIX_.'category_group` cg ON cp.`id_category` = cg.`id_category`' : '').' INNER JOIN `'._DB_PREFIX_.'category` c ON cp.`id_category` = c.`id_category` INNER JOIN `'._DB_PREFIX_.'product` p ON cp.`id_product` = p.`id_product` ' .(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Shop::addSqlAssociation('product', 'p', false) : '').' WHERE c.`active` = 1 ' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? ' AND product_shop.`active` = 1 AND product_shop.`visibility` IN ("both", "search") AND product_shop.indexed = 1 ' : ' AND p.`active` = 1 AND indexed = 1 ' ) . $sqlGroups, false); $eligibleProducts = array(); while ($row = $db->nextRow($result)) $eligibleProducts[] = (int)$row['id_product']; foreach ($intersectArray as $query) { $result = $db->ExecuteS($query, false); $eligibleProducts2 = array(); while ($row = $db->nextRow($result)) $eligibleProducts2[] = (int)$row['id_product']; $eligibleProducts = array_intersect($eligibleProducts, $eligibleProducts2); if (!count($eligibleProducts)) return array(); } array_unique($eligibleProducts); return $eligibleProducts; } public function install() { if (!$this->installDB() || ! parent::install()) return false; if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $valid_hooks = AdvancedSearchClass::$_valid_hooks_1_5; else $valid_hooks = AdvancedSearchClass::$_valid_hooks; foreach ($valid_hooks as $k => $hook_name) { if (!$this->registerHook($hook_name)) return false; } if (!$this->registerHook('backOfficeHeader') || !$this->registerHook('header') || !$this->registerHook('updateProduct') || !$this->registerHook('addProduct')/* || !$this->registerHook('updateProductAttribute')*/ || !$this->registerHook('deleteProduct')) return false; // Specific price update if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !$this->registerHook('actionObjectSpecificPriceDeleteAfter')) return false; /*Update*/ $this->checkIfModuleIsUpdate(true, false); return true; } public function installDB() { if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_BASE_FILE)) return (false); else if (!$sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_BASE_FILE)) return (false); $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql); if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')) $sql = str_replace('MYSQL_ENGINE', _MYSQL_ENGINE_, $sql); else $sql = str_replace('MYSQL_ENGINE', 'MyISAM', $sql); $sql = preg_split("/;\s*[\r\n]+/", $sql); foreach ($sql as $query ) if (!Db::getInstance()->Execute(trim($query))) return (false); return true; } public function installDBCache($id_search, $with_drop = true) { if (!file_exists(dirname(__FILE__) . '/' . self::INSTALL_SQL_DYN_FILE)) return (false); else if (!$sql = file_get_contents(dirname(__FILE__) . '/' . self::INSTALL_SQL_DYN_FILE)) return (false); $sql = str_replace('ID_SEARCH', $id_search, $sql); $sql = str_replace('PREFIX_', _DB_PREFIX_, $sql); if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')) $sql = str_replace('MYSQL_ENGINE', _MYSQL_ENGINE_, $sql); else $sql = str_replace('MYSQL_ENGINE', 'MyISAM', $sql); $sql = preg_split("/;\s*[\r\n]+/", $sql); foreach ($sql as $query) { if (!$with_drop && preg_match('#^DROP#i',trim($query))) continue; if (!Db::getInstance()->Execute(trim($query))) return (false); } return true; } public function checkIfModuleIsUpdate($updateDb = false, $displayConfirm = true) { parent::checkIfModuleIsUpdate($updateDb, $displayConfirm); $isUpdate = true; // Get & remove old version configuration values if (Configuration::get('AS4_LAST_VERSION', false) !== false && Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false) === false) { Configuration::updateValue('PM_' . self::$_module_prefix . '_LAST_VERSION', Configuration::get('AS4_LAST_VERSION', false)); Configuration::deleteByName('AS4_LAST_VERSION'); } if (!$updateDb && $this->version != Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false)) return false; if ($updateDb) { $oldModuleVersion = Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false); if (Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false) !== false && version_compare(Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false), '4.8', '>=') && version_compare(Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false), '4.9.1', '<=')) { $updateShopTable = true; } else { $updateShopTable = false; } unset($_GET ['makeUpdate']); //Register on hook backOfficeHeader for a beter reindexation if (!$this->isRegisteredInHook('backOfficeHeader')) $this->registerHook('backOfficeHeader'); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !$this->isRegisteredInHook('actionObjectSpecificPriceDeleteAfter')) $this->registerHook('actionObjectSpecificPriceDeleteAfter'); Configuration::updateValue('PM_' . self::$_module_prefix . '_LAST_VERSION', $this->version); //Update secure key for cron task if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { if (!Configuration::getGlobalValue('PM_AS4_SECURE_KEY')) Configuration::updateGlobalValue('PM_AS4_SECURE_KEY', strtoupper(Tools::passwdGen(16))); } else { if (!Configuration::get('PM_AS4_SECURE_KEY')) Configuration::updateValue('PM_AS4_SECURE_KEY', strtoupper(Tools::passwdGen(16))); } $this->installDB(); $this->updateSearchTable($updateShopTable, $oldModuleVersion); $this->generateCss(); $this->_pmClearCache(); if ($displayConfirm) { $this->_html .= $this->displayConfirmation($this->l('Module updated successfully')); } } return $isUpdate; } //Update search table whene module update public function updateSearchTable($updateShopTable = false, $oldModuleVersion = false) { $advanced_searchs_id = AdvancedSearchClass::getSearchsId(false); $toAdd = array(); $toChange = array(); $indexToAdd = array(); $primaryToAdd = array(); //Remove unsigned attribut to allow negative number $toChange [] = array ('pm_advancedsearch', 'id_hook', 'int(11) NOT NULL'); if (is_array($advanced_searchs_id) && sizeof($advanced_searchs_id)) { foreach ($advanced_searchs_id as $key => $row) { $this->installDBCache($row ['id_search'],false); //Change DB engine for existing tables foreach($this->_dyn_tables as $table) { $table = str_replace('ID_SEARCH', $row ['id_search'], $table); if (!Db::getInstance()->Execute('ALTER TABLE `'. _DB_PREFIX_ .pSQL($table).'` ENGINE=`MyISAM`')) $this->_errors[] = $this->l('Can\'t change engine for').' '. _DB_PREFIX_ .$table; } $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` WHERE `column_name` = "id_criterion_group"'); //Removing unnecessary indexe FROM v4.0 if ($result && Db::getInstance()->numRows()) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` DROP INDEX `id_product` , ADD INDEX `id_product` ( `id_currency` , `id_country` , `id_group` , `price` , `price_wt` , `from` , `to` ) '); $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` WHERE `Key_name` = "PRIMARY" AND `Column_name` = "reduction_amount"'); $result2 = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` WHERE `Key_name` = "PRIMARY"'); //Alter Primary key of price table if (!$result && $result2) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` DROP PRIMARY KEY'); $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int)($row ['id_search']) . '` WHERE `key_name` = "id_criterion2"'); //SQL optimization from 4.2 if (!$result || !Db::getInstance()->numRows()) { Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int)($row ['id_search']) . '` ADD INDEX `id_criterion2` ( `id_criterion`)'); Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_cache_product_criterion_' . (int)($row ['id_search']) . '` ADD INDEX `id_cache_product` ( `id_cache_product`)'); } $result = Db::getInstance()->ExecuteS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` WHERE `Field` = "price"'); //Remove unnecessary price field and get compatibility with windows server if ($result && Db::getInstance()->numRows()) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_product_price_' . (int)($row ['id_search']) . '` DROP `price`'); //Add fields on dynamic tables $toAdd [] = array ('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'visible', 'tinyint(4) NOT NULL DEFAULT "1"', 'level_depth' ); $toAdd [] = array ('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'id_parent', 'int(10) unsigned DEFAULT NULL', 'level_depth' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']), 'show_all_depth', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'is_multicriteria' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']), 'only_children', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'is_multicriteria' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_'. (int)($row ['id_search']),'is_collapsed','tinyint(3) unsigned NOT NULL DEFAULT "0"'); $toAdd [] = array ('pm_advancedsearch_criterion_group_'. (int)($row ['id_search']),'hidden','tinyint(3) unsigned NOT NULL DEFAULT "0"'); $toAdd [] = array ('pm_advancedsearch_criterion_group_'. (int)($row ['id_search']),'range_nb','decimal(10,2) unsigned NOT NULL DEFAULT "15"'); $toAdd [] = array ('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'single_value', 'varchar(255) default NULL', 'color' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']), 'range', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'is_multicriteria' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']), 'sort_by', 'varchar(10) default "position"', 'is_multicriteria' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']), 'sort_way', 'varchar(4) default "ASC"', 'is_multicriteria' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']).'_lang', 'range_sign', 'varchar(32) default NULL', 'icon' ); $toAdd [] = array ('pm_advancedsearch_criterion_group_' . (int)($row ['id_search']).'_lang', 'range_interval', 'varchar(255) default NULL', 'icon' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'reduction_amount', 'decimal(20,6) NOT NULL default "0"', 'price_wt' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'is_specific', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'to' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'id_shop', 'int(10) unsigned DEFAULT "0"', 'id_criterion_group' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'id_specific_price', 'int(10) unsigned DEFAULT "0"', 'is_specific' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'valid_id_specific_price', 'int(10) unsigned DEFAULT "0"', 'id_specific_price' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'reduction_type', 'enum(\'amount\',\'percentage\')', 'reduction_amount' ); $toAdd [] = array ('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'has_no_specific', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'is_specific' ); $toAdd [] = array ('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'is_custom', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'visible' ); //Update fields on dynamic tables $toChange [] = array ('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'position', 'int(10) unsigned DEFAULT "0"' ); $indexToAdd[] = array('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'single_value', '`single_value`'); $indexToAdd[] = array('pm_advancedsearch_criterion_' . (int)($row ['id_search']) . '_lang', 'value','`value`'); $indexToAdd[] = array('pm_advancedsearch_criterion_' . (int)($row ['id_search']), 'is_custom', '`is_custom`'); $indexToAdd[] = array('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'is_specific','`is_specific`'); $indexToAdd[] = array('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'valid_id_specific_price','`valid_id_specific_price`'); $indexToAdd[] = array('pm_advancedsearch_product_price_' . (int)($row ['id_search']), 'has_no_specific','`has_no_specific`'); // Add index to feature_value_lang $indexToAdd[] = array('feature_value_lang', 'id_feature_value','`id_feature_value`'); $indexToAdd[] = array('feature_value_lang', 'id_lang','`id_lang`'); // Add index on pm_advancedsearch_cache_product_criterion $indexToAdd[] = array('pm_advancedsearch_cache_product_criterion_' . (int)($row ['id_search']), 'id_criterion','`id_criterion`, `id_cache_product`'); $primaryToAdd[] = array( 'pm_advancedsearch_criterion_group_' . (int)($row ['id_search']).'_lang', '`id_criterion_group`, `id_lang`', 'id_criterion_group', ); $primaryToAdd[] = array( 'pm_advancedsearch_criterion_' . (int)($row ['id_search']).'_lang', '`id_criterion`, `id_lang`', 'id_criterion', ); $primaryToAdd[] = array( 'pm_advancedsearch_cache_product_criterion_' . (int)($row ['id_search']), '`id_criterion`, `id_cache_product`', 'id_criterion', ); $primaryToAdd[] = array( 'pm_advancedsearch_product_price_' . (int)($row ['id_search']), '`id_cache_product` , `id_currency` , `id_country` , `id_group` , `price_wt` , `reduction_amount` , `from` , `to`', 'id_product', ); } } //Change DB engine for existing tables foreach($this->_static_tables as $table) { if (!Db::getInstance()->Execute('ALTER TABLE `'. _DB_PREFIX_ .pSQL($table).'` ENGINE=`MyISAM`')) $this->_errors[] = $this->l('Can\'t change engine for').' '. _DB_PREFIX_ .$table; } //Add fields on static tables $toAdd [] = array ('pm_advancedsearch', 'keep_category_information', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'step_search' ); $toAdd [] = array ('pm_advancedsearch', 'display_empty_criteria', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'step_search' ); $toAdd [] = array ('pm_advancedsearch', 'recursing_indexing', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'step_search' ); $toAdd [] = array ('pm_advancedsearch', 'share', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'step_search' ); $toAdd [] = array ('pm_advancedsearch', 'search_results_selector', 'varchar(64) NOT NULL DEFAULT "#center_column"', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'smarty_var_name', 'varchar(64) NOT NULL', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'insert_in_center_column', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'collapsable_criterias', 'tinyint(3) unsigned NOT NULL DEFAULT "1"', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'reset_group', 'tinyint(3) unsigned NOT NULL DEFAULT "1"', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'unique_search', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'share' ); $toAdd [] = array ('pm_advancedsearch', 'scrolltop_active', 'tinyint(3) unsigned NOT NULL DEFAULT "1"', 'unique_search' ); $toAdd [] = array ('pm_advancedsearch', 'id_category_root', 'int(10) unsigned NOT NULL DEFAULT "0"', 'scrolltop_active' ); $toAdd [] = array ('pm_advancedsearch', 'redirect_one_product', 'tinyint(3) unsigned NOT NULL DEFAULT "1"', 'id_category_root' ); $toAdd [] = array ('pm_advancedsearch', 'add_anchor_to_url', 'tinyint(3) unsigned NOT NULL DEFAULT "0"', 'redirect_one_product' ); //Update fields on static tables $toChange [] = array ('pm_advancedsearch_seo', 'criteria', 'TEXT NOT NULL' ); $toChange [] = array ('pm_advancedsearch', 'background_color', 'VARCHAR( 15 ) NULL' ); $toChange [] = array ('pm_advancedsearch', 'border_color', 'VARCHAR( 7 ) NULL' ); $toChange [] = array ('pm_advancedsearch', 'border_size', 'VARCHAR( 24 ) NULL' ); $toChange [] = array ('pm_advancedsearch', 'color_group_title', 'VARCHAR( 7 ) NULL' ); $toChange [] = array ('pm_advancedsearch', 'font_size_group_title', 'SMALLINT( 4 ) UNSIGNED NULL DEFAULT "0"' ); $toChange [] = array ('pm_advancedsearch', 'border_radius', 'SMALLINT( 4 ) UNSIGNED NULL DEFAULT "0"' ); $toChange [] = array ('pm_advancedsearch', 'color_title', 'VARCHAR( 7 ) NULL' ); $toChange [] = array ('pm_advancedsearch', 'font_size_title', 'SMALLINT( 4 ) UNSIGNED NULL DEFAULT "0"' ); $primaryToAdd[] = array( /*table*/ 'pm_advancedsearch_seo_lang', /*primary field*/ '`id_seo`, `id_lang`', /*old key to delete*/ 'id_seo', ); $primaryToAdd[] = array( 'pm_advancedsearch_lang', '`id_search`, `id_lang`', 'id_search', ); $primaryToAdd[] = array( 'pm_advancedsearch_category', '`id_search`, `id_category`', 'id_search', ); $primaryToAdd[] = array( 'pm_advancedsearch_seo_crosslinks', '`id_seo`, `id_seo_linked`', 'id_seo', ); if (sizeof($toAdd)) { foreach ($toAdd as $table => $infos) { if (!$this->columnExists($infos [0], $infos [1], true, $infos [2], (isset($infos[3]) ? $infos[3] : false))) { $isUpdate = false; } } } if (sizeof($toChange)) { foreach ($toChange as $table => $infos) { $resultset = Db::getInstance()->ExecuteS("SHOW COLUMNS FROM `" . _DB_PREFIX_ . $infos [0] . "` WHERE `Field` = '" . $infos [1] . "'"); foreach ($resultset as $row) { if ($row ['Type'] != $infos [2]) { Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $infos [0] . '` CHANGE `' . $infos [1] . '` `' . $infos [1] . '` ' . $infos [2] . ''); } } } } if (sizeof($indexToAdd)) { foreach ($indexToAdd as $infos) { //Add index for optimized search by step and range $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . $infos[0] . '` WHERE `Key_name` = "'.$infos[1].'"'); if (!$result || !Db::getInstance()->numRows()) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $infos[0] . '` ADD INDEX ( '.$infos[2].' )'); } } if (sizeof($primaryToAdd)) { foreach ($primaryToAdd as $infos) { //Add index for optimized search by step and range $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . $infos[0] . '` WHERE `Key_name` = "PRIMARY"'); if (!$result || !Db::getInstance()->numRows()) { if (isset($infos[2])) { //Check if old key exists $result = Db::getInstance()->ExecuteS('SHOW INDEX FROM `' . _DB_PREFIX_ . $infos[0] . '` WHERE `column_name` = "'.$infos[2].'"'); if ($result && Db::getInstance()->numRows()) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $infos[0] . '` DROP INDEX `'.$infos[2].'`'); } Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $infos[0] . '` ADD PRIMARY KEY ('.$infos[1].')'); } } } //Update seo data $seo = AdvancedSearchSeoClass::getSeoSearchs(false, true); $seo_url_updated = false; foreach ($seo as $row) { //Seo as allready new data if (preg_match('#\{i:#', $row['criteria'])) break; $newCriteria = array(); $criteria = explode(',', $row['criteria']); if (sizeof($criteria)) { foreach ($criteria AS $k => $value) { //Set price range if (preg_match('/-/', $value)) $id_criterion_group = AdvancedSearchCriterionGroupClass::getIdCriterionGroupByTypeAndIdLinked($row['id_search'],'price',0); else $id_criterion_group = AdvancedSearchCriterionClass::getIdCriterionGroupByIdCriterion($row['id_search'], $value); if (!$id_criterion_group) continue; //Set criteria as new format $newCriteria[] = $id_criterion_group.'_'.$value; $save_seo = true; } } if (sizeof($newCriteria)) { $row['criteria'] = serialize($newCriteria); Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'pm_advancedsearch_seo', $row, 'UPDATE', 'id_seo = ' . (int) $row['id_seo']); //Update SEO URL one time if ($seo_url_updated) { Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'pm_advancedsearch_seo_lang` SET `seo_url` = REPLACE(`seo_url`,"/","-")'); $seo_url_updated = true; } } } // Updates shops if ($updateShopTable) { $result = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_shop` ORDER BY `id_search` , `id_shop`'); if ($result && self::_isFilledArray($result)) { $first_shop = array(); foreach ($result as $row) { if (!isset($first_shop[$row['id_search']])) $first_shop[$row['id_search']] = $row['id_shop']; else continue; } // Only keep the first one shop relation foreach ($first_shop as $id_search => $id_shop) { Db::getInstance()->Execute('DELETE FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_shop` WHERE `id_search`='.(int)$id_search.' AND `id_shop`!='.(int)$id_shop); } } } if ($oldModuleVersion !== false && version_compare($oldModuleVersion, '4.10.0', '<=')) { // Update SEO pages md5 key $result = Db::getInstance()->ExecuteS('SELECT * FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_seo`'); if ($result && self::_isFilledArray($result)) { foreach ($result as $row) { $criteria = unserialize($row['criteria']); $newSeoKey = $this->getSeoKeyFromCriteria($row['id_search'], $criteria, $row['id_currency']); if ($newSeoKey != $row['seo_key']) Db::getInstance()->Execute('UPDATE `' . _DB_PREFIX_ . 'pm_advancedsearch_seo` SET `seo_key`="' . pSQL($newSeoKey) . '" WHERE id_seo="' . (int)$row['id_seo'] . '"'); } } } if ($oldModuleVersion !== false && version_compare($oldModuleVersion, '4.10.1', '<=')) { // Add new tables // pm_advancedsearch_criterion__link if (is_array($advanced_searchs_id) && sizeof($advanced_searchs_id)) { foreach ($advanced_searchs_id as $key => $row) { // Remove id_criterion_linked column from pm_advancedsearch_criterion_ tables $result = Db::getInstance()->ExecuteS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '` WHERE `Field` = "id_criterion_linked"'); if ($result && Db::getInstance()->numRows()) { // If query OK, we delete the column if (Db::getInstance()->Execute('INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$row['id_search'].'_link` (`id_criterion`, `id_criterion_linked`) (SELECT `id_criterion`, `id_criterion_linked` FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$row['id_search'].'`)')) Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '` DROP `id_criterion_linked`'); } // Add criterions list to the new table $criterionsCount = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '`'); $criterionsListCount = (int)Db::getInstance()->getValue('SELECT COUNT(*) FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '_list`'); if ($criterionsCount > 0 && $criterionsListCount == 0) Db::getInstance()->Execute('INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$row['id_search'].'_list` (`id_criterion_parent`, `id_criterion`) (SELECT `id_criterion` AS `id_criterion_parent`, `id_criterion` FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$row['id_search'].'`)'); // Remove criterions_list column $result = Db::getInstance()->ExecuteS('SHOW COLUMNS FROM `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '` WHERE `Field` = "criterions_list"'); if ($result && Db::getInstance()->numRows()) { $result = Db::getInstance()->ExecuteS('SELECT `id_criterion`, `criterions_list` FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$row['id_search'].'`'); if ($result && self::_isFilledArray($result)) { foreach ($result as $criterionRow) { if ($criterionRow['criterions_list'] != '' && !empty($criterionRow['criterions_list'])) { $criterionRow['criterions_list'] = array_unique(explode(',', $criterionRow['criterions_list'])); if (self::_isFilledArray($criterionRow['criterions_list'])) foreach ($criterionRow['criterions_list'] as $k=>$idCriterionToAdd) if (empty($idCriterionToAdd) || !is_numeric($idCriterionToAdd)) unset($criterionRow['criterions_list'][$k]); } if (self::_isFilledArray($criterionRow['criterions_list'])) { $idCriterionToAddList = array(); foreach ($criterionRow['criterions_list'] as $idCriterionToAdd) { $idCriterionToAddList[] = (int)$idCriterionToAdd; AdvancedSearchCriterionClass::addCriterionToList((int)$row['id_search'], $criterionRow['id_criterion'], $idCriterionToAdd); } AdvancedSearchCriterionClass::populateCriterionsLink((int)$row['id_search'], $criterionRow['id_criterion'], false, $idCriterionToAddList); } else { AdvancedSearchCriterionClass::addCriterionToList((int)$row['id_search'], $criterionRow['id_criterion'], $criterionRow['id_criterion']); } } } Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$row['id_search'] . '` DROP `criterions_list`'); } } } } return; } private function columnExists($table, $column, $createIfNotExist = false, $type = false, $insertAfter = false) { $resultset = Db::getInstance()->ExecuteS("SHOW COLUMNS FROM `" . _DB_PREFIX_ . $table . "`"); foreach ($resultset as $row ) if ($row ['Field'] == $column) return true; if ($createIfNotExist && Db::getInstance()->Execute('ALTER TABLE `' . _DB_PREFIX_ . $table . '` ADD `' . $column . '` ' . $type . ' ' . ($insertAfter ? ' AFTER `' . $insertAfter . '`' : '') . '')) return true; return false; } public function updateAdvancedStyles($css_styles) { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) $advanced_css_file_db = Configuration::updateGlobalValue('PM_'.self::$_module_prefix.'_ADVANCED_STYLES', base64_encode($css_styles)); else $advanced_css_file_db = Configuration::updateValue('PM_'.self::$_module_prefix.'_ADVANCED_STYLES', base64_encode($css_styles)); $this->generateCss(); } public function getAdvancedStylesDb() { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) $advanced_css_file_db = Configuration::getGlobalValue('PM_'.self::$_module_prefix.'_ADVANCED_STYLES'); else $advanced_css_file_db = Configuration::get('PM_'.self::$_module_prefix.'_ADVANCED_STYLES'); if ($advanced_css_file_db !== false) return base64_decode($advanced_css_file_db); return false; } public function displayAdvancedConfig() { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) $advanced_css_file = str_replace('.css','-'.$this->_context->shop->id.'.css',dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE); else $advanced_css_file = dirname(__FILE__) . '/' . self::ADVANCED_CSS_FILE; // Try to get the actual advanced styles content (upgrading...) if ($this->getAdvancedStylesDb() == false) { if (file_exists($advanced_css_file) && is_readable($advanced_css_file) && strlen(file_get_contents($advanced_css_file)) > 0) // Convert old file to BDD $this->updateAdvancedStyles(file_get_contents($advanced_css_file)); else // Init BDD $this->updateAdvancedStyles("/* Advanced Search 4 - Advanced Styles Content */\n"); } $this->_html .= '
'; $this->_pmClear(); $this->_html .= '
'; $this->_pmClear(); } public function displayMaintenance() { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $advanced_searchs_id = AdvancedSearchClass::getSearchsId(false, $this->_context->shop->id); else $advanced_searchs_id = AdvancedSearchClass::getSearchsId(false); if (self::_isFilledArray($advanced_searchs_id)) { $this->_html .= ''; } $this->_html .= '

' . $this->l('Reindex all the search engines') . '

'; $this->_html .= '' . $this->l('Reindexing all advanced search') . '
'; $this->_html .= ''; $this->_html .= '

' . $this->l('Clear all modules tables') . '

'; $this->_html .= '
' . $this->l('Warning ! This will delete all your advanced searches & configuration.') . '
'; $this->_html .= '' . $this->l('Clear all advanced searches') . ''; } public static function moduleIsInstalled($moduleName) { Db::getInstance()->ExecuteS('SELECT `id_module` FROM `' . _DB_PREFIX_ . 'module` WHERE `name` = \'' . pSQL($moduleName) . '\' AND `active` = 1'); return (bool)Db::getInstance()->NumRows(); } public function generateCssGradientBackground($selector, $background_color) { $css = ''; $background_color = explode($this->gradient_separator, $background_color); if (isset($background_color [1])) { $color1 = htmlentities($background_color [0], ENT_COMPAT, 'UTF-8'); $color2 = htmlentities($background_color [1], ENT_COMPAT, 'UTF-8'); $css = $selector . ' {background: ' . $color1 . ';background: -webkit-gradient(linear, 0 0, 0 bottom, from(' . $color1 . '), to(' . $color2 . '));background: -moz-linear-gradient(' . $color1 . ', ' . $color2 . ');background: linear-gradient(' . $color1 . ', ' . $color2 . ');-pie-background: linear-gradient(' . $color1 . ', ' . $color2 . ');}'; } else { $css = $selector . ' {background-color:' . htmlentities($background_color [0], ENT_COMPAT, 'UTF-8') . '!important;filter: none!important; }'; } return $css; } public function generateCssBorderRadius($selector, $size) { $css = $selector . ' {-moz-border-radius:' . (int)$size . 'px;-webkit-border-radius:' . (int)$size . 'px;border-radius:' . (int)$size . 'px;behavior: url(' . $this->_path . 'js/PIE.htc);}'; return $css; } public function generateCss() { $advanced_searchs = AdvancedSearchClass::getSearchs($this->_cookie->id_lang, false, false); $css = array(); foreach ($advanced_searchs as $advanced_search) { if (in_array($advanced_search ['id_hook'], $this->display_horizontal_search_block)) { if ($advanced_search ['width']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' {width:' . (int)$advanced_search ['width'] . 'px;}'; if ($advanced_search ['height']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' {height:' . (int)$advanced_search ['height'] . 'px;}'; if ($advanced_search ['background_color']) $css [] = $this->generateCssGradientBackground('#PM_ASBlockOutput_' . $advanced_search ['id_search'], $advanced_search ['background_color']); if ($advanced_search ['border_color']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' {border-color:' . htmlentities($advanced_search ['border_color'], ENT_COMPAT, 'UTF-8') . ';}'; if ($advanced_search ['border_size']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' {border-width:' . htmlentities($advanced_search ['border_size'], ENT_COMPAT, 'UTF-8') . '!important;}'; if ($advanced_search ['border_radius']) $css [] = $this->generateCssBorderRadius('#PM_ASBlockOutput_' . $advanced_search ['id_search'], $advanced_search ['border_radius']); if ($advanced_search ['color_title']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' .PM_ASearchTitle {color:' . htmlentities($advanced_search ['color_title'], ENT_COMPAT, 'UTF-8') . ';}'; if ($advanced_search ['font_size_title']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' .PM_ASearchTitle {font-size:' . (int)$advanced_search ['font_size_title'] . 'px!important;}'; } if ($advanced_search ['color_group_title']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' .PM_ASCriterionsGroupTitle {color:' . htmlentities($advanced_search ['color_group_title'], ENT_COMPAT, 'UTF-8') . ';}'; if ($advanced_search ['font_size_group_title']) $css [] = '#PM_ASBlockOutput_' . $advanced_search ['id_search'] . ' .PM_ASCriterionsGroupTitle {font-size:' . (int)$advanced_search ['font_size_group_title'] . 'px!important;}'; $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexed($advanced_search ['id_search'], $this->_cookie->id_lang); foreach ($criterions_groups_indexed as $criterions_group) { if ($advanced_search ['show_hide_crit_method'] == 3 && $criterions_group ['overflow_height']) $css [] = '#PM_ASCriterions_' . $advanced_search ['id_search'] . '_' . $criterions_group ['id_criterion_group'] . ' .PM_ASCriterionsGroupOuter {overflow:auto;height:' . (int)$criterions_group ['overflow_height'] . 'px;}'; if (in_array($advanced_search ['id_hook'], $this->display_horizontal_search_block) && $criterions_group ['width']) $css [] = '#PM_ASCriterionsGroup_' . $advanced_search ['id_search'] . '_' . $criterions_group ['id_criterion_group'] . ' {width:' . (int)$criterions_group ['width'] . 'px!important;}'; } } // Advanced Styles $advanced_styles = "\n".$this->getAdvancedStylesDb(); if (is_writable(dirname(__FILE__) . '/css/') && is_writable(dirname(__FILE__) . '/' . self::DYN_CSS_FILE)) { if (sizeof($css)) file_put_contents(dirname(__FILE__) . '/' . self::DYN_CSS_FILE, implode(" ", $css).$advanced_styles); else file_put_contents(dirname(__FILE__) . '/' . self::DYN_CSS_FILE, ''.$advanced_styles); } else { if (!is_writable(dirname(__FILE__) . '/css/')) { $this->errors[] = $this->_showWarning($this->l('Please set write permision to folder:'). ' '.dirname(__FILE__) . '/css/'); } if (!is_writable(dirname(__FILE__) . '/' . self::DYN_CSS_FILE)) { $this->errors[] = $this->l('Please set write permision to file:'). ' '.dirname(__FILE__) . '/' . self::DYN_CSS_FILE; } } } public function getCriterionsGroupsValue($id_lang) { $criterions_groups = array(); //Get attributes groups $attributes_groups = AdvancedSearchClass::getAttributesGroups($id_lang); foreach ($attributes_groups as $row ) $criterions_groups [] = array ('id' => $row ['id_attribute_group'], 'name' => $row ['public_name'], 'type' => 'attribute' ); //Get features $features = AdvancedSearchClass::getFeatures($id_lang); foreach ($features as $row) $criterions_groups [] = array ('id' => $row ['id_feature'], 'name' => $row ['name'], 'type' => 'feature' ); //Manufacturer $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Manufacturer'), 'type' => 'manufacturer' ); //Supplier $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Supplier'), 'type' => 'supplier' ); //Categories $criterions_groups [] = array ('id' => 0, 'name' => $this->l('All category levels'), 'type' => 'category' ); //Categories by level depth $categories_level_depth = AdvancedSearchClass::getCategoriesLevelDepth(); foreach ($categories_level_depth as $category_level_depth) { $criterions_groups [] = array ('id' => $category_level_depth ['level_depth'], 'name' => $this->l('Categories level') . ' ' . $category_level_depth ['level_depth'], 'type' => 'category' ); } //Price $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Price'), 'type' => 'price' ); //On sale $criterions_groups [] = array ('id' => 0, 'name' => $this->l('On sale'), 'type' => 'on_sale' ); //In stock $criterions_groups [] = array ('id' => 0, 'name' => $this->l('In stock'), 'type' => 'stock' ); //Available for order $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Available for order'), 'type' => 'available_for_order' ); //Only online $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Only online'), 'type' => 'online_only' ); //Condition $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Condition'), 'type' => 'condition' ); //Width $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Width'), 'type' => 'width' ); //Height $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Height'), 'type' => 'height' ); //Depth $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Depth'), 'type' => 'depth' ); //Weight $criterions_groups [] = array ('id' => 0, 'name' => $this->l('Weight'), 'type' => 'weight' ); return $criterions_groups; } public function displayErrorsJs($with_script = true) { if (sizeof($this->errors)) { $this->_html .= ''; } } private function _postProcessSearch() { $id_search = Tools::getValue('id_search', false); $ObjAdvancedSearchClass = new AdvancedSearchClass($id_search); $reindexing_categories = false; $index_filter_by_emplacement = false; $desindex_filter_by_emplacement = false; $this->_cleanOutput(true); if (!Tools::getValue('bool_cat')) $_POST['categories_association'] = array(); if (!Tools::getValue('bool_prod')) $_POST['products_association'] = array(); if (!Tools::getValue('bool_manu')) $_POST['manufacturers_association'] = array(); if (!Tools::getValue('bool_supp')) $_POST['suppliers_association'] = array(); if (!Tools::getValue('bool_spe')) $_POST['special_pages_association'] = array(); $this->errors = self::_retroValidateController($ObjAdvancedSearchClass); $_POST['background_color'] = $this->_getGradientFromArray('background_color'); $_POST['border_size'] = $this->_getBorderSizeFromArray(Tools::getValue('border_size')); //If indexation type change, reindex it if ($id_search && Tools::getValue('recursing_indexing') != $ObjAdvancedSearchClass->recursing_indexing) { $reindexing_categories = true; } //Check if filter_by_emplacement change if (Tools::getValue('filter_by_emplacement') && !$ObjAdvancedSearchClass->filter_by_emplacement) $index_filter_by_emplacement = true; elseif (!Tools::getValue('filter_by_emplacement') && $ObjAdvancedSearchClass->filter_by_emplacement) $desindex_filter_by_emplacement = true; if (!sizeof($this->errors)) { $this->copyFromPost($ObjAdvancedSearchClass); if (!$ObjAdvancedSearchClass->save()) $this->errors [] = $this->l('Error while saving'); if (!sizeof($this->errors)) { if (!$id_search && !$this->installDBCache($ObjAdvancedSearchClass->id)) $this->errors [] = $this->l('Error while making cache table'); elseif (!$id_search && !$ObjAdvancedSearchClass->addCacheProduct()) $this->errors [] = $this->l('Error while creating products index'); elseif ($id_search && !$ObjAdvancedSearchClass->updateCacheProduct()) $this->errors [] = $this->l('Error while creating products index'); //Indexation des critères d'emplacement if ($index_filter_by_emplacement) { AdvancedSearchClass::indexFilterByEmplacement($ObjAdvancedSearchClass->id); } elseif ($desindex_filter_by_emplacement) AdvancedSearchClass::desIndexFilterByEmplacement($ObjAdvancedSearchClass->id); //Indexation recursive if ($reindexing_categories) { AdvancedSearchClass::reindexingCategoriesGroups($ObjAdvancedSearchClass); } $this->generateCss(); $this->_html .= ''; } } $this->displayErrorsJs(); $this->_echoOutput(true); } private function _postProcessCriteria() { $id_search = Tools::getValue('id_search', false); $id_criterion = Tools::getValue('id_criterion', false); $key_criterions_group = Tools::getValue('key_criterions_group', false); $return = ''; if (!$id_search || !$id_criterion) $return .= ''; else { $objAdvancedSearchCriterionClass = new AdvancedSearchCriterionClass($id_criterion, $id_search); $update = $this->_uploadImageLang($objAdvancedSearchCriterionClass, 'icon', '/modules/pm_advancedsearch4/search_files/criterions/', '-' . $id_search); if (is_array($update) && sizeof($update)) foreach ($update as $error) $return .= ''; elseif ($update) $objAdvancedSearchCriterionClass->save(); $return .= ''; } self::_cleanBuffer(); echo $return; die(); } private function _postProcessSeoSearch() { $id_search = Tools::getValue('id_search', false); $id_seo = Tools::getValue('id_seo', false); $id_currency = Tools::getValue('id_currency', false); if (!$id_currency) $id_currency = Configuration::get('PS_CURRENCY_DEFAULT'); self::_cleanBuffer(); $return = ''; if (!$id_search) $return .= ''; else { //Get seo key for avoid doublon $seo_key = $this->getSeoKeyFromCriteria($id_search, explode(',', Tools::getValue('criteria')), $id_currency); //If exists but is deleted, load it // if (!$id_seo && $id_seo = AdvancedSearchSeoClass::seoDeletedExists($seo_key)) {} //If exist, display error if (!$id_seo && AdvancedSearchSeoClass::seoExists($seo_key)) { $return .= ''; } else { $objAdvancedSearchSeoClass = new AdvancedSearchSeoClass($id_seo); $this->copyFromPost($objAdvancedSearchSeoClass); $objAdvancedSearchSeoClass->seo_key = $seo_key; $objAdvancedSearchSeoClass->deleted = 0; $error = $objAdvancedSearchSeoClass->validateFields(false, true); $errorLang = $objAdvancedSearchSeoClass->validateFieldsLang(false, true); if ($error !== true) $return .= ''; if ($errorLang !== true) $return .= ''; elseif ($objAdvancedSearchSeoClass->save()) { $return .= ''; } else { $return .= ''; } } } //Generate seo sitemap $this->generateSeoGSiteMap(); echo $return; die(); } public static function str2url($str) { if (function_exists('mb_strtolower')) $str = mb_strtolower($str, 'utf-8'); $str = trim($str); $str = preg_replace('/[\x{0105}\x{0104}\x{00E0}\x{00E1}\x{00E2}\x{00E3}\x{00E4}\x{00E5}]/u','a', $str); $str = preg_replace('/[\x{00E7}\x{010D}\x{0107}\x{0106}]/u','c', $str); $str = preg_replace('/[\x{010F}]/u','d', $str); $str = preg_replace('/[\x{00E8}\x{00E9}\x{00EA}\x{00EB}\x{011B}\x{0119}\x{0118}]/u','e', $str); $str = preg_replace('/[\x{00EC}\x{00ED}\x{00EE}\x{00EF}]/u','i', $str); $str = preg_replace('/[\x{0142}\x{0141}\x{013E}\x{013A}]/u','l', $str); $str = preg_replace('/[\x{00F1}\x{0148}]/u','n', $str); $str = preg_replace('/[\x{00F2}\x{00F3}\x{00F4}\x{00F5}\x{00F6}\x{00F8}\x{00D3}]/u','o', $str); $str = preg_replace('/[\x{0159}\x{0155}]/u','r', $str); $str = preg_replace('/[\x{015B}\x{015A}\x{0161}]/u','s', $str); $str = preg_replace('/[\x{00DF}]/u','ss', $str); $str = preg_replace('/[\x{0165}]/u','t', $str); $str = preg_replace('/[\x{00F9}\x{00FA}\x{00FB}\x{00FC}\x{016F}]/u','u', $str); $str = preg_replace('/[\x{00FD}\x{00FF}]/u','y', $str); $str = preg_replace('/[\x{017C}\x{017A}\x{017B}\x{0179}\x{017E}]/u','z', $str); $str = preg_replace('/[\x{00E6}]/u','ae', $str); $str = preg_replace('/[\x{0153}]/u','oe', $str); // Remove all non-whitelist chars. $str = preg_replace('/[^a-zA-Z0-9\s\'\:\/\[\]-]/','', $str); $str = preg_replace('/[\s\'\:\/\[\]-]+/',' ', $str); $str = preg_replace('/[ ]/','-', $str); $str = preg_replace('/[\/]/','-', $str); // If it was not possible to lowercase the string with mb_strtolower, we do it after the transformations. // This way we lose fewer special chars. $str = strtolower($str); return $str; } public function getSeoStrings($criteria, $id_search, $id_currency, $fields_to_get = false) { $fieldToFill = array ('meta_title', 'meta_description', 'meta_keywords', 'title', 'seo_url' ); $fieldWithGroupName = array ('meta_title', 'meta_description' ); $groupTypeWithoutGroupName = array ('category', 'supplier', 'manufacturer' ); $offersSelectionStr = $this->translateMultiple('offers_selection'); $betweenLangStr = $this->translateMultiple('from'); $andLangStr = $this->translateMultiple('to'); foreach ($criteria as $k => $value) { $info_criterion = explode('_', $value); if (isset($info_criterion[2])) { $id_criterion_group = $info_criterion[1]; $id_criterion = $info_criterion[2]; }else { $id_criterion_group = $info_criterion[0]; $id_criterion = $info_criterion[1]; } if (!isset($newCriteria [$id_criterion_group])) $newCriteria [$id_criterion_group] = array(); $newCriteria [$id_criterion_group] [] = $id_criterion; } //Get crierion values per language foreach ($this->_languages as $language) { foreach ($criteria as $k => $criterion) { $endLoop = (($k + 1) == sizeof($criteria)); $info_criterion = explode('_', $criterion); if (isset($info_criterion[2])) { $id_criterion_group = $info_criterion[1]; $id_criterion = $info_criterion[2]; } else { $id_criterion_group = $info_criterion[0]; $id_criterion = $info_criterion[1]; } $isPriceCriterion = false; $objAdvancedSearchCriterionGroupClass = new AdvancedSearchCriterionGroupClass($id_criterion_group, $id_search); if (preg_match('#-#', $id_criterion)) { $isPriceCriterion = true; $range = explode('-', $id_criterion); $currency = new Currency($id_currency); $min = $range [0]; $max = Tools::displayPrice($range[1], $currency); $citerion_value = $betweenLangStr [$language ['id_lang']] . ' ' . $min . ' ' . $andLangStr [$language ['id_lang']] . ' ' . $max; } else { $objAdvancedSearchCriterionClass = new AdvancedSearchCriterionClass($id_criterion, $id_search, $language ['id_lang']); $citerion_value = (!$objAdvancedSearchCriterionClass->value && $objAdvancedSearchCriterionClass->single_value ? $objAdvancedSearchCriterionClass->single_value : trim($objAdvancedSearchCriterionClass->value)); } foreach ($fieldToFill as $k2 => $field) { if ($fields_to_get && ! in_array($field, $fields_to_get)) continue; if (!$k && $field == 'meta_description') @$defaultReturnSeoStr [$language ['id_lang']] [$field] .= Configuration::get('PS_SHOP_NAME') . ' ' . $offersSelectionStr [$language ['id_lang']] . ' '; //Add group name for these fields if (!$isPriceCriterion && in_array($field, $fieldWithGroupName) and ! in_array($objAdvancedSearchCriterionGroupClass->criterion_group_type, $groupTypeWithoutGroupName)) { @$defaultReturnSeoStr [$language ['id_lang']] [$field] .= $objAdvancedSearchCriterionGroupClass->name[$language ['id_lang']] . ' '; } //Convert url if ($field == 'seo_url') @$defaultReturnSeoStr [$language ['id_lang']] [$field] .= self::str2url($citerion_value) . (!$endLoop ? '-' : ''); //Include criterion value with separate char else @$defaultReturnSeoStr [$language ['id_lang']] [$field] .= $citerion_value . (!$endLoop && ($field == 'meta_title' || $field == 'meta_description' || $field == 'meta_keywords') ? ', ' : ($endLoop ? '' : ' ')); } } } return $defaultReturnSeoStr; } private function _cartesianReOrder($array) { $current = array_shift($array); if (count($array) > 0) { $results = array(); $temp = $this->_cartesianReOrder($array); foreach ($current as $value) foreach ($temp as $value2) $results[] = $value . ',' . $value2; return $results; } else { return $current; } } public static function getArrayCriteriaFromSeoArrayCriteria($criteria) { $newCriteria = array(); foreach ($criteria as $k => $value) { $info_criterion = explode('_', $value); if (isset($info_criterion[2])) { $id_criterion_group = (int)$info_criterion[1]; $id_criterion = (int)$info_criterion[2]; }else { $id_criterion_group = (int)$info_criterion[0]; $id_criterion = (int)$info_criterion[1]; } if (!isset($newCriteria[$id_criterion_group])) $newCriteria[$id_criterion_group] = array(); $newCriteria[$id_criterion_group][] = $id_criterion; } return $newCriteria; } private function countProductFromSeoCriteria($id_search, $criteria, $id_currency) { if (self::_isFilledArray($criteria) && $criteria[0]) { $selected_criteria_groups_type = array(); $newCriteria = self::getArrayCriteriaFromSeoArrayCriteria($criteria); if (sizeof($newCriteria)) { $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($id_search, array_keys($newCriteria)); } $search = AdvancedSearchClass::getSearch($id_search, $this->_cookie->id_lang,false); $search = $search[0]; $resultTotalProducts = Db::getInstance()->getRow(AdvancedSearchClass::getQueryCountResults($search, $this->_cookie->id_lang, $newCriteria, $selected_criteria_groups_type, $id_currency)); } $total_product = isset($resultTotalProducts) ? $resultTotalProducts ['total'] : 0; return $total_product; } private function getSeoKeyFromCriteria($id_search, $criteria, $id_currency) { if (!$id_currency) $id_currency = Configuration::get('PS_CURRENCY_DEFAULT'); // We do not need to sort // asort($criteria); $criteria = str_replace('biscriterion_', '', $criteria); $seo_key = (int)$id_search . '-' . implode('-', $criteria) . '-' . (int)$id_currency; $seo_key = md5($seo_key); return $seo_key; } private function _postProcessMassSeoSearch() { $id_search = Tools::getValue('id_search', false); $id_currency = Tools::getValue('id_currency', false); if (!$id_currency) $id_currency = Configuration::get('PS_CURRENCY_DEFAULT'); self::_cleanBuffer(); $return = ''; if (!$id_search) $return .= ''; else { $criteria_groups = explode(',', Tools::getValue('criteria_groups', '')); $criteria = Tools::getValue('criteria', false); $seoIds = array(); if (!sizeof($criteria_groups) || ! sizeof($criteria)) $return .= ''; else { $criteria_reorder = array(); foreach ($criteria_groups as $key_criterion_group) { $id_criterion_group = self::parseInt($key_criterion_group); if (isset($criteria [$id_criterion_group]) && sizeof($criteria [$id_criterion_group])) $criteria_reorder [] = $criteria [$id_criterion_group]; } $criteria_cartesian = $this->_cartesianReOrder($criteria_reorder); foreach ($criteria_cartesian as $k => $criteria_final_str) { $criteria_final = explode(',', $criteria_final_str); //Check if combination led to results $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, $criteria_final, $id_currency); if (!$resultTotalProducts) continue; //Get seo key for avoid doublon $seo_key = $this->getSeoKeyFromCriteria($id_search, $criteria_final, $id_currency); $cur_id_seo = AdvancedSearchSeoClass::seoExists($seo_key); //If exist undelete and ignore if ($cur_id_seo) AdvancedSearchSeoClass::undeleteSeoBySeoKey($seo_key); $defaultReturnSeoStr = $this->getSeoStrings($criteria_final, $id_search, $id_currency); $objAdvancedSearchSeoClass = new AdvancedSearchSeoClass($cur_id_seo); $objAdvancedSearchSeoClass->id_search = $id_search; $objAdvancedSearchSeoClass->criteria = $criteria_final_str; $objAdvancedSearchSeoClass->seo_key = $seo_key; foreach ($defaultReturnSeoStr as $id_lang => $fields) { foreach ($fields as $field => $fieldValue) { $objAdvancedSearchSeoClass->{$field} [$id_lang] = $fieldValue; } } $error = $objAdvancedSearchSeoClass->validateFields(false, true); $errorLang = $objAdvancedSearchSeoClass->validateFieldsLang(false, true); if ($error !== true) $return .= ''; elseif ($errorLang !== true) $return .= ''; else { $objAdvancedSearchSeoClass->save(); $seoIds [] = $objAdvancedSearchSeoClass->id; } } if (sizeof($seoIds)) { //Join all created seo foreach ($seoIds as $id_seo) { foreach ($seoIds as $id_seo2) { if ($id_seo == $id_seo2) continue; $row = array ('id_seo' => intval($id_seo), 'id_seo_linked' => intval($id_seo2) ); Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'pm_advancedsearch_seo_crosslinks', $row, 'INSERT'); } } } $return .= ''; } } //Generate seo sitemap $this->generateSeoGSiteMap(); echo $return; die(); } private function _postProcessSeoRegenerate() { $id_search = Tools::getValue('id_search', false); $fields_to_regenerate = Tools::getValue('fields_to_regenerate', false); self::_cleanBuffer(); if (!$id_search) $this->_html .= ''; if (!$fields_to_regenerate || ! sizeof($fields_to_regenerate)) $this->_html .= ''; else { $seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($this->_cookie->id_lang, false, $id_search); foreach ($seoSearchs as $row) { $defaultReturnSeoStr = $this->getSeoStrings(unserialize($row ['criteria']), $id_search, $row ['id_currency'], $fields_to_regenerate); if ($defaultReturnSeoStr && is_array($defaultReturnSeoStr) && sizeof($defaultReturnSeoStr)) { $objAdvancedSearchSeoClass = new AdvancedSearchSeoClass($row ['id_seo']); $objAdvancedSearchSeoClass->id_search = $id_search; foreach ($defaultReturnSeoStr as $id_lang => $fields) { foreach ($fields as $field => $fieldValue) { $objAdvancedSearchSeoClass->{$field} [$id_lang] = $fieldValue; } } $error = $objAdvancedSearchSeoClass->validateFields(false, true); $errorLang = $objAdvancedSearchSeoClass->validateFieldsLang(false, true); if ($error !== true) $this->_html .= ''; elseif ($errorLang !== true) $this->_html .= ''; else { if (!$objAdvancedSearchSeoClass->save()) $this->_html .= ''; } } } $this->_html .= ''; } //Generate seo sitemap $this->generateSeoGSiteMap(); echo $this->_html; die(); } public static function parseInt($string) { if (preg_match('/(\d+)/', $string, $array)) { return $array [1]; } else { return 0; } } public function saveAdvancedConfig() { if (Tools::getValue('submitAdvancedConfig')) { $this->updateAdvancedStyles(Tools::getValue('advancedConfig')); $this->_html .= $this->displayConfirmation($this->l('Styles updated successfully')); } } public function checkRewriteRule() { $htaccess = file_get_contents($this->_htFile); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $rule_match = 'index.php?fc=module&module=pm_advancedsearch4&controller=advancedsearch4&isolang=$1&id_seo=$2&seo_url=$3'; else $rule_match = 'RewriteCond %{QUERY_STRING} ^id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*)'; if (!preg_match('#'.preg_quote($rule_match).'#', $htaccess)) return false; //Check new rule format if (!preg_match('#\^\(\[a-z\]\{2\}\)\?\/\?s/#', $htaccess)) return false; //Check multishop rules if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) { foreach (array_values(Shop::getCompleteListOfShopsID()) AS $id_shop) { $shopUrl = new Shop($id_shop); $base_uri = $shopUrl->virtual_uri; if (!preg_match('#\^'.str_replace('\-', '-', preg_quote($base_uri)).'\(\[a-z\]\{2\}\)\?\/\?s/#', $htaccess)) return false; } } return true; } private function _writeRewriteRule() { if ($this->checkRewriteRule()) return true; if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $htaccess_source = file_get_contents($this->_htFile); $dest_rule = 'index.php?fc=module&module=pm_advancedsearch4&controller=advancedsearch4&isolang=$1&id_seo=$2&seo_url=$3'; } else { $htaccess_source = Configuration::get('PS_HTACCESS_SPECIFIC'); $dest_rule = __PS_BASE_URI__ . 'modules/pm_advancedsearch4/advancedsearch4.php?isolang=$1&id_seo=$2&seo_url=$3'; $dest_rule_2 = __PS_BASE_URI__ . 'modules/pm_advancedsearch4/advancedsearch4.php?'; } //Check new rule format if (preg_match('#\^\(\[a-z\]\{2\}\)\/s/#', $htaccess_source)) { $PS_HTACCESS_SPECIFIC = preg_replace('#\^\(\[a-z\]\{2\}\)\/s/#','^([a-z]{2})?/?s/', $htaccess_source); } else { //Clear Htaccess if (preg_match('#\#START AS4 RULES#', $htaccess_source)) { $htaccess_source = preg_replace('#\#START AS4 RULES(.*)\#END AS4 RULES\n?#s','', $htaccess_source); } $PS_HTACCESS_SPECIFIC = '#START AS4 RULES (Do not remove)'."\n"; if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $PS_HTACCESS_SPECIFIC .= ''."\n".'RewriteEngine on'."\n"; // SEO Sitemap alternative link $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^as4_seositemap.xml$ modules/pm_advancedsearch4/seositemap.xml [L]'."\n"; if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) { foreach (array_values(Shop::getCompleteListOfShopsID()) AS $id_shop) { $shopUrl = new Shop($id_shop); $base_uri = $shopUrl->virtual_uri; // Fix product comparaison 404 on PS 1.5+ $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} !^controller=products-comparison [NC]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^'.str_replace('\-', '-', preg_quote($base_uri)).'([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*) '.$dest_rule.' [QSA,L]'."\n"; } } else { // Fix product comparaison 404 on PS 1.5+ if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} !^controller=products-comparison [NC]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^([a-z]{2})?/?s/([0-9]+)/([a-zA-Z0-9/_-]*) '.$dest_rule.' [QSA,L]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^isolang=([a-z]{2})&id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*).*p=([0-9]+)$'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php '.__PS_BASE_URI__.'%1/s/%2/%3?p=%4 [R=301,L]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^isolang=([a-z]{2})&id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*)'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php '.__PS_BASE_URI__.'%1/s/%2/%3? [R=301,L]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*).*p=([0-9]+)$'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php '.__PS_BASE_URI__.'s/%1/%2?p=%3 [R=301,L]'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteCond %{QUERY_STRING} ^id_seo=([0-9]+)&seo_url=([a-zA-Z0-9/_-]*)'."\n"; $PS_HTACCESS_SPECIFIC .= 'RewriteRule ^advancedsearch4.php '.__PS_BASE_URI__.'s/%1/%2? [R=301,L]'."\n"; } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $PS_HTACCESS_SPECIFIC .= ''."\n"; $PS_HTACCESS_SPECIFIC .= '#END AS4 RULES'."\n"; $PS_HTACCESS_SPECIFIC .= $htaccess_source; } if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { return file_put_contents($this->_htFile, $PS_HTACCESS_SPECIFIC); }else { Configuration::updateValue('PS_HTACCESS_SPECIFIC', $PS_HTACCESS_SPECIFIC, true); if (Tools::generateHtaccess($this->_htFile, Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), $PS_HTACCESS_SPECIFIC, Configuration::get('PS_HTACCESS_DISABLE_MULTIVIEWS'))) return true; } return false; } protected function _postProcess() { $this->saveAdvancedConfig(); if (Tools::getIsset('submitSearch')) $this->_postProcessSearch(); elseif (Tools::getIsset('submitCriteria')) $this->_postProcessCriteria(); elseif (Tools::getIsset('submitSeoSearchForm')) $this->_postProcessSeoSearch(); elseif (Tools::getIsset('submitMassSeoSearchForm')) $this->_postProcessMassSeoSearch(); elseif (Tools::getIsset('submitSeoRegenerate')) $this->_postProcessSeoRegenerate(); elseif (Tools::getIsset('action') && Tools::getValue('action') == 'orderCriterion') { $this->_cleanOutput(); $order = Tools::getValue('order') ? explode(',', Tools::getValue('order')) : array(); $id_search = Tools::getValue('id_search'); foreach ($order as $position => $id_criterion) { if (!trim($id_criterion)) continue; $row = array ('position' => intval($position) ); Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'pm_advancedsearch_criterion_' . (int)$id_search, $row, 'UPDATE', 'id_criterion =' . self::parseInt($id_criterion)); } $this->_html .= $this->l('Saved'); $this->_echoOutput(true); } elseif (Tools::getIsset('action') && Tools::getValue('action') == 'orderCriterionGroup') { $this->_cleanOutput(); $order = Tools::getValue('order') ? explode(',', Tools::getValue('order')) : array(); $id_search = Tools::getValue('id_search'); $auto_hide = Tools::getValue('auto_hide'); $hidden = false; foreach ($order as $position => $key_criterions_group) { if ($key_criterions_group == "hide_after_".$id_search) { if ($auto_hide == 'true') $hidden = true; continue; } if (!trim($key_criterions_group)) continue; $row = array ('position' => intval($position), 'hidden' => (int)$hidden ); $infos_criterions_group = explode('-', $key_criterions_group); list ( $criterions_group_type, $id_criterion_group_linked, $id_search ) = $infos_criterions_group; if (!$criterions_group_type || !$id_search) continue; $id_criterion_group = AdvancedSearchCriterionGroupClass::getIdCriterionGroupByTypeAndIdLinked($id_search, $criterions_group_type, $id_criterion_group_linked); Db::getInstance()->AutoExecute(_DB_PREFIX_ . 'pm_advancedsearch_criterion_group_' . (int)$id_search, $row, 'UPDATE', 'id_criterion_group = ' . (int)$id_criterion_group); } $this->_html .= $this->l('Saved'); $this->_echoOutput(true); } // Other Request parent::_postProcess(); } //After save process protected function _postSaveProcess($params) { parent::_postSaveProcess($params); if ($params['class'] == 'AdvancedSearchCriterionGroupClass' && Tools::isSubmit('submitCriteriaGroupOptions')) { $this->generateCss(); if (Validate::isLoadedObject($params['obj'])) { $this->_html .= ''; } $this->_html .= ''; } } //After delete process protected function _postDeleteProcess($params) { parent::_postDeleteProcess($params); if ($params['class'] == 'AdvancedSearchClass') { $this->_html .= 'removeTabPanel("#wrapAsTab","li#TabSearchAdminPanel' . Tools::getValue('id_search') . '","ul#asTab", '.(int)version_compare(_PS_VERSION_, '1.6.0.0', '>=').');'; //Generate seo sitemap $this->generateSeoGSiteMap(); } } protected function checkSeoCriteriaCombination(){ $criteria = Tools::getValue('criteria', false); $id_search = Tools::getValue('id_search', false); $id_currency = Tools::getValue('id_currency', false); if (!$criteria || !$id_search) die(); $criteria = explode(',', $criteria); //Check if combination led to results $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, $criteria, $id_currency); if (!$resultTotalProducts) { $this->_html .= '$jqPm("input[name=submitSeoSearchForm]").hide();$jqPm("#errorCombinationSeoSearchForm").show();'; $this->_html .= '$jqPm("#nbProductsCombinationSeoSearchForm").html(\'

0 ' . $this->l('result found') . '

\');'; } else { $this->_html .= '$jqPm("input[name=submitSeoSearchForm]").show();$jqPm("#errorCombinationSeoSearchForm").hide();'; $this->_html .= '$jqPm("#nbProductsCombinationSeoSearchForm").html(\'

' . $resultTotalProducts . ' ' . $this->l('result(s) found(s)') . '

\');'; } } public function displaySearchAdminPanel() { $id_search = (int) Tools::getValue('id_search'); $advanced_search = AdvancedSearchClass::getSearch($id_search, $this->_cookie->id_lang, false); if (!isset($advanced_search [0])) return; $advanced_search = $advanced_search [0]; $criterions_groups = $this->getCriterionsGroupsValue($this->_cookie->id_lang); $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexed($advanced_search ['id_search'], $this->_cookie->id_lang); $keys_criterions_group_indexed = array(); $criterions_groups_to_reindex = AdvancedSearchClass::getCriterionsGroupsIndexed($advanced_search ['id_search'], $this->_cookie->id_lang,false); //Prepare JS array for reindexation if (self::_isFilledArray($criterions_groups_to_reindex)) { $this->_html .= ''; } $this->_html .= '
'; /*Actions*/ $this->_addButton(array('text'=> $this->l('Edit'),'href'=>$this->_base_config_url . '&pm_load_function=displaySearchForm&class=AdvancedSearchClass&pm_js_callback=closeDialogIframe&id_search=' . $advanced_search ['id_search'],'class'=>'open_on_dialog_iframe','rel'=>'980_530_1','icon_class'=>'ui-icon ui-icon-pencil')); $this->_addButton(array('text'=> $this->l('Delete'),'href'=>$this->_base_config_url . '&pm_delete_obj=1&class=AdvancedSearchClass&id_search=' . $advanced_search ['id_search'],'class'=>'ajax_script_load pm_confirm','icon_class'=>'ui-icon ui-icon-trash', 'title'=>addcslashes($this->l('Delete item #'), "'") . $advanced_search ['id_search'] . ' ?')); $this->_addButton(array('text'=> $this->l('Status:') . ' ' . ($advanced_search ['active'] ? $this->l('enabled') : $this->l('disable')) . '','href'=>$this->_base_config_url . '&pm_load_function=processActiveSearch&id_search=' . $advanced_search ['id_search'],'class'=>'ajax_script_load status_search_' . (int)$advanced_search ['id_search'],'icon_class'=>'ui-icon ' . ($advanced_search ['active'] ? 'ui-icon-circle-check' : 'ui-icon-circle-close'), 'title'=>addcslashes($this->l('Change status'), "'"))); $this->_addButton(array('text'=> $this->l('Reindexing this search'),'href'=>'javascript:void(0);','class'=>'ajax_script_load','icon_class'=>'ui-icon ui-icon-shuffle','onclick'=>'reindexSearchCritriaGroups(this,criteriaGroupToReindex'.$id_search.',"#progressbarReindexSpecificSearch' . (int)$advanced_search ['id_search'] . '");')); $this->_html .= '
'; $this->_pmClear(); $this->_html .= '

' . $this->l('Active criteria groups') . '

'; $this->_html .= '
'; $this->_html .= '
'; $this->_pmClear(); $keys_criterions_group_indexed = array(); $hidden = true; $this->_html .= '
    '; foreach ($criterions_groups_indexed as $criterions_group_indexed) { if ($criterions_group_indexed['hidden'] && $hidden){ $this->_html .= '
  • ' . $this->l('Groups under this line will be hidden') . '

  • '; $hidden = false; } $key_criterions_group_indexed = $criterions_group_indexed ['criterion_group_type'] . '-' . (int)$criterions_group_indexed ['id_criterion_group_linked'] . '-' . (int)$advanced_search ['id_search']; $keys_criterions_group_indexed [] = $key_criterions_group_indexed; $this->_html .= '
  • ' . $criterions_group_indexed ['name'] . ' ('.$this->criteriaGroupLabels[$criterions_group_indexed ['criterion_group_type']].')
  • '; $this->_html .= ''; } if ($hidden){ $this->_html .= ''; } $this->_html .= '
'; $this->_html .= ' '; $this->_html .= '

' . $this->l('Available criteria groups') . '

    '; foreach ($criterions_groups as $criterions_group) { $key_criterions_group = $criterions_group ['type'] . '-' . (int)$criterions_group ['id'] . '-' . (int)$advanced_search ['id_search']; if (in_array($key_criterions_group, $keys_criterions_group_indexed)) continue; $this->_html .= '
  • ' . $criterions_group ['name'] . ' ('.$this->criteriaGroupLabels[$criterions_group ['type']].')
  • '; } $this->_html .= '
'; $this->_pmClear(); $this->_html .= '
'; $this->_html .= ''; $this->_html .= ' '; } /** * Generate SEO sitemap for indexing URL in GOOGLE */ public function generateSeoGSiteMap() { $xmlSiteMap = << XML; $xml = new SimpleXMLElement($xmlSiteMap); foreach(Language::getLanguages(true) as $language) { $seo_searchs = AdvancedSearchSeoClass::getSeoSearchs($language['id_lang']); foreach($seo_searchs as $seo_search) { $nb_criteria = count(explode(',', $seo_search['criteria'])); if ($nb_criteria <= 3) $priority = 0.7; elseif ($nb_criteria <= 5) $priority = 0.6; else $priority = 0.5; $sitemap = $xml->addChild('url'); $sitemap->addChild('loc', _PS_BASE_URL_.__PS_BASE_URI__.(Language::countActiveLanguages() > 1 ? $language['iso_code'].'/': '').'s/'.(int)$seo_search['id_seo'].'/'.htmlentities($seo_search['seo_url'],ENT_COMPAT,'UTF-8')); $sitemap->addChild('priority', $priority); $sitemap->addChild('changefreq', 'weekly'); } } $xmlSiteMap = $xml->asXML(); $res = file_put_contents(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/seositemap.xml', $xmlSiteMap); return ($res!==false); } protected function processIndexCriterionsGroup($optimization = true) { self::_changeTimeLimit(0); //self::_iniSet('memory_limit', '100M'); $key_criterions_group = Tools::getValue('key_criterions_group',false); if (!$key_criterions_group) die; $infos_criterions_group = explode('-', $key_criterions_group); $error = 0; list($criterions_group_type, $id_criterion_group_linked, $id_search) = $infos_criterions_group; if (!$criterions_group_type || !$id_search) die; $objSearch = new AdvancedSearchClass($id_search, $this->_cookie->id_lang); $id_criterion_group = AdvancedSearchClass::indexCriterionsGroup($criterions_group_type, $id_criterion_group_linked, $objSearch); //Tables optimization AdvancedSearchClass::optimizedSearchTables($objSearch->id); //Remove loading $this->_html .= '$jqPm("#'.$key_criterions_group.'").children(".loadingOnConnectList").hide().remove();'; $this->_html .= 'setCriterionGroupActions("'.$key_criterions_group.'");'; //set id criterion group on rel attribut $this->_html .= '$jqPm("#'.$key_criterions_group.'").attr("rel",'.(int)$id_criterion_group.');'; //Open criteria group option $this->_html .= 'getCriterionGroupActions("'.$key_criterions_group.'");'; } protected function processDesindexCriterionsGroup() { $key_criterions_group = Tools::getValue('key_criterions_group',false); if (!$key_criterions_group) die; $infos_criterions_group = explode('-', $key_criterions_group); $error = 0; list($criterions_group_type, $id_criterion_group_linked, $id_search) = $infos_criterions_group; if (!$criterions_group_type || !$id_search) die; AdvancedSearchClass::desIndexCriterionsGroup($criterions_group_type, $id_criterion_group_linked, $id_search); //Tables optimization AdvancedSearchClass::optimizedSearchTables($id_search); $this->_html .= '$jqPm("#'.$key_criterions_group.'").children(".loadingOnConnectList").fadeOut("fast");'; } protected function processRemoveEmptySeo() { $id_search = Tools::getValue('id_search', false); if (!$id_search) die(); $seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($this->_cookie->id_lang, false, $id_search); foreach ($seoSearchs as $row) { $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, unserialize($row ['criteria']), $row ['id_currency']); if (!$resultTotalProducts) { $objAdvancedSearchSeoClass = new AdvancedSearchSeoClass($row ['id_seo']); if (!$objAdvancedSearchSeoClass->delete()) $this->_html .= 'show_error("' . $this->l('Error while deleting seo search') . ' ' . $row ['id_seo'] . '");'; } } $this->_html .= 'show_info("' . $this->l('Empty SEO pages has been deleted') . '");reloadPanel("seo_search_panel_' . (int)$id_search . '");'; } protected function processFillSeoFields() { $criteria = Tools::getValue('criteria',false); $id_search = Tools::getValue('id_search',false); $id_currency = Tools::getValue('id_currency',false); if (!$criteria || !$id_search) die; $criteria = explode(',', $criteria); $defaultReturnSeoStr = $this->getSeoStrings($criteria, $id_search, $id_currency); foreach($defaultReturnSeoStr as $id_lang => $fields) { foreach($fields as $field => $fieldValue) { $this->_html .= '$jqPm("input[name='.$field.'_'.$id_lang.']").val("'.addcslashes($fieldValue,'"').'");'; } } } protected function processClearAllTables() { $advanced_searchs_id = AdvancedSearchClass::getSearchsId(false); AdvancedSearchClass::clearAllTables(); foreach($advanced_searchs_id as $key=>$row) { $this->_html .= 'removeTabPanel("#wrapAsTab","li#TabSearchAdminPanel'.$row['id_search'].'","ul#asTab", '.(int)version_compare(_PS_VERSION_, '1.6.0.0', '>=').');'; } $this->_html .= '$jqPm(window).scrollTo("#wrapAsTab",500,{onAfter:function() { show_info("'.addcslashes($this->l('Clear done'),'"').'"); $jqPm("#msgNoResults").slideDown(); }});'; } protected function processReindexSpecificSearch() { //Increase server limit self::_changeTimeLimit(0); //self::_iniSet('memory_limit', '100M'); $id_search = Tools::getValue('id_search'); $this->reindexSpecificSearch($id_search); $this->_html .= '$jqPm( "#progressbarReindexSpecificSearch'.(int)$id_search.'" ).progressbar( "option", "value", 100 );show_info("'.addcslashes($this->l('Indexation done'),'"').'")'; } protected function processDeleteCriterionImg() { $id_search = Tools::getValue('id_search'); $id_criterion = Tools::getValue('id_criterion'); $id_lang = Tools::getValue('id_lang'); $objCriterion = new AdvancedSearchCriterionClass($id_criterion, $id_search); $file_name = $objCriterion->icon[$id_lang]; $file_name_final_path = _PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/'.$file_name; $objCriterion->icon[$id_lang] = ''; if (AdvancedSearchCoreClass::_isRealFile($file_name_final_path)) unlink($file_name_final_path); if ($objCriterion->save()) $this->_html .= 'show_info("'.addcslashes($this->l('Criterion image deleted'),'"').'");'; else $this->_html .= 'show_info("'.addcslashes($this->l('An error occured'),'"').'");'; } protected function processSaveCriterionImg() { $id_search = Tools::getValue('id_search'); $id_criterion = Tools::getValue('id_criterion'); $id_lang = Tools::getValue('id_lang'); $file_name = Tools::getValue('file_name'); $file_name_temp_path = _PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/uploads/temp/'.$file_name; $file_name_final_path = _PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/'.$file_name; if (AdvancedSearchCoreClass::_isRealFile($file_name_temp_path)) { //Move it from temp directory to final directory rename($file_name_temp_path, $file_name_final_path); $objCriterion = new AdvancedSearchCriterionClass($id_criterion, $id_search); $objCriterion->icon[$id_lang] = $file_name; if ($objCriterion->save()) $this->_html .= 'ok'; else $this->_html .= 'ko'; }else $this->_html .= 'ko'; } protected function processDeleteCustomCriterion() { $objCriterion = new AdvancedSearchCriterionClass((int)Tools::getValue('id_criterion'), (int)Tools::getValue('id_search')); if (Validate::isLoadedObject($objCriterion)) { if ($objCriterion->delete()) { $this->_html .= 'parent.show_info("' . $this->l('Successfully deleted') . '");'; $this->_html .= 'this.location.reload(true);'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterion') . '");'; } } else { $this->_html .= 'parent.show_error("' . $this->l('Error while deleting criterion') . '");'; } } protected function processAddCustomCriterion() { $objCriterion = new AdvancedSearchCriterionClass(null, (int)Tools::getValue('id_search')); $objCriterion->id_criterion_group = (int)Tools::getValue('id_criterion_group'); $objCriterion->id_criterion_linked = 0; $objCriterion->is_custom = 1; $this->copyFromPost($objCriterion); $validationErrors = AdvancedSearchCoreClass::_retroValidateController($objCriterion); if (!self::_isFilledArray($validationErrors)) { if ($objCriterion->add()) { $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; $this->_html .= 'this.location.reload(true);'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while adding criterion') . '");'; } } else { $this->_html .= 'parent.show_error("' . $this->l('Error while adding criterion') . '");'; foreach ($validationErrors as $error) $this->_html .= 'parent.show_error("' . $error . '");'; } } protected function processUpdateCustomCriterion() { $objCriterion = new AdvancedSearchCriterionClass((int)Tools::getValue('id_criterion'), (int)Tools::getValue('id_search')); $this->copyFromPost($objCriterion); if (Validate::isLoadedObject($objCriterion)) { if ($objCriterion->save()) { $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; $this->_html .= 'this.location.reload(true);'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterion') . '");'; } } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterion') . '");'; } } protected function processAddCustomCriterionToGroup() { $idSearch = (int)Tools::getValue('id_search'); $idCriterionGroup = (int)Tools::getValue('id_criterion_group'); $criterionsGroupList = explode(',', Tools::getValue('criterionsGroupList')); $newCriterionsGroupList = array(); if (self::_isFilledArray($criterionsGroupList)) { foreach ($criterionsGroupList as $criterionsGroupListRow) { $criterionsGroupListRow = explode('-', $criterionsGroupListRow); $idCriterion = (int)$criterionsGroupListRow[0]; $idCriterionParent = (int)$criterionsGroupListRow[1]; if (!$idCriterionParent) continue; $newCriterionsGroupList[$idCriterionParent][] = $idCriterion; } } $customCriterionList = AdvancedSearchCriterionClass::getCustomCriterionsLinkIdsByGroup($idSearch, $idCriterionGroup); foreach ($customCriterionList as $idCriterionParent => $currentCriterionsGroupList) { Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_list` WHERE `id_criterion_parent`='.(int)$idCriterionParent); AdvancedSearchCriterionClass::populateCriterionsLink($idSearch, $idCriterionParent); } foreach ($newCriterionsGroupList as $idCriterionParent => $currentCriterionsGroupList) { Db::getInstance()->Execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_list` WHERE `id_criterion_parent`='.(int)$idCriterionParent); if (self::_isFilledArray($currentCriterionsGroupList)) { foreach ($currentCriterionsGroupList as $idCriterion) AdvancedSearchCriterionClass::addCriterionToList($idSearch, $idCriterionParent, $idCriterion); } AdvancedSearchCriterionClass::populateCriterionsLink($idSearch, $idCriterionParent, false, $currentCriterionsGroupList); } $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; } protected function processEnableAllCriterions() { $objCriterionGoup = new AdvancedSearchCriterionGroupClass((int)Tools::getValue('id_criterion_group'), (int)Tools::getValue('id_search')); if (Validate::isLoadedObject($objCriterionGoup)) { if (AdvancedSearchCriterionGroupClass::enableAllCriterions((int)Tools::getValue('id_search'), (int)Tools::getValue('id_criterion_group'))) { $this->_html .= '$jqPm("img[id^=imgActiveCriterion]").attr("src","../img/admin/enabled.gif");'; $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterions status') . '");'; } } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterions status') . '");'; } } protected function processDisableAllCriterions() { $objCriterionGoup = new AdvancedSearchCriterionGroupClass((int)Tools::getValue('id_criterion_group'), (int)Tools::getValue('id_search')); if (Validate::isLoadedObject($objCriterionGoup)) { if (AdvancedSearchCriterionGroupClass::disableAllCriterions((int)Tools::getValue('id_search'), (int)Tools::getValue('id_criterion_group'))) { $this->_html .= '$jqPm("img[id^=imgActiveCriterion]").attr("src","../img/admin/disabled.gif");'; $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterions status') . '");'; } } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating criterions status') . '");'; } } protected function processActiveCriterion() { $ObjAdvancedSearchCriterionClass = new AdvancedSearchCriterionClass(Tools::getValue('id_criterion'), Tools::getValue('id_search')); $ObjAdvancedSearchCriterionClass->visible = ($ObjAdvancedSearchCriterionClass->visible ? 0 : 1); if ($ObjAdvancedSearchCriterionClass->save()) { $this->_html .= '$jqPm("#imgActiveCriterion' . $ObjAdvancedSearchCriterionClass->id . '").attr("src","../img/admin/' . ($ObjAdvancedSearchCriterionClass->visible ? 'enabled' : 'disabled') . '.gif");'; $this->_html .= 'parent.show_info("' . $this->l('Saved') . '");'; } else { $this->_html .= 'parent.show_error("' . $this->l('Error while updating search') . '");'; } } protected function processActiveSearch() { $ObjAdvancedSearchClass = new AdvancedSearchClass(Tools::getValue('id_search')); $ObjAdvancedSearchClass->active = ($ObjAdvancedSearchClass->active ? 0 : 1); if ($ObjAdvancedSearchClass->save()) { //Change search status if ($ObjAdvancedSearchClass->active) $this->_html .= '$jqPm("#searchStatusLabel' . $ObjAdvancedSearchClass->id . '").html("' . $this->l('enabled') . '");$jqPm(".status_search_' . $ObjAdvancedSearchClass->id . ' span").removeClass("ui-icon-circle-close").addClass("ui-icon-circle-check");'; else $this->_html .= '$jqPm("#searchStatusLabel' . $ObjAdvancedSearchClass->id . '").html("' . $this->l('disabled') . '");$jqPm(".status_search_' . $ObjAdvancedSearchClass->id . ' span").removeClass("ui-icon-circle-check").addClass("ui-icon-circle-close");'; $this->_html .= 'show_info("' . $this->l('Saved') . '");'; } else { $this->_html .= 'show_error("' . $this->l('Error while updating search') . '");'; } } protected function processDeleteSeoSearch() { $ObjAdvancedSearchSeoClass = new AdvancedSearchSeoClass(Tools::getValue('id_seo')); $ObjAdvancedSearchSeoClass->deleted = 1; if ($ObjAdvancedSearchSeoClass->save()) { $this->_html .= 'show_info("' . $this->l('Seo Search has been deleted') . '");reloadPanel("seo_search_panel_' . (int)Tools::getValue('id_search') . '");'; } else $this->_html .= 'show_error("' . $this->l('Error while deleting seo search') . '");'; } protected function processWriteSeoRewriteRule() { $id_search = Tools::getValue('id_search'); if ($this->_writeRewriteRule()) $this->_html .= 'show_info("' . $this->l('Htaccess has been updated') . '");reloadPanel("seo_search_panel_' . (int)$id_search . '");'; else $this->_html .= 'show_error("' . $this->l('Error while updating Htaccess') . '");'; } protected function processDeleteMassSeo() { $id_seos = Tools::getValue('seo_group_action', false); $id_search = Tools::getValue('id_search', false); if (self::_isFilledArray($id_seos)) { foreach ($id_seos as $id_seo) { $objAdvancedSearchSeoClass = new AdvancedSearchSeoClass($id_seo); $objAdvancedSearchSeoClass->deleted = 1; $objAdvancedSearchSeoClass->save(); } $this->_html .= 'show_info("' . $this->l('Seo Pages has been deleted') . '");reloadPanel("seo_search_panel_' . (int)$id_search . '");'; }else $this->_html .= 'show_error("' . $this->l('Please select at least one seo page') . '");'; } protected function displaySeoPriceSlider() { $id_search = Tools::getValue('id_search', false); $id_criterion_group_linked = Tools::getValue('id_criterion_group_linked', false); $id_currency = Tools::getValue('id_currency', false); $currency = new Currency($id_currency); if (!$id_search || !$id_currency) die(); $search = AdvancedSearchClass::getSearch($id_search,false); $price_range = AdvancedSearchClass::getPriceRangeForSearchBloc($search[0], $id_criterion_group_linked, (int)$id_currency, $this->getCurrentCustomerGroupId(), 0, false, array(), array()); $min_price_id_currency = (int)$price_range [0] ['min_price_id_currency']; $max_price_id_currency = (int)$price_range [0] ['max_price_id_currency']; if (($min_price_id_currency == 0 && $min_price_id_currency != $id_currency) || ($min_price_id_currency != 0 && $min_price_id_currency != $id_currency)) $price_range [0] ['min_price'] = Tools::convertPrice($price_range [0] ['min_price'], $id_currency); if (($max_price_id_currency == 0 && $max_price_id_currency != $id_currency) || ($max_price_id_currency != 0 && $max_price_id_currency != $id_currency)) $price_range [0] ['max_price'] = Tools::convertPrice($price_range [0] ['max_price'], $id_currency); //Floor min price $price_range [0] ['min_price'] = floor($price_range [0] ['min_price']); //Ceil max price $price_range [0] ['max_price'] = ceil($price_range [0] ['max_price']); $this->_html .= '$jqPm( "#PM_ASSeoPriceRange" ).slider({ range: true, min: ' . (int)$price_range[0] ['min_price'] . ', max: ' . (int)$price_range[0] ['max_price'] . ', values: [ ' . (int)$price_range[0]['min_price'] . ', ' . (int)$price_range[0]['max_price'] . ' ], slide: function( event, ui) { $jqPm( "#PM_ASPriceRangeValue" ).html( "" + ui.values[ 0 ] + " - " + "'.$currency->getSign('left').'" + ui.values[ 1 ] + "'.$currency->getSign('right').'" ); $jqPm( "#massSeoSearchCriterionPriceInput" ).val("-" + ui.values[ 0 ] + "-" + ui.values[ 1 ] ); $jqPm( ".seoSearchCriterionPriceSortable" ).attr("id", "criterion_price-" + ui.values[ 0 ] + "-" + ui.values[ 1 ] ); $jqPm( ".seoSearchCriterionPriceSortable" ).attr("title", "' . $this->l('From') . ' " + ui.values[ 0 ] + " ' . $this->l('to') . ' " + "'.$currency->getSign('left').'" + ui.values[ 1 ] + "'.$currency->getSign('right').'" ); } }); $jqPm( "#PM_ASPriceRangeValue" ).html( "' . (int)$price_range[0]['min_price'] . ' - ' . Tools::displayPrice((int)$price_range[0]['max_price'], $currency) . '" ); $jqPm( ".seoSearchCriterionPriceSortable" ).attr("id", "criterion_price-' . (int)$price_range[0]['min_price'] . '-' . (int)$price_range[0]['max_price'] . '" ); $jqPm( ".seoSearchCriterionPriceSortable" ).attr("title", "' . $this->l('From') . ' ' . (int)$price_range[0]['min_price'] . ' ' . $this->l('to') . ' ' . Tools::displayPrice((int)$price_range[0]['max_price'], $currency) . '" );'; } protected function displaySeoSearchOptions() { if (Tools::getValue('id_seo_excludes')) $id_seo_excludes = explode(',', Tools::getValue('id_seo_excludes', false)); else $id_seo_excludes = false; $query_search = Tools::getValue('q', false); $limit = Tools::getValue('limit', 100); $start = Tools::getValue('start', 0); $nbResults = AdvancedSearchSeoClass::getCrossLinksAvailable($this->_cookie->id_lang, $id_seo_excludes, $query_search, true); $results = AdvancedSearchSeoClass::getCrossLinksAvailable($this->_cookie->id_lang, $id_seo_excludes, $query_search, false, $limit, $start); foreach ($results as $key => $value) { $this->_html .= $key . '=' . $value . "\n"; } if ($nbResults > ($start + $limit)) $this->_html .= 'DisplayMore' . "\n"; } protected function displayCmsOptions() { $query = Tools::getValue('q', false); if (trim($query)) { $limit = Tools::getValue('limit', 100); $start = Tools::getValue('start', 0); $items = Db::getInstance()->ExecuteS(' SELECT c.`id_cms`, cl.`meta_title` FROM `'._DB_PREFIX_.'cms` c LEFT JOIN `'._DB_PREFIX_.'cms_lang` cl ON (c.`id_cms` = cl.`id_cms`) WHERE (cl.`meta_title` LIKE \'%'.pSQL($query).'%\') AND cl.`id_lang` = '.(int)($this->_cookie->id_lang).' AND c.`active` = 1 ORDER BY cl.`meta_title` '.($limit? 'LIMIT '.$start.', '.(int)$limit : '') ); if ($items) foreach($items as $row) $this->_html .= $row['id_cms']. '=' .$row['meta_title']. "\n"; } } protected function displaySeoSearchPanelList() { $id_search = Tools::getValue('id_search'); $this->_html .= '

' . $this->l('Pages generator for SEO') . '

'; if (!Configuration::get('PS_REWRITING_SETTINGS')) $this->_showInfo($this->l('Please activate Friendly URL to use this option')); elseif (!is_writable($this->_htFile)) $this->_showInfo($this->l('Please give write permission to file') . ' ' . $this->_htFile); elseif (!$this->checkRewriteRule()) $this->_showInfo($this->l('The rewrite rule is not present in your htaccess file.') . '

' . $this->l('Click here to update your htaccess.') . ''); else { $this->_html .= '
'; $this->_showInfo($this->l('The SEO google sitemap is located at: ').' '._PS_BASE_URL_.__PS_BASE_URI__.'as4_seositemap.xml'); $this->_html .= '
'; $this->_addButton(array('text'=> $this->l('Add products page'),'href'=>$this->_base_config_url . '&pm_load_function=displaySeoSearchForm&class=AdvancedSearchSeoClass&pm_js_callback=closeDialogIframe&id_search=' . (int)$id_search,'class'=>'open_on_dialog_iframe','rel'=>'950_530_1','icon_class'=>'ui-icon ui-icon-circle-plus')); $this->_addButton(array('text'=> $this->l('Massive add of products pages'),'href'=>$this->_base_config_url . '&pm_load_function=displayMassSeoSearchForm&pm_js_callback=closeDialogIframe&id_search=' . (int)$id_search,'class'=>'open_on_dialog_iframe','rel'=>'950_530_1','icon_class'=>'ui-icon ui-icon-circle-plus')); $seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($this->_cookie->id_lang, false, $id_search); if ($seoSearchs && self::_isFilledArray($seoSearchs)) { $this->_html .= '
'; $this->_addButton(array('text'=> $this->l('Remove empty results pages'),'href'=>$this->_base_config_url . '&pm_load_function=processRemoveEmptySeo&id_search=' . $id_search,'class'=>'ajax_script_load','icon_class'=>'ui-icon ui-icon-trash')); $this->_addButton(array('text'=> $this->l('Regenerate SEO data'),'href'=>$this->_base_config_url . '&pm_load_function=displaySeoRegenerateForm&id_search=' . (int)$id_search,'class'=>'open_on_dialog_iframe','rel'=>'700_315','icon_class'=>'ui-icon ui-icon-refresh')); $this->_addButton(array('text'=> $this->l('List all SEO URL'),'href'=>$this->_base_config_url . '&pm_load_function=displaySeoUrlList&id_search=' . (int)$id_search,'class'=>'open_on_dialog_iframe','rel'=>'950_530_1','icon_class'=>'ui-icon ui-icon-link')); $this->_html .= ''; $this->_html .= ''; foreach ($seoSearchs as $row) { $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, unserialize($row ['criteria']), $row ['id_currency']); $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; } $this->_html .= ''; $this->_html .= '
'; $this->_addButton(array('text'=> $this->l('Check/Uncheck all'),'href'=>'javascript:void(0);','onclick'=>'checkAllSeoItems('.(int)$id_search.');','icon_class'=>'ui-icon')); $this->_addButton(array('text'=> $this->l('Delete selected items'),'href'=>'javascript:void(0);','onclick'=>'deleteSeoItems('.(int)$id_search.');','icon_class'=>'ui-icon ui-icon-trash')); $this->_html .= ''; }else { $this->_showInfo($this->l('No seo page at this time please add one')); } } } protected function displaySeoUrl($id_search) { $id_search = Tools::getValue('id_search',false); $id_seo = Tools::getValue('id_seo',false); if (!$id_seo || !$id_search) die; $ObjAdvancedSearchSeoClass = new AdvancedSearchSeoClass($id_seo,null); $this->_startForm(array('id' => 'SEOpages')); $this->_displayTitle($this->l('Products page URL')); $this->_showInfo($this->l('Use this URL in your slideshows, menus and others. One link per language is available.')); $this->_html .= '
'; if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) { $shopUrl = new Shop($this->_context->shop->id); $base_url = $shopUrl->getBaseURL(); }else $base_url = Tools::getShopDomain(true) . __PS_BASE_URI__ ; foreach ($this->_languages as $language) { $this->_html .= '
'; } $this->displayPMFlags(); $this->_pmClear(); $this->_html .= '
'; $this->_endForm(array('id' => 'SEOpages')); } protected function displaySeoUrlList() { $id_search = Tools::getValue('id_search'); $this->_startForm(array('id' => 'SEOURLListForm')); $this->_displayTitle($this->l('SEO URL list')); $this->_showInfo($this->l('You will find here the list of all the SEO URLs pages you have created for this search engine. You have to add them in your menu, slideshow, footer, blocks, or anywhere you want in your website for Google crawling')); $seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($this->_cookie->id_lang, false, $id_search); if ($seoSearchs && self::_isFilledArray($seoSearchs)) { $new_SeoSearch = array(); foreach ($seoSearchs as $row) { $resultTotalProducts = $this->countProductFromSeoCriteria($id_search, unserialize($row ['criteria']), $row ['id_currency']); $ObjAdvancedSearchSeoClass = new AdvancedSearchSeoClass($row['id_seo'], null); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::isFeatureActive()) { $shopUrl = new Shop($this->_context->shop->id); $base_url = $shopUrl->getBaseURL(); } else { $base_url = Tools::getShopDomain(true) . __PS_BASE_URI__ ; } foreach ($this->_languages as $language) { $url = $base_url . (Language::countActiveLanguages() > 1 ? $language ['iso_code'].'/': '') . 's/' . (int)$ObjAdvancedSearchSeoClass->id . '/' . $ObjAdvancedSearchSeoClass->seo_url [$language ['id_lang']]; $title = htmlentities($ObjAdvancedSearchSeoClass->title[$language ['id_lang']], ENT_COMPAT, 'UTF-8'); $new_SeoSearch[$language['id_lang']][$ObjAdvancedSearchSeoClass->id]['url'] = $url; $new_SeoSearch[$language['id_lang']][$ObjAdvancedSearchSeoClass->id]['title'] = $title; } } $seoSearchs = $new_SeoSearch; unset($new_SeoSearch); if ($seoSearchs && self::_isFilledArray($seoSearchs)) { $this->_html .= '

'.$this->l('Please select the language :').'

'; $this->displayPMFlags(); $this->_html .= '

'; foreach ($seoSearchs as $id_lang=>$seo_urls) { $this->_html .= '
'; $this->_html .= '

'.$this->l('HTML version:').'

'; $this->_html .= ''; $this->_html .= '

'.$this->l('CSV version:').'

'; $this->_html .= ''; $this->_html .= '
'; } } } else { $this->_showInfo($this->l('No seo page at this time please add one')); } $this->_endForm(array('id' => 'SEOURLListForm')); } protected function displaySeoRegenerateForm() { $id_search = Tools::getValue('id_search'); $this->_startForm(array('id' => 'seoRegenerateForm')); $this->_displayTitle($this->l('Regenerate SEO data')); $this->_showInfo($this->l('Select data bellow to regenerate')); $this->_html .= ''; $this->_html .= '
'; $this->_pmClear(); $this->_html .= '
'; $this->_displaySubmit($this->l(' Regenerate '),'submitSeoRegenerate'); $this->_html .= ''; $this->_endForm(array('id' => 'seoRegenerateForm')); } protected function displaySeoSearchForm($params) { $id_search = Tools::getValue('id_search'); $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexedForSEO($id_search, $this->_cookie->id_lang); $search = AdvancedSearchClass::getSearch($id_search,false,false); $criteria = false; if ($params['obj'] && $params['obj']->criteria) { $criteria = unserialize($params['obj']->criteria); } $this->_startForm(array('id' => 'seoSearchForm','obj' => $params['obj'],'params'=>$params)); if (!self::_isFilledArray($criterions_groups_indexed)) { $this->_showWarning($this->l('Before add SEO page, please add criteria to your search')); }else { $this->_displayTitle(($params['obj'] ? $this->l('Edit products page') : $this->l('Add products page'))); $this->_html .= '
'; foreach ($criterions_groups_indexed as $key => $criterions_group_indexed) { $this->_html .= '
    '; //Range group if ($criterions_group_indexed ['range'] == 1) { if ($criterions_group_indexed ['criterion_group_type'] == 'price') { $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $criterions_group_indexed ['range_sign'] = $default_currency->sign; $rangeSignLeft = $default_currency->getSign('left'); $rangeSignRight = $default_currency->getSign('right'); } else { $rangeSignLeft = ''; $rangeSignRight = ' '.$criterions_group_indexed['range_sign']; } $ranges = explode(',', $criterions_group_indexed ['range_interval']); $criterions = array(); foreach($ranges as $krange => $range) { $rangeUp = (isset($ranges[$krange+1]) ? $ranges[$krange+1]:''); $range1 = $range.'-'.$rangeUp; $range2 = ($rangeUp?$this->l('From'):$this->l('More than')).' '.$rangeSignLeft.$range.$rangeSignRight.($rangeUp?' '.$this->l('to').' '.$rangeSignLeft.$rangeUp.$rangeSignRight:''); $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($id_search,array($criterions_group_indexed ['id_criterion_group'])); $criterions [] = array('id_criterion' => $range1, 'value' => $range2); } if ($criterions && sizeof($criterions)) { foreach ($criterions as $row) { $this->_html .= '
  • '; $this->_html .= htmlentities($row ['value'], ENT_COMPAT, 'UTF-8'); $this->_html .= '
  • '; } } } //Price group elseif ($criterions_group_indexed ['criterion_group_type'] == 'price') { $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $price_range = AdvancedSearchClass::getPriceRangeForSearchBloc($search[0], $criterions_group_indexed ['id_criterion_group_linked'], (int)$default_currency->id, $this->getCurrentCustomerGroupId(), 0, $count_product = false, $selected_criterion = array(), $selected_criteria_groups_type = array()); $this->_html .= '
  • '; $this->_html .= $this->l('Choose your price range bellow : ') . '
    '; $this->_html .= '
    '; $this->_html .= '' . (int)$price_range [0] ['min_price'] . ' - ' . $default_currency->getSign('left') . (int)$price_range [0] ['max_price'] . $default_currency->getSign('right') . ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= '
  • '; } //Slider group elseif ($criterions_group_indexed ['display_type'] == 5) { $range = AdvancedSearchClass::getCriterionsRange($search[0], $criterions_group_indexed ['id_criterion_group'], $this->_cookie->id_lang,false,array(),array(),false,false,false, $criterions_group_indexed); $this->_html .= '
  • '; $this->_html .= $this->l('Choose your range bellow : ') . '
    '; $this->_html .= '
    '; $this->_html .= '' . (float)$range [0] ['min'] . ' - ' . (float)$range [0] ['max'] . ' (' . $criterions_group_indexed ['range_sign'] . ')'; $this->_html .= ''; $this->_html .= '
  • '; } //Classic group else { $criterions = AdvancedSearchClass::getCriterionsFromCriterionGroup($criterions_group_indexed ['criterion_group_type'], $criterions_group_indexed ['id_criterion_group_linked'], $criterions_group_indexed ['id_search'], $criterions_group_indexed ['sort_by'], $criterions_group_indexed ['sort_way'], $this->_cookie->id_lang); if ($criterions && sizeof($criterions)) { foreach ($criterions as $row) { $this->_html .= '
  • '; $this->_html .= htmlentities($row ['value'], ENT_COMPAT, 'UTF-8'); $this->_html .= '
  • '; } } } $this->_html .= '
'; } $this->_html .= '
'; $this->_showInfo($this->l('Add criteria of your choice to generate pre-defined searches.') . '
' . $this->l('Drag selected criteria above and drop them bellow.')); $this->_html .= '
'; $this->_html .= '
    '; if ($criteria && sizeof($criteria)) { foreach ($criteria as $criterion) { $info_criterion = explode('_', $criterion); $id_criterion_group = $info_criterion[0]; $id_criterion = $info_criterion[1]; $isPriceCriterion = false; $objAdvancedSearchCriterionGroupClass = new AdvancedSearchCriterionGroupClass($id_criterion_group, $id_search); if (preg_match('#-#', $id_criterion)) { $isPriceCriterion = true; $range = explode('-', $id_criterion); $currency = new Currency($params['obj']->id_currency); $min = $range [0]; $max = Tools::displayPrice($range[1], $currency); $citerion_value = $this->l('From') . ' ' . $min . ' ' . $this->l('to') . ' ' . $max; } else { $objAdvancedSearchCriterionClass = new AdvancedSearchCriterionClass($id_criterion, $id_search, $this->_cookie->id_lang); $citerion_value = (!$objAdvancedSearchCriterionClass->value && $objAdvancedSearchCriterionClass->single_value ? $objAdvancedSearchCriterionClass->single_value : trim($objAdvancedSearchCriterionClass->value)); } $this->_html .= '
  • ' . $citerion_value ; $this->_html .= ''; $this->_html .= '
  • '; } } else { $this->_html .= '
  • ' . $this->l('Add your criteria here') . '
  • '; } $this->_html .= '
'; $this->_pmClear(); $this->_html .= '
'; $this->_html .= ''; $this->_showInfo($this->l('Then, you can re-order them to automaticaly generate friendly strings and urls')); $this->_addButton(array('text'=> $this->l('Auto Fill'),'href'=>'javascript:void(0);','onclick'=>'fillSeoFields();','icon_class'=>'ui-icon ui-icon-refresh')); $this->_pmClear(); $this->_html .= ' ' . ($params['obj'] ? '

' : ''); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'meta_title', 'label' => $this->l('Meta Title'))); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'meta_description', 'label' => $this->l('Meta description'))); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'meta_keywords', 'label' => $this->l('Meta keywords'))); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'title', 'label' => $this->l('Title (H1)'))); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'seo_url', 'label' => $this->l('Friendly URL'),'onkeyup'=>'ASStr2url(this);','onchange'=>'ASStr2url(this);')); $this->_displayRichTextareaLang(array('obj' => $params['obj'], 'key' => 'description', 'label' => $this->l('Description'))); $crossLinksSelected = false; if ($params['obj']) $crossLinksSelected = $params['obj']->getCrossLinksOptionsSelected($this->_cookie->id_lang); $this->_displayAjaxSelectMultiple(array('selectedoptions' => $crossLinksSelected, 'key' => 'cross_links', 'label' => $this->l('Products pages to link under results'), 'remoteurl' => $this->_base_config_url.'&pm_load_function=displaySeoSearchOptions')); $this->_html .= '
'; $this->_displaySubmit($this->l(' Save '), 'submitSeoSearchForm'); } $this->_endForm(array('id' => 'seoSearchForm')); } protected function displayMassSeoSearchForm() { $id_search = Tools::getValue('id_search'); $search = AdvancedSearchClass::getSearch($id_search,false,false); $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexedForSEO($id_search, $this->_cookie->id_lang); $this->_startForm(array('id' => 'seoMassSearchForm')); $this->_displayTitle($this->l('Massive add of products pages')); $this->_showInfo($this->l('Select your criteria')); $this->_html .= '
'; foreach ($criterions_groups_indexed as $key => $criterions_group_indexed) { $this->_html .= '
'; $this->_html .= '   ' . $this->l('Check all') . '

'; $this->_html .= '
    '; //Range group if ($criterions_group_indexed ['range'] == 1) { if ($criterions_group_indexed ['criterion_group_type'] == 'price') { $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $criterions_group_indexed ['range_sign'] = $default_currency->sign; $rangeSignLeft = $default_currency->getSign('left'); $rangeSignRight = $default_currency->getSign('right'); } else { $rangeSignLeft = ''; $rangeSignRight = ' '.$criterions_group_indexed['range_sign']; } $ranges = explode(',', $criterions_group_indexed ['range_interval']); $criterions = array(); foreach($ranges as $krange => $range) { $rangeUp = (isset($ranges[$krange+1]) ? $ranges[$krange+1]:''); $range1 = $range.'-'.$rangeUp; $range2 = ($rangeUp?$this->l('From'):$this->l('More than')).' '.$rangeSignLeft.$range.$rangeSignRight.($rangeUp?' '.$this->l('to').' '.$rangeSignLeft.$rangeUp.$rangeSignRight:''); $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($id_search,array($criterions_group_indexed ['id_criterion_group'])); $criterions [] = array('id_criterion' => $range1, 'value' => $range2); } if ($criterions && sizeof($criterions)) { foreach ($criterions as $row) { $this->_html .= '
  • '; $this->_html .= '   '; $this->_html .= htmlentities($row ['value'], ENT_COMPAT, 'UTF-8'); $this->_html .= '
  • '; } } } elseif ($criterions_group_indexed ['criterion_group_type'] == 'price') { //Price group $default_currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $price_range = AdvancedSearchClass::getPriceRangeForSearchBloc($search[0], $criterions_group_indexed ['id_criterion_group_linked'], (int)$default_currency->id, $this->getCurrentCustomerGroupId(), 0, $count_product = false, $selected_criterion = array(), $selected_criteria_groups_type = array()); $this->_html .= '
  • '; $this->_html .= '   '; $this->_html .= $this->l('Choose your price range bellow : ') . '
    '; $this->_html .= '
    '; $this->_html .= '' . (int)$price_range [0] ['min_price'] . ' - ' . Tools::displayPrice((int)$price_range[0]['max_price'], $default_currency) . ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= '
  • '; } elseif ($criterions_group_indexed ['display_type'] == 5) { //Slider group $range = AdvancedSearchClass::getCriterionsRange($search[0], $criterions_group_indexed ['id_criterion_group'], $this->_cookie->id_lang,false,array(),array(),false,false,false, $criterions_group_indexed); $this->_html .= '
  • '; $this->_html .= '   '; $this->_html .= $this->l('Choose your range bellow : ') . '
    '; $this->_html .= '
    '; $this->_html .= '' . (float)$range [0] ['min'] . ' - ' . (float)$range [0] ['max'] . ' (' . $criterions_group_indexed ['range_sign'] . ')'; $this->_html .= ''; $this->_html .= '
  • '; } else { //Classic group $criterions = AdvancedSearchClass::getCriterionsFromCriterionGroup($criterions_group_indexed ['criterion_group_type'], $criterions_group_indexed ['id_criterion_group_linked'], $criterions_group_indexed ['id_search'], $criterions_group_indexed ['sort_by'], $criterions_group_indexed ['sort_way'], $this->_cookie->id_lang); if ($criterions && sizeof($criterions)) { foreach ($criterions as $row) { $this->_html .= '
  • '; $this->_html .= '   '; $this->_html .= htmlentities($row ['value'], ENT_COMPAT, 'UTF-8'); $this->_html .= '
  • '; } } } $this->_html .= '
'; } $this->_html .= '
'; $this->_showInfo($this->l('Reorder criteria groups for making human reading expressions')); $this->_html .= '
'; $this->_pmClear(); $this->_html .= ''; $this->_showInfo($this->l('Then, you can click bellow to automaticaly generate friendly strings and urls')); $this->_displaySubmit($this->l('Generate SEO pages'), 'submitMassSeoSearchForm'); $this->_pmClear(); $this->_endForm(array('id' => 'seoMassSearchForm')); } public function getContent() { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $this->_html .= '
'; $this->_displayTitle($this->displayName); if ($this -> _checkPermissions()) { if (Tools::getValue('makeUpdate')) $this->checkIfModuleIsUpdate(true); if (!$this->checkIfModuleIsUpdate(false)) { // 4.8 releases updates if (Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false) !== false && version_compare(Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false), '4.8', '>=') && version_compare(Configuration::get('PM_' . self::$_module_prefix . '_LAST_VERSION', false), '4.9.1', '<=')) { $this->_html .= '
'.(version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? '

' . $this->l('You have an old version of the module, this new version has a new approach for multishop features.') . '

' . $this->l('Because of a lot of constraints, you will not be able to associate one search engine to multiple shops anymore.') . '

' . $this->l('If it is your case at this time, we will only associate your search engine to one shop (from all the shops it was currently associated).') . '

' : '').'

' . $this->l('We really recommand you to re-index all the search engines after this update. Thank you for your comprehension.') . '


'; } $this->_html .= '

' . $this->l('We have detected that you installed a new version of the module on your shop') . '

' . $this->l('Please click here in order to finish the installation process') . '

'; $this->_loadCssJsLibraries(); } else { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Shop::getContext() != Shop::CONTEXT_SHOP) { $this->_loadCssJsLibraries(); $this->_html .= '
' . $this->l('You must select a specific shop in order to continue, you can\'t create/edit a search engine from the "all shop" or "group shop" context.'). '
'; } else { $this ->_preProcess(); $this->_loadCssJsLibraries(); $this->_postProcess(); $this->_showRating(true); parent::getContent(); $this->_html .= ' '; $advanced_searchs = AdvancedSearchClass::getSearchs($this->_cookie->id_lang, false); $this->_addButton(array('text'=> $this->l('Add a new search'),'href'=>$this->_base_config_url . '&pm_load_function=displaySearchForm&class=AdvancedSearchClass&pm_js_callback=closeDialogIframe','icon_class'=>'ui-icon ui-icon-circle-plus','class'=>'open_on_dialog_iframe','rel'=>'950_530_1')); $this->_html .= '

'; $this->_html .= '

'; $this->_html .= '
'; $this->_showInfo($this->l('You do not have added a search engine yet. Please click on the click "Add a new search" in order to start.')); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
'; $this->displayAdvancedConfig(); $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '
' . $this->l('Use this URL for CRON Tasks (reindexation)') . '
' . Tools::getHttpHost(true, true) . __PS_BASE_URI__ . 'modules/pm_advancedsearch4/cron.php?secure_key=' . (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Configuration::getGlobalValue('PM_AS4_SECURE_KEY') : Configuration::get('PM_AS4_SECURE_KEY')). '
'; $this->_html .= '
'; $this->_html .= '
'; $this->displayMaintenance(); $this->_html .= '
'; $this->_html .= '
'; } } }else { $this->_loadCssJsLibraries(); } $this->_displaySupport(); $this->_html .= '
'; return $this->_html; } protected function displaySearchForm($params) { if ($params['obj']->id) { $categoriesAssociation = AdvancedSearchClass::getCategoriesAssociation($params['obj']->id, $this->_cookie->id_lang); $cmsAssociation = AdvancedSearchClass::getCMSAssociation($params['obj']->id, $this->_cookie->id_lang); $manufacturersAssociation = AdvancedSearchClass::getManufacturersAssociation($params['obj']->id); $suppliersAssociation = AdvancedSearchClass::getSuppliersAssociation($params['obj']->id); $productsAssociation = AdvancedSearchClass::getProductsAssociation($params['obj']->id, $this->_cookie->id_lang); $specialPagesAssociation = AdvancedSearchClass::getSpecialPagesAssociation($params['obj']->id, true, $this->_cookie->id_lang); }else { $categoriesAssociation = array(); $cmsAssociation = array(); $manufacturersAssociation = array(); $suppliersAssociation = array(); $productsAssociation = array(); $specialPagesAssociation = array(); } $this->_startForm(array('id' => 'searchForm','obj' => $params['obj'],'params'=>$params)); $this->_displayTitle((isset($params['obj']) && Validate::isLoadedObject($params['obj']) ? $this->l('Edit Search') : $this->l('Add Search'))); /*Bloc Option interne*/ $this->_startFieldset(false, false, false); $this->_displayInputText(array('obj' => $params['obj'],'key' => 'internal_name', 'label' => $this->l('Internal name') )); $this->_endFieldset(); /*FIN Bloc Option interne*/ /*Bloc Affichage*/ $this->_startFieldset($this->l('Display'), $this->_path . 'img/eye.png', false); $this->_displayInputTextLang(array('obj' => $params['obj'], 'key' => 'title', 'label' => $this->l('Public title'))); $this->_displayRichTextareaLang(array('obj' => $params['obj'], 'key' => 'description', 'label' => $this->l('Description'))); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'activestatus', 'key_db' => 'active', 'label' => $this->l('Active'))); $hooks = array(); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $valid_hooks = AdvancedSearchClass::$_valid_hooks_1_5; else $valid_hooks = AdvancedSearchClass::$_valid_hooks; foreach ($valid_hooks as $k => $hook_name) { $id_hook = self::_getHookIdByName($hook_name); if (!$id_hook) continue; $hooks[$id_hook] = $hook_name; } $hooks[-1] = $this->l('Custom (advanced user only)'); $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Transplant to hook'), 'key' => 'id_hook', 'options' => $hooks, 'defaultvalue'=>$this->l('Do not show'), 'onchange' => 'updateHookOptions($jqPm(this));' ); $this->_displaySelect($configOptions); $this->_html .= ''; $this->_html .= ''; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= '

'.$this->l('Set here the ID of your center column. (If you are not sure do not change this value)').'

'; $this->_displayInputText(array('obj' => $params['obj'],'key' => 'search_results_selector', 'label' => $this->l('Search results area'),'defaultvalue'=>'#center_column' )); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'unique_search', 'key_db' => 'unique_search', 'label' => $this->l('Unique search'),'tips'=>$this->l('Only search to be displayed. If several searches have the unique option activated, they will all be displayed on your page.'))); $this->_html .= '
'; $this->_html .= ''; $this->_endFieldset(); /*FIN Bloc Affichage*/ /*Bloc Comportement*/ $this->_startFieldset($this->l('Behaviour'), $this->_path . 'img/clapperboard.png', true); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'keep_category_information', 'key_db' => 'keep_category_information', 'label' => $this->l('Keep category information while searching'))); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'display_nb_result_on_blc', 'key_db' => 'display_nb_result_on_blc', 'label' => $this->l('Display number of results on search block'))); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'display_nb_result_criterion', 'key_db' => 'display_nb_result_criterion', 'label' => $this->l('Display number of results per criteria'))); $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Display a remind of selection'), 'key' => 'remind_selection', 'options' => $this->options_remind_selection, 'size' => '400px' ); $this->_displaySelect($configOptions); $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Method to display hidden criteria'), 'key' => 'show_hide_crit_method', 'options' => $this->options_show_hide_crit_method ); $this->_displaySelect($configOptions); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'step_search', 'key_db' => 'step_search', 'label' => $this->l('Search by steps'), 'onclick'=>'toogleDisplayCriteriaOptions(); showRelatedOptions($jqPm(this))')); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'collapsable_criterias', 'key_db' => 'collapsable_criterias', 'label' => $this->l('Allow criterias to be collapsed'))); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'reset_group', 'key_db' => 'reset_group', 'label' => $this->l('Display an option to reset user choices'),'defaultvalue'=>true)); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'filter_by_emplacement', 'key_db' => 'filter_by_emplacement', 'label' => $this->l('Show available criteria only for displayed products'),'defaultvalue'=>true, 'onclick'=>'toogleDisplayCategoryRootOption()')); $categorySelect = array(0 => $this->l('-- User-context category --')); foreach (Category::getCategories($this->_cookie->id_lang) as $shopCategory) { foreach ($shopCategory as $idCategory=>$categoryInformations) { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=') && Configuration::get('PS_ROOT_CATEGORY') == $idCategory) continue; $categorySelect[$idCategory] = str_repeat('– ', (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? $categoryInformations['infos']['level_depth'] - 1 : $categoryInformations['infos']['level_depth'])) . $categoryInformations['infos']['name']; } } $this->_html .= '
'; $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Set the root category for your search (default is user-context category)'), 'key' => 'id_category_root', 'options' => $categorySelect, 'size' => '500px' ); $this->_displaySelect($configOptions); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'recursing_indexing', 'key_db' => 'recursing_indexing', 'label' => $this->l('Recursive indexing of categories'),'defaultvalue'=>true)); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'share', 'key_db' => 'share', 'label' => $this->l('Display share block under search results'),'defaultvalue'=>true)); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'search_on_stock', 'key_db' => 'search_on_stock', 'label' => $this->l('Search only products in stock'),'defaultvalue'=>false)); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'display_empty_criteria', 'key_db' => 'display_empty_criteria', 'label' => $this->l('Display empty criteria'),'defaultvalue'=>false,'onclick'=>'toogleDisplayCriteriaOptions()')); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'hide_empty_crit_group', 'key_db' => 'hide_empty_crit_group', 'label' => $this->l('Hide empty criteria groups'),'defaultvalue'=>false)); $this->_html .= '
'; $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'save_selection', 'key_db' => 'save_selection', 'label' => $this->l('Save selection during navigation'), 'onclick'=>'toogleDisplayCriteriaOptions()')); $this->_html .= '
'; $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Submit search method'), 'key' => 'search_method', 'options' => $this->options_launch_search_method, 'onchange' => 'display_search_method_options();' ); $this->_displaySelect($configOptions); $this->_html .= ''; $this->_html .= '
search_method == 2)) ? '' : ' style="display:none"') . '>'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'dynamic_criterion', 'key_db' => 'dynamic_criterion', 'label' => $this->l('Dynamic criteria'),'defaultvalue'=>true)); $this->_html .= '
'; $this->_html .= '
search_method == 1)) ? '' : ' style="display:none"') . '>'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'redirect_one_product', 'key_db' => 'redirect_one_product', 'label' => $this->l('Redirect to product sheet if only one product found'),'defaultvalue'=>true)); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'priority_on_combination_image', 'key_db' => 'priority_on_combination_image', 'label' => $this->l('Display combination image on priority'),'defaultvalue'=>true)); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'add_anchor_to_url', 'key_db' => 'add_anchor_to_url', 'label' => $this->l('Pre-select product\'s combination for product page'), 'defaultvalue'=> false)); else $this->_html .= ''; $this->_displayInputText(array('obj' => $params['obj'],'key' => 'products_per_page', 'label' => $this->l('Number of products per page'), 'defaultvalue'=>Configuration::get('PS_PRODUCTS_PER_PAGE'))); $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Default order by'), 'key' => 'products_order_by', 'options' => $this->options_defaut_order_by, 'size' => '500px' ); $this->_displaySelect($configOptions); $configOptions = array( 'obj' => $params['obj'], 'label' => $this->l('Default order way'), 'key' => 'products_order_way', 'options' => $this->options_defaut_order_way ); $this->_displaySelect($configOptions); $this->_displayInputActive(array('obj' => $params['obj'], 'key_active' => 'scrolltop_active', 'key_db' => 'scrolltop_active', 'label' => $this->l('Activate auto scrolling effect'),'defaultvalue'=>true)); $this->_endFieldset(); /*FIN Bloc Comportement*/ /*Bloc Apparence*/ $this->_startFieldset($this->l('Appearance'), $this->_path . 'img/color-swatch.png', true); $this->_html .= ''; $this->_displayInputColor(array('obj' => $params['obj'], 'key' => 'color_group_title', 'label' => $this->l('Criteria group color title'),'defaultvalue'=>'#333333')); $this->_displayInputSlider(array('obj' => $params['obj'], 'key' => 'font_size_group_title', 'label' => $this->l('Criteria group title font size'), 'minvalue' => '8', 'maxvalue' => '30', 'defaultvalue' => '12', 'suffix' => 'px')); $this->_endFieldset(); /*FIN Bloc Apparence*/ /*Bloc affichage sur zone du site*/ $this-> _startFieldset($this->l('Associations')); //Champs radio oui/non pour $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_cat', 'key_db' => 'bool_cat', 'label' => $this->l('Apply this rule to some categories'), 'defaultvalue' => ($categoriesAssociation && self::_isFilledArray($categoriesAssociation) ? 1 : 0), 'onclick' => 'display_cat_picker();' )); // Choix des categories $this -> _html .= '
'; //multiselect table $this->_displayCategoryTree(array( 'label' => $this->l('Categories'), 'input_name' => 'categories_association', 'selected_cat' => ($categoriesAssociation && self::_isFilledArray($categoriesAssociation) ? $categoriesAssociation : array(0)), 'category_root_id' => (version_compare(_PS_VERSION_, '1.5.0.0', '>=') ? Category::getRootCategory()->id : 1) )); $this -> _html .= '
'; //Champs radio oui/non pour l'activation $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_prod', 'key_db' => 'bool_prod', 'label' => $this->l('Apply this rule to some products'), 'defaultvalue' => ($productsAssociation && self::_isFilledArray($productsAssociation) ? 1 : 0), 'onclick' => 'display_prod_picker();' )); // Choix des categories $this -> _html .= '
'; //multiselect table $this -> _displayAjaxSelectMultiple(array( 'selectedoptions' => ($productsAssociation && self::_isFilledArray($productsAssociation) ?$productsAssociation:false), //retourne le tableau associatif de ce qu'on veut afficher dans le tableau (à gauche) 'key' => 'products_association', 'label' => $this->l('Products'), 'remoteurl' => $this -> _base_config_url . '&getItem=1&itemType=product',//postprocess 'limit' => 50, 'limitincrement' => 20, 'remoteparams' => false, // New parameters 'idcolumn' => 'id_product', 'namecolumn' => 'name', 'triggeronliclick' => true, 'displaymore' => true, )); $this -> _html .= '
'; //Champs radio oui/non pour l'activation $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_manu', 'key_db' => 'bool_manu', 'label' => $this->l('Apply this rule to some manufacturers'), 'defaultvalue' => ($manufacturersAssociation && self::_isFilledArray($manufacturersAssociation) ? 1 : 0), 'onclick' => 'display_manu_picker();' )); // Choix des categories $this -> _html .= '
'; //multiselect table $this -> _displayAjaxSelectMultiple(array( 'selectedoptions' => ($manufacturersAssociation && self::_isFilledArray($manufacturersAssociation) ?$manufacturersAssociation:false), //retourne le tableau associatif de ce qu'on veut afficher dans le tableau (à gauche) 'key' => 'manufacturers_association', 'label' => $this->l('Manufacturers'), 'remoteurl' => $this -> _base_config_url . '&getItem=1&itemType=manufacturer',//postprocess 'limit' => 50, 'limitincrement' => 20, 'remoteparams' => false, // New parameters 'idcolumn' => 'id_manufacturer', 'namecolumn' => 'name', 'triggeronliclick' => true, 'displaymore' => true, )); $this -> _html .= '
'; //Champs radio oui/non pour l'activation $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_supp', 'key_db' => 'bool_supp', 'label' => $this->l('Apply this rule to some suppliers'), 'defaultvalue' => ($suppliersAssociation && self::_isFilledArray($suppliersAssociation) ? true : false), 'onclick' => 'display_supp_picker();' )); // Choix des categories $this -> _html .= '
'; //multiselect table $this -> _displayAjaxSelectMultiple(array( 'selectedoptions' => ($suppliersAssociation && self::_isFilledArray($suppliersAssociation) ?$suppliersAssociation:false), //retourne le tableau associatif de ce qu'on veut afficher dans le tableau (à gauche) 'key' => 'suppliers_association', 'label' => $this->l('Suppliers'), 'remoteurl' => $this -> _base_config_url . '&getItem=1&itemType=supplier',//postprocess 'limit' => 50, 'limitincrement' => 20, 'remoteparams' => false, // New parameters 'idcolumn' => 'id_supplier', 'namecolumn' => 'name', 'triggeronliclick' => true, 'displaymore' => true, )); $this -> _html .= '
'; //Champs radio oui/non pour l'activation $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_cms', 'key_db' => 'bool_cms', 'label' => $this->l('Apply this rule to some CMS pages'), 'defaultvalue' => (self::_isFilledArray($cmsAssociation) ?true:false), 'onclick' => 'display_cms_picker();' )); // Choix des categories $this -> _html .= '
'; //multiselect table $this -> _displayAjaxSelectMultiple(array( 'selectedoptions' => ($cmsAssociation && self::_isFilledArray($cmsAssociation) ?$cmsAssociation:false), //retourne le tableau associatif de ce qu'on veut afficher dans le tableau (à gauche) 'key' => 'cms_association', 'label' => $this->l('CMS Pages'), 'remoteurl' => $this -> _base_config_url . '&getItem=1&itemType=cms',//postprocess 'limit' => 50, 'limitincrement' => 20, 'remoteparams' => false, // New parameters 'idcolumn' => 'id_cms', 'namecolumn' => 'meta_title', 'triggeronliclick' => true, 'displaymore' => true, )); $this -> _html .= '
'; //Champs radio oui/non pour l'activation $this -> _displayInputActive(array( 'obj' => $params['obj'], 'key_active' => 'bool_spe', 'key_db' => 'bool_spe', 'label' => $this->l('Apply this rule to some special pages'), 'defaultvalue' => ($specialPagesAssociation && self::_isFilledArray($specialPagesAssociation) ?true:false), 'onclick' => 'display_spe_picker();' )); $this->_html .='
'; // Choix des controllers $this -> _html .= '
'; $this -> _displayAjaxSelectMultiple(array( 'selectedoptions' => ($specialPagesAssociation && self::_isFilledArray($specialPagesAssociation) ?$specialPagesAssociation:false), //retourne le tableau associatif de ce qu'on veut afficher dans le tableau (à gauche) 'key' => 'special_pages_association', 'label' => $this->l('Select the controller where you want the search engine to be shown'), 'remoteurl' => $this -> _base_config_url . '&getItem=1&itemType=controller',//postprocess 'limit' => 50, 'limitincrement' => 20, 'remoteparams' => false, 'idcolumn' => 'page', 'namecolumn' => 'title', 'triggeronliclick' => true, 'displaymore' => true, )); $this -> _html .= '
'; $this -> _html .= '
'; $this->_html .=' '; $this->_endFieldset(); /*FIN Bloc affichage sur zone du site*/ $this->_displaySubmit($this->l(' Save '), 'submitSearch'); $this->_html .= '

'; $this->_html .= ''; $this->_endForm(array('id' => 'searchForm')); return; } private function _lWithoutCache($string, $specific = false) { global $_MODULES, $_MODULE; $_MODULES = array(); $id_lang = (! isset($this->_cookie) or ! is_object($this->_cookie)) ? intval(Configuration::get('PS_LANG_DEFAULT')) : intval($this->_cookie->id_lang); $iso_lang = Language::getIsoById($id_lang); if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { $file = _PS_MODULE_DIR_ . $this->name . '/' . $iso_lang . '.php'; if (file_exists($file) and include($file)) $_MODULES = ! empty($_MODULES) ? array_merge($_MODULES, $_MODULE) : $_MODULE; } else { $filesByPriority = array( _PS_THEME_DIR_.'modules/'.$this->name.'/translations/'.$iso_lang.'.php', _PS_THEME_DIR_.'modules/'.$this->name.'/'.$iso_lang.'.php', _PS_MODULE_DIR_.$this->name.'/translations/'.$iso_lang.'.php', _PS_MODULE_DIR_.$this->name.'/'.$iso_lang.'.php' ); foreach ($filesByPriority as $file) if (Tools::file_exists_cache($file) && include($file)) $_MODULES = !empty($_MODULES) ? $_MODULES + $_MODULE : $_MODULE; } if (!is_array($_MODULES)) return (str_replace('"', '"', $string)); $source = Tools::strtolower($specific ? $specific : get_class($this)); $string2 = str_replace('\'', '\\\'', $string); $currentKey = '<{' . $this->name . '}' . _THEME_NAME_ . '>' . $source . '_' . md5($string2); $defaultKey = '<{' . $this->name . '}prestashop>' . $source . '_' . md5($string2); if (key_exists($currentKey, $_MODULES)) $ret = stripslashes($_MODULES [$currentKey]); elseif (key_exists($defaultKey, $_MODULES)) $ret = stripslashes($_MODULES [$defaultKey]); else $ret = $string; return str_replace('"', '"', $ret); } public function translateMultiple($type, $category_level_depth = false) { $defaultIdLang = $this->_cookie->id_lang; $return = array(); // Do not delete this lines : /* $this->l('Manufacturer'); $this->l('Supplier'); $this->l('Categories level'); $this->l('Categories'); $this->l('Price'); $this->l('offers a selection of'); $this->l('Between'); $this->l('and'); $this->l('From'); $this->l('to'); $this->l('On sale'); $this->l('In stock'); $this->l('Available for order'); $this->l('Online only'); $this->l('Weight'); $this->l('Width'); $this->l('Height'); $this->l('Depth'); $this->l('Condition'); $this->l('New'); $this->l('Used'); $this->l('Refurbished'); $this->l('Yes'); $this->l('No'); */ foreach ($this->_languages as $language) { $this->_cookie->id_lang = $language['id_lang']; switch ($type) { case 'manufacturer' : $return[$language['id_lang']] = $this->_lWithoutCache('Manufacturer'); break; case 'supplier' : $return[$language['id_lang']] = $this->_lWithoutCache('Supplier'); break; case 'categories' : if ($category_level_depth) $return[$language['id_lang']] = $this->_lWithoutCache('Categories level').' '.$category_level_depth; else $return[$language['id_lang']] = $this->_lWithoutCache('Categories'); break; case 'price' : $return[$language['id_lang']] = $this->_lWithoutCache('Price'); break; case 'offers_selection' : $return[$language['id_lang']] = $this->_lWithoutCache('offers a selection of'); break; case 'between' : $return[$language['id_lang']] = $this->_lWithoutCache('Between'); break; case 'and' : break; case 'from' : $return[$language['id_lang']] = $this->_lWithoutCache('From'); break; case 'to' : $return[$language['id_lang']] = $this->_lWithoutCache('to'); break; case 'on_sale' : $return[$language['id_lang']] = $this->_lWithoutCache('On sale'); break; case 'stock' : $return[$language['id_lang']] = $this->_lWithoutCache('In stock'); break; case 'available_for_order' : $return[$language['id_lang']] = $this->_lWithoutCache('Available for order'); break; case 'online_only' : $return[$language['id_lang']] = $this->_lWithoutCache('Online only'); break; case 'weight' : $return[$language['id_lang']] = $this->_lWithoutCache('Weight'); break; case 'width' : $return[$language['id_lang']] = $this->_lWithoutCache('Width'); break; case 'height' : $return[$language['id_lang']] = $this->_lWithoutCache('Height'); break; case 'depth' : $return[$language['id_lang']] = $this->_lWithoutCache('Depth'); break; case 'condition' : $return[$language['id_lang']] = $this->_lWithoutCache('Condition'); break; case 'new' : $return[$language['id_lang']] = $this->_lWithoutCache('New'); break; case 'used' : $return[$language['id_lang']] = $this->_lWithoutCache('Used'); break; case 'refurbished' : $return[$language['id_lang']] = $this->_lWithoutCache('Refurbished'); break; case 'yes' : $return[$language['id_lang']] = $this->_lWithoutCache('Yes'); break; case 'no' : $return[$language['id_lang']] = $this->_lWithoutCache('No'); break; } } $this->_cookie->id_lang = $defaultIdLang; return $return; } private function _getCriteriaFromEmplacement($id_search, $id_category_root = false) { if ($id_category_root !== false && is_numeric($id_category_root) && (int)$id_category_root > 0) $criterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('category', (int)$id_category_root, (int)$id_search); else if ($id_category = (Tools::getIsset('id_category') ? (int)Tools::getValue('id_category') : (int)Tools::getValue('id_category_search'))) $criterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('category', $id_category, (int)$id_search); elseif ($id_manufacturer = (Tools::getIsset('id_manufacturer') ? (int)Tools::getValue('id_manufacturer') : (int)Tools::getValue('id_manufacturer_search'))) $criterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('manufacturer', $id_manufacturer, (int)$id_search); elseif ($id_supplier = (Tools::getIsset('id_supplier') ? (int)Tools::getValue('id_supplier') : (int)Tools::getValue('id_supplier_search'))) $criterion = AdvancedSearchClass::getCriterionsWithIdGroupFromIdLinked('supplier', $id_supplier, (int)$id_search); return (isset($criterion) && $criterion ? $criterion : array()); } private function _addToFBLog($nom_etape) { if ($this->bench) { if (!$this->bench_start) $this->bench_start = microtime(true); if ($this->bench_step) $time_elapsed_step = microtime(true) - $this->bench_step; $this->bench_step = microtime(true); $time_elapsed_start = $this->bench_step - $this->bench_start; if (is_array($nom_etape) || is_object($nom_etape)) { $this->bench_output [] = $nom_etape; $this->bench_output [] = '=> Temps écoulé depuis départ ' . $time_elapsed_start . ' secondes' . (isset($time_elapsed_step) ? ' - Temps écoulé depuis step ' . $time_elapsed_step : ''); } else { $this->bench_output [] = $nom_etape . ' : Temps écoulé depuis départ ' . $time_elapsed_start . ' secondes' . (isset($time_elapsed_step) ? ' - Temps écoulé depuis step ' . $time_elapsed_step : ''); } } } private function _assignProductSort($orderByDefault, $orderWayDefault) { $stock_management = (int)(Configuration::get('PS_STOCK_MANAGEMENT')) ? true : false; // no display quantity order if stock management disabled $orderBy = Tools::strtolower(Tools::getValue('orderby', $this->orderByValues [(int)($orderByDefault)])); $orderWay = Tools::strtolower(Tools::getValue('orderway', $this->orderWayValues [(int)($orderWayDefault)])); if (!in_array($orderBy, $this->orderByValues)) $orderBy = $this->orderByValues[0]; if (!in_array($orderWay, $this->orderWayValues)) $orderWay = $this->orderWayValues[0]; $this->_smarty->assign(array( 'orderby' => $orderBy, 'orderway' => $orderWay, 'orderbydefault' => $this->orderByValues[(int)($orderByDefault)], 'orderwayposition' => $this->orderWayValues[(int)($orderWayDefault)], // Deprecated: orderwayposition 'orderwaydefault' => $this->orderWayValues[(int)($orderWayDefault)], 'stock_management' => (int)$stock_management )); } private function _assignPagination($products_per_page, $nbProducts = 10) { $nArray = array_unique(array((int)$products_per_page, 20, 40, 80)); asort($nArray); $this->n = abs((int)(Tools::getValue('n', ((isset($this->_cookie->nb_item_per_page) && $this->_cookie->nb_item_per_page >= 10) ? $this->_cookie->nb_item_per_page : (int)$products_per_page)))); $this->p = abs((int)(Tools::getValue('p', 1))); $range = 2; /* how many pages around page selected */ if ($this->p < 0) $this->p = 0; if (isset($this->_cookie->nb_item_per_page) && $this->n != $this->_cookie->nb_item_per_page && in_array($this->n, $nArray)) $this->_cookie->nb_item_per_page = $this->n; if ($this->p > ($nbProducts / $this->n)) $this->p = ceil($nbProducts / $this->n); $pages_nb = ceil($nbProducts / (int)$this->n); $start = (int)($this->p - $range); if ($start < 1) $start = 1; $stop = (int)($this->p + $range); if ($stop > $pages_nb) $stop = (int)$pages_nb; $this->_smarty->assign('nb_products', (int)$nbProducts); $pagination_infos = array( 'pages_nb' => (int)$pages_nb, 'p' => (int)$this->p, 'n' => (int)$this->n, 'nArray' => $nArray, 'range' => (int)$range, 'start' => (int)$start, 'stop' => (int)$stop, 'products_per_page' => (int)$products_per_page ); $this->_smarty->assign($pagination_infos); } public function resetSearchSelection($id_search) { $this->_cookie->as4_reset_selection = true; } //Save criterion and price_range for recover on productlinknc module private function saveSearchSelection4ProductLinkNC($id_search, $selected_criterion, $search_on_stock, $default_order_by, $default_order_way) { $this->_cookie->as4_id_search_nc = $id_search; $this->_cookie->as4_on_stock_nc = $search_on_stock; if (Tools::getValue('orderway') && in_array(Tools::strtolower(Tools::getValue('orderway')), $this->orderWayValues)) $this->_cookie->as4_orderway_nc = Tools::strtolower(Tools::getValue('orderway')); elseif (!isset($this->_cookie->as4_orderway_nc) || !$this->_cookie->as4_orderway_nc) $this->_cookie->as4_orderway_nc = $this->orderWayValues [$default_order_way]; else $this->_cookie->as4_orderway_nc = false; if (Tools::getValue('orderby') && in_array(Tools::strtolower(Tools::getValue('orderby')), $this->orderByValues)) $this->_cookie->as4_orderby_nc = Tools::strtolower(Tools::getValue('orderby')); elseif (!isset($this->_cookie->as4_orderby_nc) || !$this->_cookie->as4_orderby_nc) $this->_cookie->as4_orderby_nc = $this->orderByValues [$default_order_by]; else $this->_cookie->as4_orderby_nc = false; if ($selected_criterion && is_array($selected_criterion) && sizeof($selected_criterion)) $this->_cookie->as4_selected_criterion_nc = serialize($selected_criterion); else $this->_cookie->as4_selected_criterion_nc = false; } private function clearSearchSelection4ProductLinkNC() { unset($this->_cookie->as4_id_search_nc, $this->_cookie->as4_on_stock_nc, $this->_cookie->as4_selected_criterion_nc, $this->_cookie->as_price_range_nc); } private function saveSearchSelection(&$row, &$selectedCriterions) { // 2 keys, one global, one depending on the context $globalKey = implode('-', array((int)$row['id_search'])); $contextKey = implode('-', array( (int)$row['id_search'], (int)$row['step_search'], (int)$row['search_method'], (Tools::getIsset('id_category') ? (int)Tools::getValue('id_category') : (int)Tools::getValue('id_category_search')), (Tools::getIsset('id_manufacturer') ? (int)Tools::getValue('id_manufacturer') : (int)Tools::getValue('id_manufacturer_search')), (Tools::getIsset('id_supplier') ? (int)Tools::getValue('id_supplier') : (int)Tools::getValue('id_supplier_search')), )); // Cookie keys (global & context) $cookieGlobalIndexKey = 'as4SC_' .$globalKey; $cookieContextIndexKey = 'as4SC_' .$contextKey; $selectedCriterionsGlobal = $selectedCriterionsCurrent = $selectedCriterions; // Retrieve context selected criterions (will always override selected criterions) $preSelectedCriterions = $this->_getCriteriaFromEmplacement($row['id_search'], $row['id_category_root']); // We only save selected criterions if (self::_isFilledArray($selectedCriterionsGlobal)) { foreach ($selectedCriterionsGlobal as $idCriterionGroup=>$criterions) { // Remove preSelected (_getCriteriaFromEmplacement) or empty criterions if (isset($preSelectedCriterions[$idCriterionGroup]) || (self::_isFilledArray($criterions) && isset($criterions[0]) && $criterions[0] == '')) unset($selectedCriterionsGlobal[$idCriterionGroup]); } } else { $selectedCriterionsGlobal = $preSelectedCriterions; } if (self::_isFilledArray($selectedCriterionsCurrent)) { foreach ($selectedCriterionsCurrent as $idCriterionGroup=>$criterions) { // Remove preSelected (_getCriteriaFromEmplacement) or empty criterions if (isset($preSelectedCriterions[$idCriterionGroup]) || (self::_isFilledArray($criterions) && isset($criterions[0]) && $criterions[0] == '')) unset($selectedCriterionsCurrent[$idCriterionGroup]); } } else { $selectedCriterionsCurrent = $preSelectedCriterions; } // Get saved criterions $cookieSelectedCriterionsCurrent = $cookieSelectedCriterionsGlobal = array(); if (isset($this->_cookie->{$cookieContextIndexKey})) $cookieSelectedCriterionsCurrent = unserialize($this->_cookie->{$cookieContextIndexKey}); if (isset($this->_cookie->{$cookieGlobalIndexKey})) $cookieSelectedCriterionsGlobal = unserialize($this->_cookie->{$cookieGlobalIndexKey}); if (Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && isset($cookieSelectedCriterionsGlobal[(int)Tools::getValue('reset_group')])) unset($cookieSelectedCriterionsGlobal[(int)Tools::getValue('reset_group')]); if (Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && isset($cookieSelectedCriterionsCurrent[(int)Tools::getValue('reset_group')])) unset($cookieSelectedCriterionsCurrent[(int)Tools::getValue('reset_group')]); if ($selectedCriterionsGlobal == false && self::_isFilledArray($cookieSelectedCriterionsGlobal)) { $selectedCriterionsGlobal = $cookieSelectedCriterionsGlobal; } if ($selectedCriterionsCurrent == false && self::_isFilledArray($cookieSelectedCriterionsCurrent)) { $selectedCriterionsCurrent = $cookieSelectedCriterionsCurrent; } // Override current criterions if (self::_isFilledArray($selectedCriterions)) { foreach ($selectedCriterions as $idCriterionGroup=>$criterions) { if (!isset($preSelectedCriterions[$idCriterionGroup])) { $selectedCriterionsGlobal[$idCriterionGroup] = $criterions; } $selectedCriterionsCurrent[$idCriterionGroup] = $criterions; } } else if (self::_isFilledArray($preSelectedCriterions) && !self::_isFilledArray($selectedCriterionsCurrent)) { $selectedCriterionsCurrent = $preSelectedCriterions; } // Put overrided values from cookies // Current if (self::_isFilledArray($selectedCriterionsCurrent) && self::_isFilledArray($cookieSelectedCriterionsCurrent)) { foreach ($cookieSelectedCriterionsCurrent as $idCriterionGroup=>$criterions) { // Update new value from current selectedCriterions (ajaxMode, new selection) if (!Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && is_array($selectedCriterions) && isset($selectedCriterions[$idCriterionGroup])) { $selectedCriterionsCurrent[$idCriterionGroup] = $selectedCriterions[$idCriterionGroup]; } else if (Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && isset($selectedCriterionsCurrent[(int)Tools::getValue('reset_group')])) { unset($selectedCriterionsCurrent[(int)Tools::getValue('reset_group')]); } else { $selectedCriterionsCurrent[$idCriterionGroup] = $criterions; } } } // Global if (self::_isFilledArray($selectedCriterionsGlobal) && self::_isFilledArray($cookieSelectedCriterionsGlobal)) { foreach ($cookieSelectedCriterionsGlobal as $idCriterionGroup=>$criterions) { // Update new value from current selectedCriterions (ajaxMode, new selection) if (!Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && is_array($selectedCriterions) && isset($selectedCriterions[$idCriterionGroup])) { $selectedCriterionsGlobal[$idCriterionGroup] = $selectedCriterions[$idCriterionGroup]; } else if (Tools::getValue('reset_group') && Tools::getValue('ajaxMode') && isset($selectedCriterionsGlobal[(int)Tools::getValue('reset_group')])) { unset($selectedCriterionsGlobal[(int)Tools::getValue('reset_group')]); } else if (AdvancedSearchCriterionGroupClass::getCriterionGroupType($row['id_search'], $idCriterionGroup) == 'category') { unset($selectedCriterionsGlobal[$idCriterionGroup]); } else { $selectedCriterionsGlobal[$idCriterionGroup] = $criterions; } } } // Override predefined criterions if (self::_isFilledArray($preSelectedCriterions)) { foreach ($preSelectedCriterions as $idCriterionGroup=>$criterions) { if ($row['search_method'] != 2 && self::_isFilledArray($selectedCriterionsGlobal) && isset($selectedCriterionsGlobal[$idCriterionGroup])) unset($selectedCriterionsGlobal[$idCriterionGroup]); if (self::_isFilledArray($selectedCriterionsCurrent)) $selectedCriterionsCurrent[$idCriterionGroup] = $criterions; } } // Auto-Submit if search method is "instant search" and step search is on if ((self::_isFilledArray($selectedCriterionsCurrent) || self::_isFilledArray($selectedCriterionsGlobal)) && $row['search_method'] == 1 && $row['step_search'] == 1) { $row['save_selection_active'] = 1; } // Clear saved criterions (global & context) if (isset($this->_cookie->as4_reset_selection)) { $selectedCriterions = array(); unset($this->_cookie->{$cookieGlobalIndexKey}); unset($this->_cookie->{$cookieContextIndexKey}); unset($this->_cookie->as4_reset_selection); return; } elseif ($row['save_selection']) { $cookieSelectedCriterionsCurrent = array(); if (self::_isFilledArray($selectedCriterionsCurrent)) { foreach ($selectedCriterionsCurrent as $idCriterionGroup=>$criterions) { if (isset($preSelectedCriterions[$idCriterionGroup]) || (self::_isFilledArray($criterions) && isset($criterions[0]) && $criterions[0] != '')) $cookieSelectedCriterionsCurrent[$idCriterionGroup] = $criterions; } } $cookieSelectedCriterionsGlobal = array(); if (self::_isFilledArray($selectedCriterionsGlobal)) { foreach ($selectedCriterionsGlobal as $idCriterionGroup=>$criterions) { if (!isset($preSelectedCriterions[$idCriterionGroup]) && (self::_isFilledArray($criterions) && isset($criterions[0]) && $criterions[0] != '')) $cookieSelectedCriterionsGlobal[$idCriterionGroup] = $criterions; } } // We have to save the current selection if (self::_isFilledArray($selectedCriterionsCurrent)) { if (Tools::getValue('ajaxMode')) foreach (array_keys($selectedCriterionsCurrent) as $idCriterionGroup) { if (!isset($selectedCriterions[$idCriterionGroup])) { unset($selectedCriterionsCurrent[$idCriterionGroup]); unset($cookieSelectedCriterionsCurrent[$idCriterionGroup]); } } $this->_cookie->{$cookieContextIndexKey} = serialize($cookieSelectedCriterionsCurrent); } // We have to save the global selection if (self::_isFilledArray($selectedCriterionsGlobal)) { if (Tools::getValue('ajaxMode')) foreach (array_keys($cookieSelectedCriterionsGlobal) as $idCriterionGroup) { if (!isset($selectedCriterions[$idCriterionGroup])) { unset($selectedCriterionsGlobal[$idCriterionGroup]); unset($cookieSelectedCriterionsGlobal[$idCriterionGroup]); } } $this->_cookie->{$cookieGlobalIndexKey} = serialize($cookieSelectedCriterionsGlobal); } // Step by step search if ($row['step_search'] == 1) { // Export new $selectedCriterions value, depending on context, or global selected criterions if (self::_isFilledArray($selectedCriterionsGlobal)) foreach ($selectedCriterionsGlobal as $idCriterionGroup => $criterions) $selectedCriterions[$idCriterionGroup] = $criterions; if (self::_isFilledArray($selectedCriterionsCurrent)) foreach ($selectedCriterionsCurrent as $idCriterionGroup => $criterions) if (!isset($selectedCriterions[$idCriterionGroup]) && Tools::getValue('ajaxMode')) $selectedCriterions[$idCriterionGroup] = $criterions; else if (!Tools::getValue('ajaxMode')) $selectedCriterions[$idCriterionGroup] = $criterions; } else { if ($row['search_method'] == 2) { // Search by submit button if (self::_isFilledArray($selectedCriterionsGlobal)) foreach ($selectedCriterionsGlobal as $idCriterionGroup => $criterions) $selectedCriterions[$idCriterionGroup] = $criterions; if (self::_isFilledArray($selectedCriterionsCurrent)) foreach ($selectedCriterionsCurrent as $idCriterionGroup => $criterions) if (!isset($selectedCriterions[$idCriterionGroup]) && Tools::getValue('ajaxMode')) $selectedCriterions[$idCriterionGroup] = $criterions; else if (!Tools::getValue('ajaxMode')) $selectedCriterions[$idCriterionGroup] = $criterions; } } } } private function getCriterionsGroupsAndCriterionsForSearch($result, $id_lang, $selected_criterion = array(), $selected_criterion_hidden = array(), $with_products = false, $id_criterion_group = 0, $on_search = false) { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $currency = Context::getContext()->currency; else global $currency; $criterion_group_state = (isset($this->_cookie->criterion_group_state) ? @unserialize($this->_cookie->criterion_group_state):array()); $hidden_criteria_state = (isset($this->_cookie->hidden_criteria_state) ? @unserialize($this->_cookie->hidden_criteria_state):array()); $set_base_selection = false; $selected_criteria_groups_type = array(); if (!$selected_criterion || (is_array($selected_criterion) && ! sizeof($selected_criterion))) $reinit_selected_criterion = true; if (AdvancedSearchCoreClass::_isFilledArray($result)) { foreach ($result as $key => $row) { // Pages SEO & Option ne montrer que les critères disponibles if ($row['filter_by_emplacement'] && Tools::getValue('id_seo') !== false && is_numeric(Tools::getValue('id_seo')) && Tools::getValue('id_seo') > 0) { if (!isset($result[$key]['seo_criterion_groups'])) $result[$key]['seo_criterion_groups'] = array(); if ($row['filter_by_emplacement'] && Tools::getValue('id_seo') !== false && is_numeric(Tools::getValue('id_seo')) && Tools::getValue('id_seo') > 0) { $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]; $result[$key]['seo_criterion_groups'][] = $id_criterion_group_seo; } } } } $result[$key]['seo_criterion_groups'] = array_unique($result[$key]['seo_criterion_groups']); } else { $result[$key]['seo_criterion_groups'] = array(); } if (isset($reinit_selected_criterion)) $selected_criterion = false; //Enable selected criteria only for current seo search if (Tools::getValue('seo_url') && Tools::getValue('id_seo_id_search') == $row ['id_search']) { $selected_criterion = Tools::getValue('as4c', array()); } //Force disable keep_category_information when SEO search if (Tools::getValue('seo_url')) { $result [$key] ['keep_category_information'] = 0; $row ['keep_category_information'] = 0; } if ($row['save_selection']) { if ($on_search && ((!$selected_criterion || (is_array($selected_criterion) && !sizeof($selected_criterion))))) $this->resetSearchSelection($row['id_search']); $this->saveSearchSelection($row, $selected_criterion); } //Filter search criterion depending of the location on the site Yes if ($row ['filter_by_emplacement'] && (!$selected_criterion || (is_array($selected_criterion) && ! sizeof($selected_criterion)))) { $selected_criterion = $this->_getCriteriaFromEmplacement($row['id_search'], $row['id_category_root']); $set_base_selection = true; } // Pages SEO & Option ne montrer que les critères disponibles if ($row['filter_by_emplacement'] && Tools::getValue('id_seo') !== false && is_numeric(Tools::getValue('id_seo')) && Tools::getValue('id_seo') > 0) { $this->_addToFBLog('SEO page, looking for pre-selected criterions'); $seo_search = new AdvancedSearchSeoClass((int)Tools::getValue('id_seo')); //$selected_criterion[(int)$row2['id_criterion_group']] = array(); if (Validate::isLoadedObject($seo_search) && isset($seo_search->criteria) && !empty($seo_search->criteria)) { $criteres_seo = @unserialize($seo_search->criteria); if (self::_isFilledArray($criteres_seo)) { foreach ($criteres_seo as $critere_seo) { $critere_seo = explode('_', $critere_seo); $id_criterion_group_seo = (int)$critere_seo[0]; if (strpos($critere_seo[1], '-') === false) $id_criterion_value = (int)$critere_seo[1]; else $id_criterion_value = $critere_seo[1]; if (isset($selected_criterion[$id_criterion_group_seo])) { if (!in_array($id_criterion_value, $selected_criterion[$id_criterion_group_seo])) { $selected_criterion[$id_criterion_group_seo][] = $id_criterion_value; } } else { $selected_criterion[$id_criterion_group_seo] = array(); $selected_criterion[$id_criterion_group_seo][] = $id_criterion_value; } } } $row['id_seo'] = (int)Tools::getValue('id_seo'); $row['id_seo_id_search'] = (int)$row['id_search']; $row['seo_url'] = (string)trim(Tools::getValue('seo_url')); } } //Clean empty criterion if (is_array($selected_criterion) && sizeof($selected_criterion)) { $selected_criterion = AdvancedSearchClass::cleanArrayCriterion($selected_criterion); $selected_criteria_groups_type = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($row ['id_search'], array_keys($selected_criterion)); } if ($set_base_selection || ($result [$key] ['base_selection'] = Tools::getValue('as4_base_selection',false))) { if (!isset($result [$key] ['base_selection'])) { if (isset($selected_criterion[key($selected_criterion)])) $result [$key] ['base_selection'] = $selected_criterion[key($selected_criterion)]; }else $result [$key] ['base_selection'] = unserialize(base64_decode($result [$key] ['base_selection'])); } if ($row ['step_search'] && is_array($selected_criterion) && sizeof($selected_criterion)) { $selected_criterion_groups = array_keys($selected_criterion); } //Keep old selection whene criteria are load dynamically if ($row ['dynamic_criterion'] && $row ['search_method'] && Tools::getIsset('with_product') && Tools::getIsset('old_selected_criterion')) $current_selected_criterion = unserialize(base64_decode(Tools::getValue('old_selected_criterion'))); else $current_selected_criterion = $selected_criterion; // Format selected criterions for SEO page lookup $selectedCriterionsForSeo = array(); if (self::_isFilledArray($current_selected_criterion)) { foreach ($current_selected_criterion as $idCriterionGroupSeo=>$idCriterionsForSeo) foreach (array_values($idCriterionsForSeo) as $idCriterionForSeo) $selectedCriterionsForSeo[] = (int)$idCriterionGroupSeo.'_'.(int)$idCriterionForSeo; $selectedCriterionsForSeo = array_unique($selectedCriterionsForSeo); } //Compatibility for module productLinksNC if ($this->productLinksNCIsInstalled && (Tools::getValue('id_search') || Tools::getValue('id_seo'))/* && ((is_array($selected_criterion) && sizeof($selected_criterion)) || )*/) { $this->saveSearchSelection4ProductLinkNC($row['id_search'], $selected_criterion, $row['search_on_stock'], $row ['products_order_by'], $row ['products_order_way']); }elseif ($this->productLinksNCIsInstalled && !Tools::getValue('id_product',false)) { $this->clearSearchSelection4ProductLinkNC(); } if (!$id_criterion_group) $result [$key] ['criterions_groups'] = AdvancedSearchCriterionGroupClass::getCriterionsGroupsFromIdSearch($row ['id_search'], $id_lang, false); else $result [$key] ['criterions_groups'] = AdvancedSearchCriterionGroupClass::getCriterionsGroup($row ['id_search'], $id_criterion_group, $id_lang); //If remind selection OR display selection, get criterias groups selected if ($row ['remind_selection'] && is_array($current_selected_criterion) && sizeof($current_selected_criterion)) { $result [$key] ['criterions_groups_selected'] = AdvancedSearchCriterionGroupClass::getCriterionsGroup($row ['id_search'], array_keys($current_selected_criterion), $id_lang); foreach($current_selected_criterion as $id_criterion_group_selected => $selected_criteria) { foreach($selected_criteria as $criterion_value) { if (!isset($result [$key] ['criterions_selected'] [$id_criterion_group_selected])) $result [$key] ['criterions_selected'] [$id_criterion_group_selected] = array(); if (preg_match('#-#', $criterion_value)) { $range = explode('-', $criterion_value); $groupInfo = AdvancedSearchCriterionGroupClass::getCriterionGroupTypeAndRangeSign($row ['id_search'], $id_criterion_group_selected, $id_lang); if (self::_isFilledArray($groupInfo) && isset($groupInfo['criterion_group_type']) && $groupInfo['criterion_group_type'] == 'price') { $rangeSignLeft = $currency->getSign('left'); $rangeSignRight = $currency->getSign('right'); } else { $rangeSignLeft = ''; if (self::_isFilledArray($groupInfo) && isset($groupInfo['criterion_group_type'])) { $rangeSignRight = ' '.$groupInfo['range_sign']; } else { $rangeSignRight = ''; } } $result [$key] ['criterions_selected'] [$id_criterion_group_selected] [] = array('value' => $this->l('from').' '.$rangeSignLeft.$range[0].$rangeSignRight.' '.$this->l('to').' '.$rangeSignLeft.$range[1].$rangeSignRight, 'id_criterion' => $criterion_value); } else { $result [$key] ['criterions_selected'] [$id_criterion_group_selected] [] = AdvancedSearchCriterionClass::getCriterionValueById($row ['id_search'], $id_lang, $criterion_value); } } } } if (!Tools::getValue('only_products')) { if (isset($hidden_criteria_state[$row['id_search']])) { $result [$key] ['advanced_search_open'] = $hidden_criteria_state[$row['id_search']]; }else $result [$key] ['advanced_search_open'] = 0; $this->_addToFBLog("Retrieve criterions groups"); if (sizeof($result [$key] ['criterions_groups'])) { $prev_id_criterion_group = false; foreach ($result [$key] ['criterions_groups'] as $key2 => $row2) { // Do not calculate invisible criterion group if ($row2['visible'] == 0) continue; //Check if criterion group is collapsed if ($row['collapsable_criterias'] && isset($criterion_group_state[$row['id_search'].'_'.$row2 ['id_criterion_group']]) && (int)$criterion_group_state[$row['id_search'].'_'.$row2 ['id_criterion_group']] == 0) { $result [$key] ['criterions_groups'][$key2]['is_collapsed'] = true; } elseif (isset($criterion_group_state[$row['id_search'].'_'.$row2 ['id_criterion_group']]) && $criterion_group_state[$row['id_search'].'_'.$row2 ['id_criterion_group']]) $result [$key] ['criterions_groups'][$key2]['is_collapsed'] = false; //Exclude filter by emplacement if are not on this if (!$row2 ['visible'] && ! isset($selected_criterion [$row2 ['id_criterion_group']]) && (($row2 ['criterion_group_type'] == 'manufacturer' && ! Tools::getValue('id_manufacturer')) || ($row2 ['criterion_group_type'] == 'supplier' && ! Tools::getValue('id_supplier')) || ($row2 ['criterion_group_type'] == 'category' && ! Tools::getValue('id_category')))) continue; //If step mode and not slection, get only criterion for the first group if (!$row ['step_search'] || (($row ['step_search'] && ($key2 == 0 || (isset($selected_criterion_groups) && (in_array($row2 ['id_criterion_group'], $selected_criterion_groups) || ($prev_id_criterion_group && in_array($prev_id_criterion_group, $selected_criterion_groups)) || ! sizeof($result [$key] ['criterions'] [$prev_id_criterion_group]))))))) { //Display as range if ($row2 ['range'] == 1) { if ($row2 ['criterion_group_type'] == 'price') { $rangeSignLeft = $currency->getSign('left'); $rangeSignRight = $currency->getSign('right'); } else { $rangeSignLeft = ''; $rangeSignRight = ' '.$row2['range_sign']; } $ranges = explode(',', $row2 ['range_interval']); $criteria_formated = array(); foreach($ranges as $krange => $range) { $rangeUp = (isset($ranges[$krange+1]) ? $ranges[$krange+1]:''); $range1 = $range.'-'.$rangeUp; $range2 = ($rangeUp?$this->l('from'):$this->l('more than')).' '.$rangeSignLeft.$range.$rangeSignRight.($rangeUp?' '.$this->l('to').' '.$rangeSignLeft.$rangeUp.$rangeSignRight:''); $selected_criteria_groups_type2 = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($row['id_search'],array($row2 ['id_criterion_group'])); if (is_array($selected_criterion)) $citeria4count = $selected_criterion; else $citeria4count = array(); $citeria4count[$row2 ['id_criterion_group']] = array($range1); $selected_criteria_groups_type2 = AdvancedSearchClass::getCriterionGroupsTypeAndDisplay($row['id_search'],array_keys($citeria4count)); $nb_products = AdvancedSearchClass::getProductsSearched($row, $id_lang,false, $citeria4count, $selected_criteria_groups_type2, NULL, NULL, NULL, NULL, true,false,false,false,false,true,false, $row['search_on_stock']); if (!$row['display_empty_criteria'] && !$nb_products) continue; $criteria_formated [$range1] = array('id_criterion' => $range1, 'value' => $range2,'nb_product'=> $nb_products); } $result [$key] ['criterions'] [$row2 ['id_criterion_group']] = $criteria_formated; } //Display as price slider elseif ($row2 ['criterion_group_type'] == 'price') { //Remove current group from selection for getting original range $range_selected_criterion = $selected_criterion; unset($range_selected_criterion[$row2 ['id_criterion_group']]); //Get min/max price range $result [$key] ['criterions'] [$row2 ['id_criterion_group']] = AdvancedSearchClass::getPriceRangeForSearchBloc($row, $row2 ['id_criterion_group'], $this->_cookie->id_currency, (isset($this->_cookie->id_country) ? $this->_cookie->id_country : 0), $this->getCurrentCustomerGroupId(), false, ($row ['step_search'] && !$id_criterion_group && $key2 == 0 ? array() : $range_selected_criterion), ($row ['step_search'] && !$id_criterion_group && $key2 == 0 ? array() : $selected_criteria_groups_type)); $this->_addToFBLog("Retrieve price range group " . $row2 ['id_criterion_group']); $min_price_id_currency = (int)$result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['min_price_id_currency']; $max_price_id_currency = (int)$result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['max_price_id_currency']; // Default values before convert $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['min'] = $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['min_price']; $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['max'] = $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['max_price']; if (($min_price_id_currency == 0 && $min_price_id_currency != $this->_cookie->id_currency) || ($min_price_id_currency != 0 && $min_price_id_currency != $this->_cookie->id_currency)) $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['min'] = floor(Tools::convertPrice($result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['min_price'], NULL, $this->_cookie->id_currency)); if (($max_price_id_currency == 0 && $max_price_id_currency != $this->_cookie->id_currency) || ($max_price_id_currency != 0 && $max_price_id_currency != $this->_cookie->id_currency)) $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['max'] = ceil(Tools::convertPrice($result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['max_price'], NULL, $this->_cookie->id_currency)); $result [$key] ['criterions_groups'][$key2]['left_range_sign'] = $currency->getSign('left'); $result [$key] ['criterions_groups'][$key2]['right_range_sign'] = $currency->getSign('right'); //Set current price range if (AdvancedSearchCoreClass::_isFilledArray($selected_criterion) && isset($selected_criterion[$row2 ['id_criterion_group']]) && sizeof($selected_criterion[$row2 ['id_criterion_group']])) { $range = explode('-', $selected_criterion[$row2 ['id_criterion_group']][0]); $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['cur_min'] = $range [0]; if (isset($range [1])) $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['cur_max'] = $range [1]; } //Define step range $result [$key] ['criterions'] [$row2 ['id_criterion_group']][0]['step'] = ((float)$row2['range_nb'] <= 0 ? 1 : $row2['range_nb']); } elseif ($row2 ['display_type'] == 5) { //Remove current group from selection for getting original range $range_selected_criterion = $selected_criterion; unset($range_selected_criterion[$row2 ['id_criterion_group']]); $result [$key] ['criterions'] [$row2 ['id_criterion_group']] = AdvancedSearchClass::getCriterionsRange($row, $row2 ['id_criterion_group'], $id_lang,false, $range_selected_criterion, $selected_criteria_groups_type, $this->_cookie->id_currency, (isset($this->_cookie->id_country) ? $this->_cookie->id_country : 0), $this->getCurrentCustomerGroupId(), $row2); //Set current range if (AdvancedSearchCoreClass::_isFilledArray($selected_criterion) && isset($selected_criterion[$row2 ['id_criterion_group']]) && sizeof($selected_criterion[$row2 ['id_criterion_group']])) { $range = explode('-', $selected_criterion[$row2 ['id_criterion_group']][0]); $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['cur_min'] = $range [0]; if (isset($range [1])) $result [$key] ['criterions'] [$row2 ['id_criterion_group']] [0] ['cur_max'] = $range [1]; } //Define step range $result [$key] ['criterions'] [$row2 ['id_criterion_group']][0]['step'] = ((float)$row2['range_nb'] <= 0 ? 1 : $row2['range_nb']); // Define range sign $result [$key] ['criterions_groups'][$key2]['left_range_sign'] = ''; $result [$key] ['criterions_groups'][$key2]['right_range_sign'] = (isset($row2['range_sign']) && strlen($row2['range_sign']) > 0 ? ' '.$row2['range_sign'] : ''); } else { $criteria = AdvancedSearchClass::getCriterionsForSearchBloc($row, $row2 ['id_criterion_group'], $id_lang, $row ['display_nb_result_criterion'],/*($row['step_search'] && !$id_criterion_group && $key2 == 0?array():$selected_criterion)*/$selected_criterion, $selected_criteria_groups_type, $this->_cookie->id_currency, (isset($this->_cookie->id_country) ? $this->_cookie->id_country : 0), $this->getCurrentCustomerGroupId(), true, $row2,(isset($result [$key] ['base_selection']) && $result [$key] ['base_selection'] && self::_isFilledArray($result [$key] ['base_selection']) ? $result [$key] ['base_selection'] : false), $result[$key]['criterions_groups']); //Table formatted for easier access by the key $criteria_formated = array(); if ($criteria && sizeof($criteria)) { $criteria_formated = array(); foreach ($criteria as $rowCriteria) { $criteria_formated [$rowCriteria ['id_criterion']] = $rowCriteria; // Get seo page for selected criterions $idSeoCriterionLink = AdvancedSearchSeoClass::seoExists($this->getSeoKeyFromCriteria($row['id_search'], array_merge($selectedCriterionsForSeo, array((int)$rowCriteria ['id_criterion_group'].'_'.(int)$rowCriteria['id_criterion'])), $this->_cookie->id_currency)); if ($idSeoCriterionLink) { $criteria_formated [$rowCriteria ['id_criterion']]['id_seo'] = $idSeoCriterionLink; $criteria_formated [$rowCriteria ['id_criterion']]['seo_page_url'] = AdvancedSearchSeoClass::getSeoPageUrl($idSeoCriterionLink, $this->_cookie->id_lang); } else { $criteria_formated [$rowCriteria ['id_criterion']]['id_seo'] = false; $criteria_formated [$rowCriteria ['id_criterion']]['seo_page_url'] = false; } } } $result [$key] ['criterions'] [$row2 ['id_criterion_group']] = $criteria_formated; $this->_addToFBLog("Retrieve criterions for group " . $row2 ['id_criterion_group']); } $prev_id_criterion_group = $row2 ['id_criterion_group']; } } } } if ($with_products) { $result [$key] ['products'] = AdvancedSearchClass::getProductsSearched($row, $id_lang, false, $selected_criterion, $selected_criteria_groups_type, (int)Tools::getValue('p', 1), (int)Tools::getValue('n', $row ['products_per_page']),/*$orderBy = */Tools::getValue('orderby', $this->orderByValues [$row ['products_order_by']]), /*$orderWay =*/ Tools::getValue('orderway', $this->orderWayValues [$row ['products_order_way']]), /*$getTotal =*/ false, $this->_cookie->id_currency, (isset($this->_cookie->id_country) ? $this->_cookie->id_country : 0), $this->getCurrentCustomerGroupId(), true); $this->_addToFBLog("Retrieve results"); } //Count total results if ($with_products || $row ['display_nb_result_on_blc']) { $result [$key] ['total_products'] = AdvancedSearchClass::getProductsSearched($row, $id_lang, false, $selected_criterion, $selected_criteria_groups_type, 1, 10, NULL, NULL, true, $this->_cookie->id_currency, (isset($this->_cookie->id_country) ? $this->_cookie->id_country : 0), $this->getCurrentCustomerGroupId(), true); $this->_addToFBLog("Retrieve results count"); } $result [$key] ['selected_criterion'] = $selected_criterion; //Keep old selection whene criteria are load dynamically if ($row ['dynamic_criterion'] && $row ['search_method'] && Tools::getIsset('with_product') && Tools::getIsset('old_selected_criterion')) { $result [$key] ['old_selected_criterion'] = unserialize(base64_decode(Tools::getValue('old_selected_criterion'))); } $result [$key] ['save_selection_active'] = isset($row ['save_selection_active']); } } return $result; } public function getShareBlock($ASSearchTitle, $searchUrl) { $this->_smarty->assign(array('ASShareUrl'=> $this->getTinyurl($searchUrl), 'ASSearchTitle' => $ASSearchTitle)); return $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/':'').'pm_advancedsearch_share_block.tpl'); } private function _assignForProductsResults() { if (version_compare(_PS_VERSION_, '1.4.0.0', '>=')) { //Set media for PS > 1.4 $css_files = array(); $js_files = array(); if (version_compare(_PS_VERSION_, '1.5.0.0', '<')) { include_once (_PS_ROOT_DIR_ . '/controllers/CategoryController.php'); $CategoryController = new CategoryControllerCore(); $CategoryController->setMedia(); } //Fix for PS 1.4.0.17 if ((version_compare(_PS_VERSION_, '1.5.0.0', '>=') && !sizeof($this->_context->controller->css_files)) || (version_compare(_PS_VERSION_, '1.5.0.0', '<') && !sizeof($css_files))) $css_files = array (_PS_CSS_DIR_ . 'jquery.cluetip.css' => 'all', _THEME_CSS_DIR_ . 'scenes.css' => 'all', _THEME_CSS_DIR_ . 'category.css' => 'all', _THEME_CSS_DIR_ . 'product_list.css' => 'all' ); if (!sizeof($js_files)) { if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0) $js_files = array (_THEME_JS_DIR_ . 'products-comparison.js' ); } $searchUrl = Tools::getHttpHost(true) . preg_replace('$&ajaxMode=1|&keep_category_information=1|&step_search=1|&submitAsearch=.[^&]*|&next_id_criterion_group=[0-9]*$', '', $_SERVER ['REQUEST_URI']); $this->_smarty->assign(array ('comparator_max_item' => (int)(Configuration::get('PS_COMPARATOR_MAX_ITEM')), 'css_files_result_search' => $css_files, 'js_files_result_search' => $js_files, 'ASSearchUrl' => $searchUrl )); } // Set SEO vars if (Tools::getIsset('id_seo') && (int)Tools::getValue('id_seo') > 0) { $resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int)Tools::getValue('id_seo'), (int)$this->_cookie->id_lang); if (self::_isFilledArray($resultSeoUrl)) { $this->_smarty->assign(array( 'as_seo_title' => $resultSeoUrl[0]['title'], 'as_seo_description' => $resultSeoUrl[0]['description'] )); } } $this->_smarty->assign(array ('categorySize' => $this->_getImageSize('category'), 'mediumSize' => $this->_getImageSize('medium'), 'thumbSceneSize' => $this->_getImageSize('thumb_scene'), 'homeSize' => $this->_getImageSize('home'), 'static_token' => Tools::getToken(false) )); } private function _getImageSize($imageType) { if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { $img_size = Image::getSize($imageType); // Try with if (!self::_isFilledArray($img_size)) $img_size = Image::getSize(self::_getImageTypeFormatedName($imageType)); else return $img_size; // Try with _default if (!self::_isFilledArray($img_size)) $img_size = Image::getSize($imageType.'_default'); return $img_size; } else { return Image::getSize($imageType); } } private function getLocationName($id_lang) { $location_name = false; $id_category = (int)Tools::getValue('id_category'); $id_category_search = (int)Tools::getValue('id_category_search'); if ($id_category) $location_name = AdvancedSearchClass::getCategoryName($id_lang, $id_category); else if ($id_category_search) $location_name = AdvancedSearchClass::getCategoryName($id_lang, $id_category_search); return $location_name; } public function getTinyurl($url) { $tinyurl = @file_get_contents('http://tinyurl.com/api-create.php?url=' . urlencode($url)); return ($tinyurl ? $tinyurl : $url); } public function getNextIdCriterionGroup($id_search) { if (isset($this->_cookie->{'next_id_criterion_group_'.(int)$id_search})) { return $this->_cookie->{'next_id_criterion_group_'.(int)$id_search}; } return ''; } public function displayNextStepSearch($id_search, $hookName, $id_criterion_group, $with_product, $selected_criterion = array(), $selected_criterion_hidden = array()) { $json_return = array(); //Check if cache is enable $searchs = AdvancedSearchClass::getSearch($id_search, $this->_cookie->id_lang); $json_return['next_id_criterion_group'] = $this->getNextIdCriterionGroup($id_search); $this->_addToFBLog("Retrieve steps"); $searchs = $this->getCriterionsGroupsAndCriterionsForSearch($searchs, $this->_cookie->id_lang, $selected_criterion, $selected_criterion_hidden, $with_product, $id_criterion_group); $next_id_criterion_group = AdvancedSearchCriterionGroupClass::getNextIdCriterionGroup($id_search, $id_criterion_group); $this->_addToFBLog("Retrieve criterons and results 1"); $this->_smarty->assign(array ('as_searchs' => $searchs, 'as_search' => $searchs [0], 'hookName' => $hookName, 'criterions_group' => $searchs [0] ['criterions_groups'] [0], 'as_obj' => $this, 'as_path' => $this->_path, 'as_selected_criterion' => $selected_criterion, 'as_criteria_group_type_interal_name' => $this->criteria_group_type_interal_name, 'next_id_criterion_group' => $next_id_criterion_group, 'col_img_dir' => _PS_COL_IMG_DIR_ )); $json_return ['html_criteria_block'] = $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/':'').'pm_advancedsearch_criterions.tpl'); if ($searchs [0] ['remind_selection'] == 3 || $searchs [0] ['remind_selection'] == 2) { $json_return ['html_selection_block'] = $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/':'').'pm_advancedsearch_selection_block.tpl'); } if ($with_product) { //Get products listing navigations $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']); //Init MagicZoom 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'); } } self::_cleanBuffer(); if (Tools::getValue('ajaxMode')) echo json_encode($json_return); else { foreach ($json_return as $value ) echo $value; } return false; } 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); $json_return['next_id_criterion_group'] = $this->getNextIdCriterionGroup($id_search); $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); $location_name = $this->getLocationName($this->_cookie->id_lang); if (Tools::getValue('id_seo')) { $this->_smarty->assign(array('hideAS4Form' => ((empty($hookName) || $hookName == 'home') ? true : 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) || $hookName == 'home')))) $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']); // Redirect to product sheet if only one result & redirect_one_product = 1 & search_method = 2 if ($ajaxMode && 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'); } } 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; } public function displaySearchBlock($hookName, $tplName, $selected_criterion = array()) { //Compatibility 1.5 if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $newHookName = self::getNewHookName($hookName); else $newHookName = $hookName; $searchs = AdvancedSearchClass::getSearchsFromHook($newHookName, $this->_cookie->id_lang); $this->_addToFBLog("Retrieve searchs for hook ".$hookName); if (sizeof($searchs)) { $location_name = $this->getLocationName($this->_cookie->id_lang); $searchs = $this->getCriterionsGroupsAndCriterionsForSearch($searchs, $this->_cookie->id_lang, $selected_criterion, array(), false); $this->_smarty->assign(array ('as4_productFilterListSource' => self::$productFilterListSource, 'as4_productFilterListData' => (isset(self::$productFilterListSource) && self::$productFilterListSource == 'search' && !empty(self::$productFilterListData) ? base64_encode(self::$productFilterListData) : ''), '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 )); return ($this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/':'').$tplName)); } return false; } public function assignSearchVar($selected_criterion = array()) { //Get customs hooked searchs $as4_smartyVarList = AdvancedSearchClass::getSearchsIdFromHook(-1); $this->_addToFBLog("Retrieve id_search by smarty variable"); if (self::_isFilledArray($as4_smartyVarList)) { $searchs = AdvancedSearchClass::getSearchsFromHook(-1, $this->_cookie->id_lang); $location_name = $this->getLocationName($this->_cookie->id_lang); foreach($searchs as $search) { $search['next_id_criterion_group'] = $this->getNextIdCriterionGroup((int)$search['id_search']); $this->_addToFBLog("Retrieve criterions by smarty variable"); $search = $this->getCriterionsGroupsAndCriterionsForSearch(array(0 => $search), $this->_cookie->id_lang, $selected_criterion, array(), false); $this->_smarty->assign(array('as4_productFilterListSource' => self::$productFilterListSource, 'as4_productFilterListData' => (isset(self::$productFilterListSource) && self::$productFilterListSource == 'search' && !empty(self::$productFilterListData) ? base64_encode(self::$productFilterListData) : ''),'as_searchs' => $search, 'hookName' => 'home', '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)); $this->_smarty->assign($search[0] ['smarty_var_name'], $this->_smarty->fetch($this->_getTemplatePath('views/templates/hook/pm_advancedsearch.tpl'))); } } return; } public function setProductFilterContext() { if (self::$productFilterListSource == 'best-sales') { self::$productFilterList = $this->_getBestSellersProductsIds(); } else if (self::$productFilterListSource == 'new-products') { self::$productFilterList = $this->_getNewProductsIds(); } else if (self::$productFilterListSource == 'prices-drop') { self::$productFilterList = $this->_getPricesDropProductsIds(); } else if (self::$productFilterListSource == 'search' && !empty(self::$productFilterListData)) { self::$productFilterList = $this->_getProductsByNativeSearch(self::$productFilterListData); } } 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'); //Send search URL on tpl 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(); //Output header return $this->display(__FILE__, (version_compare(_PS_VERSION_, '1.5.0.0', '<') ? '/views/templates/hook/':'').'pm_advancedsearch_header.tpl'); } public function hookHome($params) { if ($this->_isInMaintenance() || $this->_isMobileTheme()) return; return $this->displaySearchBlock('home', 'pm_advancedsearch.tpl'); } public function hookTop($params) { if ($this->_isInMaintenance() || $this->_isMobileTheme()) return; return $this->displaySearchBlock('top', 'pm_advancedsearch.tpl'); } public function hookLeftColumn($params) { if ($this->_isInMaintenance() || $this->_isMobileTheme()) return; return $this->displaySearchBlock('leftColumn', 'pm_advancedsearch.tpl'); } public function hookRightColumn($params) { if ($this->_isInMaintenance() || $this->_isMobileTheme()) return; return $this->displaySearchBlock('rightColumn', 'pm_advancedsearch.tpl'); } public function hookDisplayBackOfficeHeader($params) { parent::hookDisplayBackOfficeHeader($params); if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) $this->hookBackOfficeHeader($params); } public function hookBackOfficeHeader($params) { //Save from product attributes, features and price tabs if ( (Tools::getValue('id_product') && Tools::getIsset('addproduct') && (Tools::getValue('tabs') == 0 || Tools::getValue('tabs') == 1 || Tools::getValue('tabs') == 2 || Tools::getValue('tabs') == 3 || Tools::getValue('tabs') == 4 /*PS 1.5*/ || Tools::getValue('key_tab') == 'Features' || Tools::getValue('key_tab') == 'Combinations' || Tools::getValue('key_tab') == 'Prices' || Tools::getValue('key_tab') == 'Informations' || Tools::getValue('key_tab') == 'Shipping')) // Cover update PS 1.5 || (Tools::getValue('id_product') && Tools::getIsset('action') && strtolower(Tools::getValue('action')) == 'updatecover') ) { $id_product = Tools::getValue('id_product'); $product = New Product($id_product); AdvancedSearchClass::indexCriterionsFromProduct($product); } } // Specific price delete public function hookActionObjectSpecificPriceDeleteAfter($params) { if (isset($params['object']) && isset($params['object']->id_product)) { $id_product = $params['object']->id_product; $product = New Product($id_product); AdvancedSearchClass::indexCriterionsFromProduct($product); } } public function hookUpdateProduct($params) { AdvancedSearchClass::indexCriterionsFromProduct($params ['product']); } public function hookAddProduct($params) { AdvancedSearchClass::indexCriterionsFromProduct($params ['product'], true); } public function hookDeleteProduct($params) { $id_product = $params ['product']->id; AdvancedSearchClass::desIndexCriterionsFromProduct($id_product); } public function reindexAllSearchs() { self::_changeTimeLimit(0); //self::_iniSet('memory_limit', '100M'); $advanced_searchs_id = AdvancedSearchClass::getSearchsId(false); foreach ($advanced_searchs_id as $key => $row) { $this->reindexSpecificSearch($row ['id_search']); } $this->_html = '$jqPm( "#progressbarReindexAllSearch" ).progressbar( "option", "value", 100 );show_info("'.addcslashes($this->l('Indexation done'),'"').'")'; } public function reindexSpecificSearch($id_search) { $objSearch = new AdvancedSearchClass($id_search, $this->_cookie->id_lang); //Update product cache table $objSearch->updateCacheProduct(); $criterions_groups_indexed = AdvancedSearchClass::getCriterionsGroupsIndexed($id_search, $this->_cookie->id_lang, false); if (self::_isFilledArray($criterions_groups_indexed)) { foreach ($criterions_groups_indexed as $key2 => $row2) { AdvancedSearchClass::indexCriterionsGroup($row2 ['criterion_group_type'], $row2 ['id_criterion_group_linked'], $objSearch, $row2 ['visible'], false, true); } } //Tables optimization AdvancedSearchClass::optimizedSearchTables($objSearch->id, true); unset($objSearch, $criterions_groups_indexed, $id_search); } public function reindexCriteriaGroup() { self::_changeTimeLimit(0); //self::_iniSet('memory_limit', '100M'); $id_search = Tools::getValue('id_search'); $objSearch = new AdvancedSearchClass($id_search, $this->_cookie->id_lang); $id_criterion_group = Tools::getValue('id_criterion_group'); $objCritGroup = new AdvancedSearchCriterionGroupClass($id_criterion_group, $id_search); AdvancedSearchClass::indexCriterionsGroup($objCritGroup->criterion_group_type, $objCritGroup->id_criterion_group_linked, $objSearch, $objCritGroup->visible, false, true); //Tables optimization AdvancedSearchClass::optimizedSearchTables($objSearch->id); unset($objSearch, $id_search, $objCritGroup); } public function cronTask() { $this->reindexAllSearchs(); } public function displayCriterionGroupForm($params) { $objCrit = $params['obj']; $ObjASClass = new AdvancedSearchClass($objCrit->id_search); $this->_startForm(array('id' => 'criteriaGroupOptions_'.(int)$objCrit->id,'obj' => $params['obj'],'params'=>$params)); /*Criteria group Options*/ $this->_displayTitle($this->l('Options')); $this->_displayInputTextLang(array('obj' => $objCrit, 'key' => 'name', 'label' => $this->l('Group name'))); if (in_array($objCrit->criterion_group_type, $this->criterionGroupIsTemplatisable)) { if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked)) $this->options_criteria_group_type [7] = $this->l('Color Square'); } $classType = array(); foreach ($this->options_criteria_group_type as $key=>$val) $classType[$key] = 'display_type-'.$key; $configOptions = array( 'obj' => $objCrit, 'label' => $this->l('Type'), 'key' => 'display_type', 'class' => $classType, 'options' => $this->options_criteria_group_type, 'defaultvalue'=>false, 'onchange' => 'showRelatedOptions($jqPm(this),"'.$objCrit->criterion_group_type.'");' ); $this->_displaySelect($configOptions); //$this->_displaySelect($objCrit, $this->options_criteria_group_type, 'display_type', $this->l('Type'),false,'300px','showRelatedOptions($jqPm(this),"'.$objCrit->criterion_group_type.'")'); $this->_html .= '
'; $this->_displayInputActive(array('obj' => $objCrit, 'key_active' => 'range', 'key_db' => 'range', 'label' => $this->l('Display group as range'),'onclick'=>'displayRangeOptions($jqPm(this),\''.$objCrit->criterion_group_type.'\');')); $this->_html .= '
'; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this -> _displayInputFileLang(array( 'obj' => $objCrit, 'key' => 'icon', 'label' => $this->l('Image'), 'destination' => '/search_files/criterions_group/', 'required' => false, 'tips' => $this->l('You can upload a picture from your hard disk. This picture could be different for each language.'), 'extend'=> true )); if ($objCrit->criterion_group_type == 'category' && !$objCrit->id_criterion_group_linked) $this->_displayInputActive(array('obj' => $objCrit, 'key_active' => 'show_all_depth', 'key_db' => 'show_all_depth', 'label' => $this->l('Show all level categories'))); if ($objCrit->criterion_group_type == 'category') $this->_displayInputActive(array('obj' => $objCrit, 'key_active' => 'only_children', 'key_db' => 'only_children', 'label' => $this->l('Search only on children categories'))); if ($ObjASClass->collapsable_criterias) { $this->_html .= '
'; $this->_displayInputActive(array('obj' => $objCrit, 'key_active' => 'is_collapsed', 'key_db' => 'is_collapsed', 'label' => $this->l('Collapse the group at loading'))); $this->_html .= '
'; }else $this->_html .= ''; $this->_html .= ''; //Group width for hook top & home if (in_array($ObjASClass->id_hook, $this->display_horizontal_search_block)) $this->_displayInputText(array('obj' => $objCrit,'key' => 'width', 'label' => $this->l('Group width') )); //Height for overflow if ($ObjASClass->show_hide_crit_method == 3) $this->_displayInputText(array('obj' => $objCrit,'key' => 'overflow_height', 'label' => $this->l('Overflow height') )); //Max item visible if (($ObjASClass->show_hide_crit_method == 1 || $ObjASClass->show_hide_crit_method == 2)) { $this->_html .= ''; } $this->_html .= ''; $this->_html .= ''; $this->_pmClear(); $this->_displaySubmit($this->l('Save'), 'submitCriteriaGroupOptions'); $this->_endForm(array('id' => 'criteriaGroupOptions_'.(int)$objCrit->id,'iframetarget'=>false)); //Trigger on form element $this->_html .= ''; //Display ul sortable if (in_array($objCrit->criterion_group_type, $this->sortableCriterion)) { $this->_displayTitle($this->l('Sort criteria')); $configOptions = array( 'obj' => $objCrit, 'label' => false, 'key' => 'sort_by', 'options' => array(0=>$this->l('Sort by'),'numeric'=>$this->l('Numéric'),'alphabetic'=>$this->l('Alphabetic'),'position'=>$this->l('Position'),'nb_product'=>$this->l('Products count')), 'defaultvalue'=>0, 'onchange' => 'reorderCriteria($jqPm("#sort_by").val(),$jqPm("#sort_way").val(),$jqPm("input[name=\'id_criterion_group\']").val(),'.(int)$objCrit->id_search.');' ); $this->_html .= '
'.$this->l('Apply specific sort :').'     '; $this->_displaySelect($configOptions); $this->_html .= '
'; $configOptions = array( 'obj' => $objCrit, 'label' => false, 'key' => 'sort_way', 'options' => array('ASC'=>$this->l('ASC'),'DESC'=>$this->l('DESC')), 'defaultvalue'=> 0, 'onchange' => 'reorderCriteria($jqPm("#sort_by").val(),$jqPm("#sort_way").val(),$jqPm("input[name=\'id_criterion_group\']").val(),'.(int)$objCrit->id_search.');' ); $this->_html .= '
'; $this->_displaySelect($configOptions); $this->_html .= '
'; $this->displaySortCriteriaPanel($objCrit); $this->_html .= '

'; if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked)) $this->displayCustomCriteriaPanel($objCrit, $params); } $this->_footerIframe(); } protected function displaySortCriteriaPanel($objCrit = false){ if (Tools::getValue('pm_load_function') != 'displaySortCriteriaPanel') { $this->_html .= '
'; } else { $objCrit = new AdvancedSearchCriterionGroupClass(Tools::getValue('id_criterion_group'),Tools::getValue('id_search')); if (Tools::getValue('sort_way')) { $objCrit->sort_by = Tools::getValue('sort_by'); $objCrit->sort_way = Tools::getValue('sort_way'); $objCrit->save(); $msgConfirm = $this->l('Specific sort apply'); if ($objCrit->sort_by == 'position') $msgConfirm .= '
'.$this->l('Now, you can sort criteria by drag n drop'); $this->_html .= ''; } } $criterions = AdvancedSearchClass::getCriterionsFromCriterionGroup($objCrit->criterion_group_type, $objCrit->id_criterion_group_linked, $objCrit->id_search, $objCrit->sort_by, $objCrit->sort_way, $this->_cookie->id_lang); $this->_html .= '
'; $this->_html .= '
    '; foreach ($criterions as $row) { $objCritClass = new AdvancedSearchCriterionClass($row ['id_criterion'], $objCrit->id_search); $this->_html .= '
  • '; $this->_html .= ' '; $this->_html .= ''. $row ['value'] . ''; if ($objCrit->display_type == 2) { $this->_html .= '
    '; $this->_html .= '
    '; $this->displayInlineUploadFile($objCritClass,'icon'.$row ['id_criterion'] ,'icon', $this->l('Image'), '/search_files/criterions/'); $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; $this->_html .= ' '; $this->_html .= '
    '; $this->_html .= '
    '; } else if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked) && isset($row['is_custom']) && $row['is_custom']) { $this->_html .= '
    '; $this->_html .= '
    '; $this->_displayInputTextLang(array('obj' => $objCritClass, 'key' => 'value', 'label' => $this->l('Criterion label:'))); $this->_html .= '
    '; $this->_html .= '
    '; $this->_displayInputColor(array('obj' => $objCritClass, 'key' => 'color', 'label' => $this->l('Color:'))); $this->_html .= '
    '; $this->_html .= '
    '; $this->_displaySubmit($this->l('Save'), 'submitCustomCriterionForm'); $this->_html .= '
    '; $this->_html .= '
    '; $this->_html .= ''; $this->_html .= ''; $this->_html .= ''; } else if ($objCrit->criterion_group_type == 'attribute' && AdvancedSearchClass::isColorAttributesGroup($objCrit->id_criterion_group_linked) && (!isset($row['is_custom']) || isset($row['is_custom']) && !$row['is_custom'])) { $this->_html .= ''; $customCriterionsList = AdvancedSearchCriterionClass::getCustomCriterions($objCrit->id_search, $objCrit->id, $this->_cookie->id_lang); $customCriterionsIdsList = AdvancedSearchCriterionClass::getCustomMasterIdCriterion((int)$objCrit->id_search, $row['id_criterion']); if (is_array($customCriterionsList) && sizeof($customCriterionsList)) { $customCriterionsList = array(0 => $this->l('None')) + $customCriterionsList; $this->_html .= '
    '; $this->_displaySelect(array( 'obj' => (object)array('custom_group_link_id_'.(int)$row['id_criterion'] => AdvancedSearchCriterionClass::getCustomMasterIdCriterion((int)$objCrit->id_search, $row['id_criterion'])), 'label' => $this->l('Add to a group of custom criterion:'), 'key' => 'custom_group_link_id_'.(int)$row['id_criterion'], 'options' => $customCriterionsList, 'defaultvalue'=> false, 'onchange' => 'processAddCustomCriterionToGroup($jqPm(this), '.(int)$objCrit->id_search.', '.(int)Tools::getValue('id_criterion_group').')' )); $this->_html .= '
    '; } } else { $this->_html .= ''; } $this->_html .= '
  • '; } $this->_html .= '
'; if ($objCrit->sort_by == 'position') $this->_html .= ''; if (Tools::getValue('pm_load_function') != 'displaySortCriteriaPanel') { $this->_html .= '
'; } } protected function displayCustomCriteriaPanel($objCrit = false, $params){ $this->_displayTitle($this->l('Add a new custom criterion group')); $objCriterion = new AdvancedSearchCriterionClass(null, $objCrit->id_search); $this->_html .= '
'; $this->_displayInputTextLang(array('obj' => $objCriterion, 'key' => 'value', 'label' => $this->l('Criterion label:'))); $this->_displayInputColor(array('obj' => $objCriterion, 'key' => 'color', 'label' => $this->l('Color:'))); $this->_html .= '
'; $this->_displaySubmit($this->l('Save'), 'submitAddCustomCriterionForm'); $this->_html .= '
'; $this->_html .= '
'; } protected function displayInlineUploadFile($obj, $key, $key_db, $label, $destination, $uplodify = true, $filetype = '*.jpg;*.gif;*.png', $tips = false){ // Generate secure key if (version_compare(_PS_VERSION_, '1.5.0.0', '>=')) { if (Configuration::getGlobalValue('PM_'.self::$_module_prefix.'_UPLOAD_SECURE_KEY') === false) Configuration::updateGlobalValue('PM_'.self::$_module_prefix.'_UPLOAD_SECURE_KEY', Tools::passwdGen(16)); } else { if (Configuration::get('PM_'.self::$_module_prefix.'_UPLOAD_SECURE_KEY') === false) Configuration::updateValue('PM_'.self::$_module_prefix.'_UPLOAD_SECURE_KEY', Tools::passwdGen(16)); } $isImage = false; if (preg_match('/jpg|jpeg|gif|bmp|png/i', $filetype)) $isImage = true; $this->_html .= '
'; foreach ($this->_languages as $language) { $this->_html .= '
'; $this->_html .= '
'; } $this->displayPMFlags(); if ($uplodify) { foreach ($this->_languages as $language) { $this->_html .= '
'; $this->_html .= '
'; $file_location_dir = dirname(__FILE__) . $destination; //Check if have file and is exists if ($obj && $obj->{$key_db} [$language ['id_lang']] && file_exists($file_location_dir . $obj->{$key_db} [$language ['id_lang']])) { if ($isImage) { $this->_html .= ''; } else { $this->_html .= '' . $this->l('View file') . ''; } } $this->_html .= '' . $this->l('Delete this file') . ' '; $this->_html .= '
'; $this->_html .= '
'; $this->_html .= ''; } $this->_html .= ''; } $this->_pmClear(); $this->_html .= '
'; } public function __destruct() { if ($this->bench) { $this->_addToFBLog('End'); foreach ($this->bench_output as $message ) FB_AS4::log($message); } } public static function array_map_recursive($fn, $arr) { $rarr = array(); foreach ($arr as $k => $v) { if (is_array($v)) { $rarr[$k] = self::array_map_recursive($fn, $v); if (!count($rarr[$k])) unset($rarr[$k]); } else { $rarr[$k] = call_user_func($fn, $v); if ($rarr[$k] == 0) unset($rarr[$k]); } } return $rarr; } }