first commit

This commit is contained in:
2025-01-06 20:47:25 +01:00
commit 3bdbd78c2f
25591 changed files with 3586440 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
# Apache 2.2
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
# Apache 2.4
<IfModule mod_authz_core.c>
Require all denied
</IfModule>

View File

@@ -0,0 +1,349 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdvancedSearchClass extends ObjectModel
{
public $id;
public $id_hook;
public $active = true;
public $internal_name;
public $description;
public $title;
public $css_classes;
public $search_results_selector_css;
public $display_nb_result_on_blc = false;
public $display_nb_result_criterion = true;
public $remind_selection;
public $show_hide_crit_method;
public $filter_by_emplacement = true;
public $search_on_stock = false;
public $hide_empty_crit_group;
public $search_method;
public $step_search = false;
public $step_search_next_in_disabled;
public $position;
public $products_per_page;
public $products_order_by;
public $products_order_way;
public $keep_category_information;
public $display_empty_criteria = 0;
public $recursing_indexing = true;
public $search_results_selector;
public $smarty_var_name;
public $insert_in_center_column;
public $unique_search;
public $reset_group;
public $scrolltop_active = 1;
public $id_category_root = 0;
public $redirect_one_product = 1;
public $priority_on_combination_image = true;
public $add_anchor_to_url = true;
public $hide_criterions_group_with_no_effect;
protected $tables = array('pm_advancedsearch','pm_advancedsearch_lang');
protected $fieldsRequired = array('id_hook');
protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsRequiredLang = array();
protected $fieldsSizeLang = array();
protected $fieldsValidateLang = array('title'=>'isGenericName','description'=>'isCleanHTML');
protected $table = 'pm_advancedsearch';
public $identifier = 'id_search';
public static $definition = array(
'table' => 'pm_advancedsearch',
'primary' => 'id_search',
'multishop' => true,
'multilang_shop' => false,
'fields' => array(
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'internal_name' => array('type' => self::TYPE_STRING, 'lang' => false, 'required' => false, 'size' => 255),
'css_classes' => array('type' => self::TYPE_STRING, 'lang' => false, 'required' => false, 'size' => 255),
'search_results_selector' => array('type' => self::TYPE_STRING, 'lang' => false, 'required' => false, 'size' => 64),
'smarty_var_name' => array('type' => self::TYPE_STRING, 'lang' => false, 'required' => false, 'size' => 64),
)
);
public function __construct($id_search = null, $id_lang = null, $id_shop = null)
{
Shop::addTableAssociation(self::$definition['table'], array('type' => 'shop'));
parent::__construct($id_search, $id_lang, $id_shop);
}
public function getFields()
{
parent::validateFields();
$fields = array();
if (isset($this->id)) {
$fields['id_search'] = (int)$this->id;
}
$fields['id_hook'] = (int)$this->id_hook;
$fields['active'] = (int)$this->active;
$fields['internal_name'] = pSQL($this->internal_name);
$fields['css_classes'] = pSQL($this->css_classes);
$fields['search_results_selector_css'] = pSQL($this->search_results_selector_css);
$fields['display_nb_result_on_blc'] = (int)$this->display_nb_result_on_blc;
$fields['display_nb_result_criterion'] = (int)$this->display_nb_result_criterion;
$fields['remind_selection'] = (int)$this->remind_selection;
$fields['show_hide_crit_method'] = (int)$this->show_hide_crit_method;
$fields['filter_by_emplacement'] = (int)$this->filter_by_emplacement;
$fields['search_on_stock'] = (int)$this->search_on_stock;
$fields['hide_empty_crit_group'] = (int)$this->hide_empty_crit_group;
$fields['search_method'] = (int)$this->search_method;
$fields['priority_on_combination_image'] = (int)$this->priority_on_combination_image;
$fields['products_per_page'] = (int)$this->products_per_page;
$fields['products_order_by'] = (int)$this->products_order_by;
$fields['products_order_way'] = (int)$this->products_order_way;
$fields['step_search'] = (int)$this->step_search;
$fields['step_search_next_in_disabled'] = (int)$this->step_search_next_in_disabled;
$fields['keep_category_information'] = (int)$this->keep_category_information;
$fields['display_empty_criteria'] = (int)$this->display_empty_criteria;
$fields['recursing_indexing'] = (int)$this->recursing_indexing;
$fields['search_results_selector'] = pSQL($this->search_results_selector);
$fields['smarty_var_name'] = pSQL($this->smarty_var_name);
$fields['insert_in_center_column'] = (int)($this->insert_in_center_column);
$fields['reset_group'] = (int)($this->reset_group);
$fields['unique_search'] = (int)($this->unique_search);
$fields['scrolltop_active'] = (int)$this->scrolltop_active;
$fields['id_category_root'] = (int)$this->id_category_root;
$fields['redirect_one_product'] = (int)$this->redirect_one_product;
$fields['add_anchor_to_url'] = (int)$this->add_anchor_to_url;
$fields['position'] = (int)$this->position;
$fields['hide_criterions_group_with_no_effect'] = (int)$this->hide_criterions_group_with_no_effect;
return $fields;
}
public function getTranslationsFieldsChild()
{
parent::validateFieldsLang();
$fieldsArray = array('title');
$fields = array();
$languages = Language::getLanguages(false);
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language) {
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = (int)$this->id;
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']]) and !empty($this->description[$language['id_lang']])) ? pSQL($this->description[$language['id_lang']], true) : pSQL($this->description[$defaultLanguage], true);
foreach ($fieldsArray as $field) {
if (!Validate::isTableOrIdentifier($field)) {
die(Tools::displayError());
}
if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
} else {
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
}
}
}
return $fields;
}
public function save($nullValues = false, $autodate = false)
{
As4SearchEngine::setLocalStorageCacheKey();
if ($this->id_hook != -1) {
if ($this->id_hook == Hook::getIdByName('displayHome')) {
$this->insert_in_center_column = 1;
} else {
$this->insert_in_center_column = 0;
}
}
if (!empty($this->id) && !$this->filter_by_emplacement) {
$this->id_category_root = 0;
As4SearchEngineDb::execute('
UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_' . (int)$this->id . '`
SET `context_type`="2"
WHERE `criterion_group_type`="category"
');
}
$ret = parent::save($nullValues, $autodate);
$add_associations = true;
if ((int)$this->id_hook == (int)Hook::getIdByName('displayAdvancedSearch4')) {
$add_associations = false;
}
if (Tools::getIsset('categories_association') && $add_associations) {
$this->addAssociations($this->categories_association, 'pm_advancedsearch_category', 'id_category');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_category');
}
if (Tools::getIsset('cms_association') && $add_associations) {
$this->addAssociations($this->cms_association, 'pm_advancedsearch_cms', 'id_cms');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_cms');
}
if (Tools::getIsset('products_association') && $add_associations) {
$this->addAssociations($this->products_association, 'pm_advancedsearch_products', 'id_product');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_products');
}
if (Tools::getIsset('product_categories_association') && $add_associations) {
$this->addAssociations($this->product_categories_association, 'pm_advancedsearch_products_cat', 'id_category');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_products_cat');
}
if (Tools::getIsset('manufacturers_association') && $add_associations) {
$this->addAssociations($this->manufacturers_association, 'pm_advancedsearch_manufacturers', 'id_manufacturer');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_manufacturers');
}
if (Tools::getIsset('suppliers_association') && $add_associations) {
$this->addAssociations($this->suppliers_association, 'pm_advancedsearch_suppliers', 'id_supplier');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_suppliers');
}
if (Tools::getIsset('special_pages_association') && $add_associations) {
$this->addAssociations($this->special_pages_association, 'pm_advancedsearch_special_pages', 'page');
} elseif (Tools::isSubmit('submitSearchVisibility')) {
$this->cleanAssociation('pm_advancedsearch_special_pages');
}
return $ret;
}
public function duplicate($id_shop = null, $importData = array())
{
As4SearchEngine::setLocalStorageCacheKey();
$obj = parent::duplicateObject();
if (!Validate::isLoadedObject($obj)) {
return false;
}
if ((int)$id_shop) {
$obj->internal_name = $this->internal_name;
$obj->active = $this->active;
} else {
$translated_string = Module::getInstanceByName('pm_advancedsearch4')->translateMultiple('duplicated_from');
$obj->internal_name = sprintf($translated_string[Context::getContext()->language->id], $this->internal_name);
$obj->active = false;
}
$obj->title = $this->title;
$obj->description = $this->description;
$obj->update();
$ret = Module::getInstanceByName('pm_advancedsearch4')->installDBCache((int)$obj->id);
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$obj->id.'` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$obj->id.'_lang` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_lang`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$obj->id.'_link` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_link`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$obj->id.'_list` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_list`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$obj->id.'` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$this->id.'`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$obj->id.'_lang` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$this->id.'_lang`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_cache_product_'.(int)$obj->id.'` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_cache_product_'.(int)$this->id.'`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_cache_product_criterion_'.(int)$obj->id.'` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_cache_product_criterion_'.(int)$this->id.'`');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_product_price_'.(int)$obj->id.'` SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_product_price_'.(int)$this->id.'`');
As4SearchEngineDb::execute('UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$obj->id.'` SET `id_search` = '.(int)$obj->id);
$criterionsGroupsImages = As4SearchEngineDb::query('SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$obj->id.'_lang` WHERE `icon`!=""');
if ($criterionsGroupsImages && AdvancedSearchCoreClass::_isFilledArray($criterionsGroupsImages)) {
foreach ($criterionsGroupsImages as $criterionGroupImage) {
if ($criterionGroupImage['icon'] && Tools::file_exists_cache(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions_group/'.$criterionGroupImage['icon'])) {
$newImageName = uniqid(AdvancedSearchCoreClass::$_module_prefix . mt_rand()).'.'.AdvancedSearchCoreClass::_getFileExtension($criterionGroupImage['icon']);
if (copy(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions_group/' . $criterionGroupImage['icon'], _PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions_group/' . $newImageName)) {
Db::getInstance()->update(
'pm_advancedsearch_criterion_group_'.(int)$obj->id.'_lang',
array(
'icon' => $newImageName,
),
'id_criterion_group = '.(int)$criterionGroupImage['id_criterion_group'].' AND id_lang = '.(int)$criterionGroupImage['id_lang']
);
}
}
}
}
$criterionsImages = As4SearchEngineDb::query('SELECT * FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$obj->id.'_lang` WHERE `icon`!=""');
if ($criterionsImages && AdvancedSearchCoreClass::_isFilledArray($criterionsImages)) {
foreach ($criterionsImages as $criterionsImage) {
if ($criterionsImage['icon'] && Tools::file_exists_cache(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/'.$criterionsImage['icon'])) {
$newImageName = uniqid(AdvancedSearchCoreClass::$_module_prefix . mt_rand()).'.'.AdvancedSearchCoreClass::_getFileExtension($criterionsImage['icon']);
if (copy(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/' . $criterionsImage['icon'], _PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/' . $newImageName)) {
Db::getInstance()->update(
'pm_advancedsearch_criterion_'.(int)$obj->id.'_lang',
array(
'icon' => $newImageName,
),
'id_criterion = '.(int)$criterionsImage['id_criterion'].' AND id_lang = '.(int)$criterionsImage['id_lang']
);
}
}
}
}
if ((int)$id_shop) {
$categoryListCondition = '';
if (isset($importData['categoryList']) && is_array($importData['categoryList']) && sizeof($importData['categoryList'])) {
$categoryListCondition = ' AND `id_category` IN (' . implode(',', array_map('intval', $importData['categoryList'])) . ')';
}
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_category` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_category` FROM `'._DB_PREFIX_.'pm_advancedsearch_category` WHERE `id_search` = '.(int)$this->id . $categoryListCondition . ')');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_products_cat` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_category` FROM `'._DB_PREFIX_.'pm_advancedsearch_products_cat` WHERE `id_search` = '.(int)$this->id . $categoryListCondition . ')');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_products` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_product` FROM `'._DB_PREFIX_.'pm_advancedsearch_products` WHERE `id_search` = '.(int)$this->id.')');
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_special_pages` (SELECT "'.(int)$obj->id.'" AS `id_search`, `page` FROM `'._DB_PREFIX_.'pm_advancedsearch_special_pages` WHERE `id_search` = '.(int)$this->id.')');
if (isset($importData['cms'])) {
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_cms` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_cms` FROM `'._DB_PREFIX_.'pm_advancedsearch_cms` WHERE `id_search` = '.(int)$this->id.')');
}
if (isset($importData['manufacturer'])) {
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_manufacturers` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_manufacturer` FROM `'._DB_PREFIX_.'pm_advancedsearch_manufacturers` WHERE `id_search` = '.(int)$this->id.')');
}
if (isset($importData['supplier'])) {
$ret &= As4SearchEngineDb::execute('INSERT INTO `'._DB_PREFIX_.'pm_advancedsearch_suppliers` (SELECT "'.(int)$obj->id.'" AS `id_search`, `id_supplier` FROM `'._DB_PREFIX_.'pm_advancedsearch_suppliers` WHERE `id_search` = '.(int)$this->id.')');
}
}
if ((int)$id_shop) {
Db::getInstance()->update(
'pm_advancedsearch_shop',
array(
'id_shop' => (int)$id_shop,
),
'id_search = '.(int)$obj->id
);
Db::getInstance()->update(
'pm_advancedsearch_product_price_'.(int)$obj->id,
array(
'id_shop' => (int)$id_shop,
)
);
}
if ($ret) {
$ret = $obj;
}
return $ret;
}
public function delete()
{
As4SearchEngine::setLocalStorageCacheKey();
$ret = parent::delete();
$this->cleanAssociation('pm_advancedsearch_cms');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_shop`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_lang`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_link`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id.'_list`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$this->id.'`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int)$this->id.'_lang`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_cache_product_'.(int)$this->id.'`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_cache_product_criterion_'.(int)$this->id.'`');
As4SearchEngineDb::execute('DROP TABLE IF EXISTS `'._DB_PREFIX_.'pm_advancedsearch_product_price_'.(int)$this->id.'`');
AdvancedSearchSeoClass::deleteByIdSearch($this->id);
return $ret;
}
public function addAssociations($associations, $asso_table, $asso_identifier, $cleanBefore = true)
{
if ($cleanBefore) {
$this->cleanAssociation($asso_table);
}
foreach ($associations as $value) {
$value = trim($value);
if (!$value) {
continue;
}
$row = array($this->identifier => (int)$this->id, $asso_identifier => $value);
Db::getInstance()->insert($asso_table, $row);
}
}
public function cleanAssociation($asso_table)
{
As4SearchEngineDb::execute('DELETE FROM `' . bqSQL(_DB_PREFIX_ . $asso_table) . '` WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id);
}
}

View File

@@ -0,0 +1,590 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdvancedSearchCriterionClass extends ObjectModel
{
public $id;
public $id_criterion_group;
public $id_criterion_linked;
public $value;
public $decimal_value;
public $url_identifier;
public $url_identifier_original;
public $icon;
public $color;
public $visible = 1;
public $level_depth;
public $id_parent;
public $position;
public $is_custom;
protected $tables = array('pm_advancedsearch_criterion','pm_advancedsearch_criterion_lang');
protected $originalTables = array('pm_advancedsearch_criterion','pm_advancedsearch_criterion_lang');
public $id_search;
protected $fieldsRequired = array('id_criterion_group');
protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsRequiredLang = array();
protected $fieldsSizeLang = array();
protected $fieldsValidateLang = array('value'=>'isString');
protected $originalTable = 'pm_advancedsearch_criterion';
protected $table = 'pm_advancedsearch_criterion';
public $identifier = 'id_criterion';
public static $definition = array(
'table' => 'pm_advancedsearch_criterion',
'primary' => 'id_criterion',
'multishop' => false,
'fields' => array(
'value' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false, 'validate' => 'isString'),
'decimal_value' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'url_identifier' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false, 'validate' => 'isString'),
'url_identifier_original' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false, 'validate' => 'isString'),
'icon' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false)
)
);
private function overrideTableDefinition($id_search)
{
$this->id_search = ((int)$id_search ? (int)$id_search : (Tools::getIsset('id_search') && Tools::getValue('id_search') ? (int)Tools::getValue('id_search') : false));
if (empty($this->id_search)) {
die('Missing id_search');
}
$className = get_class($this);
self::$definition['table'] = $this->originalTable . '_' . (int)$this->id_search;
self::$definition['classname'] = $className . '_' . (int)$this->id_search;
$this->def['table'] = $this->originalTable . '_' . (int)$this->id_search;
$this->def['classname'] = $className . '_' . (int)$this->id_search;
if (isset(ObjectModel::$loaded_classes) && isset(ObjectModel::$loaded_classes[$className])) {
unset(ObjectModel::$loaded_classes[$className]);
}
$this->table = $this->originalTable . '_' . (int)$this->id_search;
foreach ($this->originalTables as $key => $table) {
$this->tables[$key] = $table . '_' . (int)$this->id_search;
}
}
protected function setDefinitionRetrocompatibility()
{
parent::setDefinitionRetrocompatibility();
$this->overrideTableDefinition((int)$this->id_search);
}
public function __construct($id_criterion = null, $id_search = null, $id_lang = null, $id_shop = null)
{
$this->overrideTableDefinition((int)$id_search);
parent::__construct($id_criterion, $id_lang, $id_shop);
if ($this->id && !isset($this->id_criterion_linked)) {
$id_criterion_link = self::getIdCriterionLinkByIdCriterion($this->id_search, $this->id);
if ($id_criterion_link !== false) {
$this->id_criterion_linked = $id_criterion_link;
}
unset($id_criterion_link);
}
}
public function save($null_values = false, $autodate = true)
{
$this->setUrlIdentifier();
$saveResult = parent::save($null_values, $autodate);
if ($saveResult) {
self::populateCriterionsLink((int)$this->id_search, $this->id, $this->id_criterion_linked);
self::addCriterionToList((int)$this->id_search, $this->id, $this->id);
}
return $saveResult;
}
public function setUrlIdentifier()
{
if (is_array($this->value)) {
foreach (array_keys($this->value) as $idLang) {
$this->url_identifier[$idLang] = str_replace('-', '_', Tools::str2url($this->value[$idLang]));
$this->url_identifier_original[$idLang] = str_replace('-', '_', Tools::str2url($this->value[$idLang]));
}
} else {
$this->url_identifier = str_replace('-', '_', Tools::str2url($this->value));
$this->url_identifier_original = str_replace('-', '_', Tools::str2url($this->value));
}
}
public function __destruct()
{
if (is_object($this)) {
$class = get_class($this);
if (method_exists('Cache', 'clean')) {
Cache::clean('objectmodel_def_'.$class);
}
if (method_exists($this, 'clearCache')) {
$this->clearCache(true);
}
}
}
public function delete()
{
if (isset($this->icon) && AdvancedSearchCoreClass::_isFilledArray($this->icon)) {
foreach ($this->icon as $icon) {
if ($icon && Tools::file_exists_cache(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/'.$icon)) {
@unlink(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions/'.$icon);
}
}
}
As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id_search.'_link` WHERE `'.bqSQL($this->identifier).'` = '.(int)$this->id);
As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$this->id_search.'_list` WHERE `id_criterion_parent` = ' . (int)$this->id . ' OR `id_criterion` = ' . (int)$this->id);
As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_cache_product_criterion_'.(int)$this->id_search.'` WHERE `id_criterion` = '.(int)$this->id);
return parent::delete();
}
public function getFields()
{
parent::validateFields();
$fields = array();
if (isset($this->id)) {
$fields['id_criterion'] = (int)$this->id;
}
$fields['id_criterion_group'] = (int)$this->id_criterion_group;
$fields['level_depth'] = (int)$this->level_depth;
$fields['color'] = pSQL($this->color);
$fields['visible'] = (int)$this->visible;
$fields['id_parent'] = (int)$this->id_parent;
$fields['position'] = (int)$this->position;
$fields['is_custom'] = (int)$this->is_custom;
return $fields;
}
public function getTranslationsFieldsChild()
{
parent::validateFieldsLang();
$res = parent::getTranslationsFields(array('value', 'decimal_value', 'url_identifier', 'url_identifier_original', 'icon'));
if (is_array($this->value)) {
foreach ($this->value as $idLangCriterionTmp => $criterionValueTmp) {
if ($criterionValueTmp === '0') {
$res[$idLangCriterionTmp]['value'] = '0';
}
}
}
if (is_array($res)) {
foreach (array_keys($res) as $idLang) {
$res[$idLang]['url_identifier'] = str_replace('-', '_', Tools::str2url($res[$idLang]['value']));
$res[$idLang]['url_identifier_original'] = str_replace('-', '_', Tools::str2url($res[$idLang]['value']));
}
}
return $res;
}
private static $getCriterionsListByIdCriterionGroupCache = array();
public static function getCriterionsListByIdCriterionGroup($idSearch, $idCriterionGroup)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsListByIdCriterionGroupCache[$cacheKey])) {
return self::$getCriterionsListByIdCriterionGroupCache[$cacheKey];
}
$results = As4SearchEngineDb::query('
SELECT aclink.`id_criterion`, aclink.`id_criterion_linked`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $idSearch.'` acg
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'` ac ON (ac.`id_criterion_group` = '.(int)$idCriterionGroup.' AND ac.`id_criterion_group` = acg.`id_criterion_group`)
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'_link` aclink ON (ac.`is_custom` = 0 AND ac.`id_criterion` = aclink.`id_criterion`)');
self::$getCriterionsListByIdCriterionGroupCache[$cacheKey] = array();
if (is_array($results)) {
foreach ($results as $row) {
self::$getCriterionsListByIdCriterionGroupCache[$cacheKey][(int)$row['id_criterion']] = (int)$row['id_criterion_linked'];
}
}
return self::$getCriterionsListByIdCriterionGroupCache[$cacheKey];
}
private static $getCriterionsValueListByIdCriterionGroupCache = array();
public static function getCriterionsValueListByIdCriterionGroup($idSearch, $idCriterionGroup)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsValueListByIdCriterionGroupCache[$cacheKey])) {
return self::$getCriterionsValueListByIdCriterionGroupCache[$cacheKey];
}
$defaultIdLang = (int)Configuration::get('PS_LANG_DEFAULT');
$results = As4SearchEngineDb::query('
SELECT ac.`id_criterion`, acl.`value`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'` ac
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int)$defaultIdLang.')
WHERE ac.`id_criterion_group`='.(int)$idCriterionGroup.' AND ac.`is_custom` = 0');
self::$getCriterionsValueListByIdCriterionGroupCache[$cacheKey] = array();
if (is_array($results)) {
foreach ($results as $row) {
self::$getCriterionsValueListByIdCriterionGroupCache[$cacheKey][(int)$row['id_criterion']] = Tools::strtolower(trim($row['value']));
}
}
return self::$getCriterionsValueListByIdCriterionGroupCache[$cacheKey];
}
private static $getCriterionsStaticIdCache = array();
public static function getCriterionsStatic($id_search, $idCriterionGroup, $id_lang = false)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsStaticIdCache[$cacheKey])) {
return self::$getCriterionsStaticIdCache[$cacheKey];
}
self::$getCriterionsStaticIdCache[$cacheKey] = As4SearchEngineDb::query('SELECT ac.* '.((int) $id_lang ? ', acl.*':'').'
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
'.($id_lang ? 'LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $id_lang.')' : '').'
WHERE ac.`id_criterion_group` = '.(int)$idCriterionGroup);
return self::$getCriterionsStaticIdCache[$cacheKey];
}
private static $getCustomCriterionsCache = array();
public static function getCustomCriterions($idSearch, $idCriterionGroup, $idLang = false)
{
$cacheKey = $idSearch.'-'.(int)$idCriterionGroup.'-'.(int)$idLang;
if (isset(self::$getCustomCriterionsCache[$cacheKey])) {
return self::$getCustomCriterionsCache[$cacheKey];
} else {
$result = As4SearchEngineDb::query('SELECT ac.* '.((int) $idLang ? ', acl.*':'').'
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'` ac
'.($idLang ? 'LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $idLang.')' : '').'
WHERE ac.`is_custom`=1
AND ac.`id_criterion_group` = '.(int)$idCriterionGroup);
}
self::$getCustomCriterionsCache[$cacheKey] = array();
if (is_array($result) && sizeof($result)) {
foreach ($result as $row) {
self::$getCustomCriterionsCache[$cacheKey][$row['id_criterion']] = $row['value'];
}
}
return self::$getCustomCriterionsCache[$cacheKey];
}
private static $getIdCriterionsGroupByIdCriterionCache = array();
public static function getIdCriterionsGroupByIdCriterion($id_search, $selected_criterion, $visible = false)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionsGroupByIdCriterionCache[$cacheKey])) {
return self::$getIdCriterionsGroupByIdCriterionCache[$cacheKey];
}
$results = As4SearchEngineDb::query('
SELECT DISTINCT ac.`id_criterion_group`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
WHERE ac.`id_criterion` IN ('.implode(',', array_map('intval', $selected_criterion)).')
'.($visible ? ' AND `visible` = 1' : ''));
$return = array();
foreach ($results as $row) {
$return[] = $row['id_criterion_group'];
}
self::$getIdCriterionsGroupByIdCriterionCache[$cacheKey] = $return;
return self::$getIdCriterionsGroupByIdCriterionCache[$cacheKey];
}
private static $getCriterionsByIdCache = array();
public static function getCriterionsById($id_search, $id_lang, $selected_criterion, $visible = false)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsByIdCache[$cacheKey])) {
return self::$getCriterionsByIdCache[$cacheKey];
}
self::$getCriterionsByIdCache[$cacheKey] = As4SearchEngineDb::query('
SELECT ac.* '.((int) $id_lang ? ', acl.*':'').'
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
'.($id_lang ? 'LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $id_lang.')' : '').'
WHERE ac.`id_criterion` IN ('.implode(',', array_map('intval', $selected_criterion)).')
'.($visible ? ' AND `visible` = 1' : ''));
return self::$getCriterionsByIdCache[$cacheKey];
}
private static $getCriterionValueByIdCache = array();
public static function getCriterionValueById($id_search, $id_lang, $id_criterion)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionValueByIdCache[$cacheKey])) {
return self::$getCriterionValueByIdCache[$cacheKey];
}
self::$getCriterionValueByIdCache[$cacheKey] = As4SearchEngineDb::row('
SELECT ac.`id_criterion`, acl.`value`, ac.`visible`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $id_lang.')
WHERE ac.`id_criterion` = '.(int)$id_criterion);
return self::$getCriterionValueByIdCache[$cacheKey];
}
private static $getIdCriterionByTypeAndIdLinkedCache = array();
public static function getIdCriterionByTypeAndIdLinked($id_search, $idCriterionGroup, $id_criterion_linked)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionByTypeAndIdLinkedCache[$cacheKey])) {
return self::$getIdCriterionByTypeAndIdLinkedCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT ac.`id_criterion`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_link` aclink ON (ac.`is_custom` = 0 AND ac.`id_criterion` = aclink.`id_criterion`)
WHERE ac.`id_criterion_group` = '.(int)$idCriterionGroup.' AND aclink.`id_criterion_linked` = '.(int)$id_criterion_linked);
if (isset($row['id_criterion']) and $row['id_criterion']) {
self::$getIdCriterionByTypeAndIdLinkedCache[$cacheKey] = (int)$row['id_criterion'];
return self::$getIdCriterionByTypeAndIdLinkedCache[$cacheKey];
}
return 0;
}
private static $getIdCriterionByTypeAndValueCache = array();
public static function getIdCriterionByTypeAndValue($id_search, $idCriterionGroup, $id_lang, $criterion_value)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionByTypeAndValueCache[$cacheKey])) {
return self::$getIdCriterionByTypeAndValueCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT ac.`id_criterion`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $id_lang.')
WHERE ac.`id_criterion_group` = '.(int)$idCriterionGroup.'
AND TRIM(acl.`value`) LIKE "'.pSQL(trim($criterion_value)).'"');
if (isset($row['id_criterion']) and $row['id_criterion']) {
self::$getIdCriterionByTypeAndValueCache[$cacheKey] = (int)$row['id_criterion'];
return self::$getIdCriterionByTypeAndValueCache[$cacheKey];
}
return 0;
}
private static $getIdCriteriongByURLIdentifierCache = array();
public static function getIdCriteriongByURLIdentifier($idSearch, $idCriterionGroup, $idLang, $name)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriteriongByURLIdentifierCache[$cacheKey])) {
return self::$getIdCriteriongByURLIdentifierCache[$cacheKey];
}
$idCriterion = As4SearchEngineDb::value('
SELECT ac.`id_criterion`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$idSearch . '` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$idSearch . '_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = ' . (int)$idLang . ')
WHERE ac.`id_criterion_group` = ' . (int)$idCriterionGroup.'
AND acl.`url_identifier`="'. pSQL($name) .'"');
if ($idCriterion) {
self::$getIdCriteriongByURLIdentifierCache[$cacheKey] = (int)$idCriterion;
return self::$getIdCriteriongByURLIdentifierCache[$cacheKey];
}
return 0;
}
private static $getIdCriterionGroupByIdCriterionCache = array();
public static function getIdCriterionGroupByIdCriterion($id_search, $id_criterion)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionGroupByIdCriterionCache[$cacheKey])) {
return self::$getIdCriterionGroupByIdCriterionCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT ac.`id_criterion_group`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
WHERE ac.`id_criterion` = "'.(int)($id_criterion).'"');
if (isset($row['id_criterion_group']) and $row['id_criterion_group']) {
self::$getIdCriterionGroupByIdCriterionCache[$cacheKey] = (int)$row['id_criterion_group'];
return self::$getIdCriterionGroupByIdCriterionCache[$cacheKey];
}
return 0;
}
public static function getCustomCriterionsLinkIds($idSearch, $criterions, $uniqueValues = true)
{
static $getCustomCriterionsLinkIdsCache = array();
if (!isset($getCustomCriterionsLinkIdsCache[$idSearch])) {
$result = As4SearchEngineDb::query('
SELECT aclist.`id_criterion_parent`, aclist.`id_criterion`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'_list` aclist ON (ac.`id_criterion` = aclist.`id_criterion_parent`)
WHERE ac.`is_custom`=1');
if (is_array($result) && sizeof($result)) {
foreach ($result as $row) {
$getCustomCriterionsLinkIdsCache[$idSearch][(int)$row['id_criterion_parent']][] = (int)$row['id_criterion'];
}
} else {
$getCustomCriterionsLinkIdsCache[$idSearch] = array();
}
}
$listToReturn = array();
$uniqueListToReturn = array();
foreach ($criterions as $idCriterion) {
if (!isset($listToReturn[$idCriterion])) {
$listToReturn[$idCriterion] = array();
}
if (isset($getCustomCriterionsLinkIdsCache[$idSearch][$idCriterion])) {
$listToReturn[$idCriterion] += $getCustomCriterionsLinkIdsCache[$idSearch][$idCriterion];
$uniqueListToReturn = array_merge($uniqueListToReturn, $getCustomCriterionsLinkIdsCache[$idSearch][$idCriterion]);
} else {
$listToReturn[$idCriterion] += array($idCriterion);
$uniqueListToReturn = array_merge($uniqueListToReturn, array($idCriterion));
}
}
if ($uniqueValues) {
return array_unique($uniqueListToReturn);
} else {
return $listToReturn;
}
}
private static $getCustomCriterionsLinkIdsByGroupCache = array();
public static function getCustomCriterionsLinkIdsByGroup($idSearch, $idCriterionGroup)
{
$cacheKey = $idSearch.'-'.$idCriterionGroup;
if (isset(self::$getCustomCriterionsLinkIdsByGroupCache[$cacheKey])) {
return self::$getCustomCriterionsLinkIdsByGroupCache[$cacheKey];
} else {
$result = As4SearchEngineDb::query('
SELECT aclist.`id_criterion_parent`, aclist.`id_criterion`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'_list` aclist ON (ac.`id_criterion` = aclist.`id_criterion_parent`)
WHERE ac.`is_custom`=1 AND ac.`id_criterion_group`=' . (int)$idCriterionGroup);
}
self::$getCustomCriterionsLinkIdsByGroupCache[$cacheKey] = array();
if (is_array($result) && sizeof($result)) {
foreach ($result as $row) {
self::$getCustomCriterionsLinkIdsByGroupCache[$cacheKey][(int)$row['id_criterion_parent']][] = (int)$row['id_criterion'];
}
}
return self::$getCustomCriterionsLinkIdsByGroupCache[$cacheKey];
}
private static $getCustomMasterIdCriterionCache = array();
public static function getCustomMasterIdCriterion($idSearch, $idCriterion)
{
$cacheKey = $idSearch.'-'.(int)$idCriterion;
if (isset(self::$getCustomMasterIdCriterionCache[$cacheKey])) {
return self::$getCustomMasterIdCriterionCache[$cacheKey];
} else {
$result = As4SearchEngineDb::value('SELECT aclist.`id_criterion_parent`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $idSearch.'_list` aclist ON (ac.`id_criterion` = aclist.`id_criterion_parent`)
WHERE ac.`is_custom`=1 AND aclist.`id_criterion`='.(int)$idCriterion);
}
if ($result > 0) {
self::$getCustomMasterIdCriterionCache[$cacheKey] = (int)$result;
} else {
self::$getCustomMasterIdCriterionCache[$cacheKey] = false;
}
return self::$getCustomMasterIdCriterionCache[$cacheKey];
}
private static $getIdCriterionLinkByIdCriterionCache = array();
public static function getIdCriterionLinkByIdCriterion($id_search, $criterionsList)
{
if (!is_array($criterionsList)) {
$criterionsList = array((int)$criterionsList);
}
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionLinkByIdCriterionCache[$cacheKey])) {
return self::$getIdCriterionLinkByIdCriterionCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT GROUP_CONCAT(`id_criterion_linked`) as `id_criterion_linked`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$id_search . '_link`
WHERE `id_criterion` IN (' . implode(', ', array_map('intval', $criterionsList)) . ')');
self::$getIdCriterionLinkByIdCriterionCache[$cacheKey] = isset($row['id_criterion_linked']) ? array_map('intval', explode(',', $row['id_criterion_linked'])) : false;
return self::$getIdCriterionLinkByIdCriterionCache[$cacheKey];
}
private static $getCriterionsByCategoryParentIdCache = array();
public static function getCriterionsByCategoryParentId($id_search, $id_criterion_group, $id_lang, $id_parent, $level_depth = false)
{
$cacheKey = (int)$id_search.'-'.(int)$id_criterion_group.'-'.(int)$id_lang.'-'.(int)$id_parent;
if (isset(self::$getCriterionsByCategoryParentIdCache[$cacheKey])) {
return self::$getCriterionsByCategoryParentIdCache[$cacheKey];
} else {
$result = As4SearchEngineDb::query('
SELECT ac.`id_criterion`, acl.`value`, ac.`id_parent`, ac.`level_depth`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'` ac
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int) $id_search.'_lang` acl ON (ac.`id_criterion` = acl.`id_criterion` AND acl.`id_lang` = '.(int) $id_lang.')
WHERE ac.`id_criterion_group` = '.(int)$id_criterion_group.'
AND ac.`id_parent` = '.(int)$id_parent.'
ORDER BY '.($level_depth ? 'ac.`level_depth`, ' : '').' ac.`position`');
}
self::$getCriterionsByCategoryParentIdCache[$cacheKey] = array();
if (is_array($result) && sizeof($result)) {
foreach ($result as $row) {
$row['nb_product'] = As4SearchEngineDb::value('
SELECT COUNT(`id_cache_product`) as `nb_product`
FROM `'._DB_PREFIX_.'pm_advancedsearch_cache_product_criterion_'.(int) $id_search.'` acpc
WHERE acpc.`id_criterion` = '.(int)$row['id_criterion'].'
');
self::$getCriterionsByCategoryParentIdCache[$cacheKey][] = $row;
}
}
return self::$getCriterionsByCategoryParentIdCache[$cacheKey];
}
public static function addCriterionToList($idSearch, $idCriterionParent, $idCriterion)
{
return As4SearchEngineDb::execute('
INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_list`
(`id_criterion_parent`, `id_criterion`)
VALUES ('. (int)$idCriterionParent. ', '. (int)$idCriterion .')');
}
public static function removeCriterionFromList($idSearch, $idCriterionParent, $idCriterion)
{
return As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_list` WHERE `id_criterion_parent`='.(int)$idCriterionParent . ' AND `id_criterion`='.(int)$idCriterion);
}
public static function populateCriterionsLink($idSearch, $idCriterion, $idCriterionLinked = false, $criterionsGroupList = array())
{
As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_link` WHERE `id_criterion` = '.(int)$idCriterion);
if (!$idCriterionLinked && is_array($criterionsGroupList) && sizeof($criterionsGroupList)) {
As4SearchEngineDb::execute('INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_link` (`id_criterion`, `id_criterion_linked`)
(SELECT "'. (int)$idCriterion .'" AS `id_criterion`, `id_criterion_linked` FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_link` WHERE `id_criterion` IN (' . implode(',', array_map('intval', $criterionsGroupList)) . '))');
} elseif ($idCriterionLinked || is_array($idCriterionLinked) && sizeof($idCriterionLinked)) {
if (!is_array($idCriterionLinked)) {
$idCriterionLinked = array($idCriterionLinked);
}
foreach ($idCriterionLinked as $idCriterionLinkedValue) {
As4SearchEngineDb::execute('INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_link` (`id_criterion`, `id_criterion_linked`) VALUES ('. (int)$idCriterion. ', '. (int)$idCriterionLinkedValue .')');
}
} elseif (!$idCriterionLinked) {
As4SearchEngineDb::execute('INSERT IGNORE INTO `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$idSearch.'_link` (`id_criterion`, `id_criterion_linked`) VALUES ('. (int)$idCriterion. ', 0)');
}
}
public static function forceUniqueUrlIdentifier($idSearch, $idCriterionGroup)
{
As4SearchEngineDb::setGroupConcatMaxLength();
$duplicateIdentifier = As4SearchEngineDb::query('
SELECT acl.`id_lang`, acl.`url_identifier_original`, GROUP_CONCAT(ac.`id_criterion`) as `id_criterion_list`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$idSearch . '` ac
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$idSearch . '_lang` acl ON (ac.`id_criterion` = acl.`id_criterion`)
WHERE ac.`id_criterion_group` = ' . (int)$idCriterionGroup.'
GROUP BY acl.`id_lang`, acl.`url_identifier_original`
HAVING COUNT(*) > 1');
foreach ($duplicateIdentifier as $duplicateIdentifierRow) {
$duplicateIdentifierRow['id_criterion_list'] = rtrim($duplicateIdentifierRow['id_criterion_list'], ',');
As4SearchEngineDb::execute('SET @i=0');
As4SearchEngineDb::execute('
UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_' . (int)$idSearch . '_lang` acl
SET acl.url_identifier = IF ((@i:=@i+1) > 1, CONCAT(acl.`url_identifier_original`, "_", @i), acl.`url_identifier_original` )
WHERE acl.`id_criterion` IN (' . pSQL($duplicateIdentifierRow['id_criterion_list']) . ')
AND acl.`id_lang` = ' . (int)$duplicateIdentifierRow['id_lang']);
}
}
public function clearCache($all = false)
{
if (!As4SearchEngineIndexation::$processingIndexation) {
parent::clearCache($all);
}
}
public function as4ForceClearCache($all = false)
{
self::$getCriterionsListByIdCriterionGroupCache = array();
self::$getCriterionsStaticIdCache = array();
self::$getCustomCriterionsCache = array();
self::$getIdCriterionsGroupByIdCriterionCache = array();
self::$getCriterionsByIdCache = array();
self::$getCriterionValueByIdCache = array();
self::$getIdCriterionByTypeAndIdLinkedCache = array();
self::$getIdCriterionByTypeAndValueCache = array();
self::$getIdCriterionGroupByIdCriterionCache = array();
self::$getCustomCriterionsLinkIdsByGroupCache = array();
self::$getCustomMasterIdCriterionCache = array();
self::$getIdCriterionLinkByIdCriterionCache = array();
parent::clearCache($all);
}
public function getHashIdentifier()
{
$idCriterionLinked = (is_array($this->id_criterion_linked) ? array_map('intval', $this->id_criterion_linked) : array((int)$this->id_criterion_linked));
sort($idCriterionLinked);
if (is_array($this->value)) {
ksort($this->value);
}
return sha1(serialize(array(
'id' => (int)$this->id,
'id_criterion_group' => (int)$this->id_criterion_group,
'id_criterion_linked' => $idCriterionLinked,
'value' => $this->value,
'decimal_value' => array_map('floatval', $this->decimal_value),
'url_identifier' => $this->url_identifier,
'url_identifier_original' => $this->url_identifier_original,
'icon' => $this->icon,
'color' => trim($this->color),
'visible' => (int)$this->visible,
'level_depth' => (int)$this->level_depth,
'id_parent' => (int)$this->id_parent,
'position' => (int)$this->position,
'is_custom' => (int)$this->is_custom,
)));
}
}

View File

@@ -0,0 +1,396 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdvancedSearchCriterionGroupClass extends ObjectModel
{
public $id;
public $id_search;
public $name;
public $url_identifier;
public $url_identifier_original;
public $icon;
public $criterion_group_type;
public $display_type = 1;
public $context_type;
public $is_multicriteria;
public $id_criterion_group_linked;
public $max_display;
public $overflow_height;
public $css_classes = 'col-xs-12 col-sm-3';
public $visible;
public $position;
public $show_all_depth;
public $only_children;
public $hidden;
public $filter_option;
public $is_combined;
public $range;
public $range_sign;
public $range_interval;
public $sort_by = 'position';
public $sort_way = 'ASC';
public $range_nb = 15;
public $all_label;
protected $tables = array('pm_advancedsearch_criterion_group','pm_advancedsearch_criterion_group_lang');
protected $originalTables = array('pm_advancedsearch_criterion_group','pm_advancedsearch_criterion_group_lang');
protected $fieldsRequired = array('id_search','criterion_group_type','display_type');
protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsRequiredLang = array('name');
protected $fieldsSizeLang = array();
protected $fieldsValidateLang = array('name'=>'isGenericName','icon'=>'isString','range_sign'=>'isGenericName','range_interval'=>'isGenericName', 'all_label'=>'isGenericName');
protected $originalTable = 'pm_advancedsearch_criterion_group';
protected $table = 'pm_advancedsearch_criterion_group';
public $identifier = 'id_criterion_group';
public static $definition = array(
'table' => 'pm_advancedsearch_criterion_group',
'primary' => 'id_criterion_group',
'multishop' => false,
'fields' => array(
'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => true),
'url_identifier' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'url_identifier_original' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'icon' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'range_sign' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'range_interval' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'all_label' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
)
);
private function overrideTableDefinition($id_search)
{
$this->id_search = ((int)$id_search ? (int)$id_search : (Tools::getIsset('id_search') && Tools::getValue('id_search') ? (int)Tools::getValue('id_search') : false));
if (empty($this->id_search)) {
die('Missing id_search');
}
$className = get_class($this);
self::$definition['table'] = $this->originalTable . '_' . (int)$this->id_search;
self::$definition['classname'] = $className . '_' . (int)$this->id_search;
$this->def['table'] = $this->originalTable . '_' . (int)$this->id_search;
$this->def['classname'] = $className . '_' . (int)$this->id_search;
if (isset(ObjectModel::$loaded_classes) && isset(ObjectModel::$loaded_classes[$className])) {
unset(ObjectModel::$loaded_classes[$className]);
}
$this->table = $this->originalTable . '_' . (int)$this->id_search;
foreach ($this->originalTables as $key => $table) {
$this->tables[$key] = $table . '_' . (int)$this->id_search;
}
}
protected function setDefinitionRetrocompatibility()
{
parent::setDefinitionRetrocompatibility();
$this->overrideTableDefinition((int)$this->id_search);
}
public function __construct($id_criterion_group = null, $id_search = null, $id_lang = null, $id_shop = null)
{
$this->overrideTableDefinition((int)$id_search);
parent::__construct($id_criterion_group, $id_lang, $id_shop);
}
public function __destruct()
{
if (is_object($this)) {
$class = get_class($this);
if (method_exists('Cache', 'clean')) {
Cache::clean('objectmodel_def_'.$class);
}
if (method_exists($this, 'clearCache')) {
$this->clearCache(true);
}
}
}
public function getFields()
{
parent::validateFields();
$fields = array();
if (isset($this->id)) {
$fields['id_criterion_group'] = (int)$this->id;
}
$fields['id_search'] = (int)$this->id_search;
$fields['criterion_group_type'] = pSQL($this->criterion_group_type);
$fields['display_type'] = (int)$this->display_type;
$fields['context_type'] = (int)$this->context_type;
$fields['is_multicriteria'] = (int)$this->is_multicriteria;
$fields['id_criterion_group_linked'] = (int)$this->id_criterion_group_linked;
$fields['max_display'] = (int)$this->max_display;
$fields['css_classes'] = pSQL($this->css_classes);
$fields['visible'] = (int)$this->visible;
$fields['position'] = (int)$this->position;
$fields['overflow_height'] = (int)$this->overflow_height;
$fields['show_all_depth'] = (int)$this->show_all_depth;
$fields['only_children'] = (int)$this->only_children;
$fields['hidden'] = (int)$this->hidden;
$fields['filter_option'] = (int)$this->filter_option;
$fields['is_combined'] = (int)$this->is_combined;
$fields['range'] = (int)$this->range;
$fields['range_nb'] = (float)$this->range_nb;
$fields['sort_by'] = pSQL($this->sort_by);
$fields['sort_way'] = pSQL($this->sort_way);
return $fields;
}
public function delete()
{
if (isset($this->icon) && AdvancedSearchCoreClass::_isFilledArray($this->icon)) {
foreach ($this->icon as $icon) {
if ($icon && Tools::file_exists_cache(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions_group/'.$icon)) {
@unlink(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/search_files/criterions_group/'.$icon);
}
}
}
if ($this->criterion_group_type == 'price') {
As4SearchEngineDb::execute('TRUNCATE TABLE `'._DB_PREFIX_.'pm_advancedsearch_product_price_'.(int)$this->id_search.'`');
}
return parent::delete();
}
public function getTranslationsFieldsChild()
{
parent::validateFieldsLang();
return parent::getTranslationsFields(array('name', 'url_identifier', 'url_identifier_original', 'icon', 'range_sign', 'range_interval', 'all_label'));
}
public function save($nullValues = false, $autodate = true)
{
if (!$this->id && $this->criterion_group_type == 'price') {
$this->display_type = 5;
}
if ($this->criterion_group_type == 'category' && $this->display_type == 9) {
$this->show_all_depth = 1;
$this->sort_by = 'o_position';
$this->sort_way = 'ASC';
} elseif ($this->criterion_group_type == 'category' && $this->display_type != 9) {
$this->context_type = 0;
}
$this->range_nb = $this->convertToPointDecimal($this->range_nb);
$ret = parent::save($nullValues, $autodate);
if (is_array($this->name)) {
foreach (array_keys($this->name) as $idLang) {
$this->url_identifier[$idLang] = str_replace('-', '_', Tools::str2url($this->name[$idLang]));
$this->url_identifier_original[$idLang] = str_replace('-', '_', Tools::str2url($this->name[$idLang]));
if (isset($this->range_interval[$idLang])) {
$this->range_interval[$idLang] = trim($this->range_interval[$idLang]);
} else {
$this->range_interval[$idLang] = '';
}
}
} else {
$this->url_identifier = str_replace('-', '_', Tools::str2url($this->name));
$this->url_identifier_original = str_replace('-', '_', Tools::str2url($this->name));
$this->range_interval = trim($this->range_interval);
}
$ret = parent::save($nullValues, $autodate);
self::forceUniqueUrlIdentifier($this->id_search);
PM_AdvancedSearch4::clearSmartyCache($this->id_search, $this->id);
return $ret;
}
protected function convertToPointDecimal($value)
{
return (float)str_replace(",", ".", $value);
}
private static $getIdCriterionGroupByTypeAndIdLinkedCache = array();
public static function getIdCriterionGroupByTypeAndIdLinked($id_search, $criterions_group_type, $id_criterion_group_linked)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionGroupByTypeAndIdLinkedCache[$cacheKey])) {
return self::$getIdCriterionGroupByTypeAndIdLinkedCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT acg.`id_criterion_group`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
WHERE acg.`criterion_group_type` = "'.pSQL($criterions_group_type).'" AND acg.`id_criterion_group_linked` = '.(int)($id_criterion_group_linked));
if (isset($row['id_criterion_group']) and $row['id_criterion_group']) {
self::$getIdCriterionGroupByTypeAndIdLinkedCache[$cacheKey] = (int)$row['id_criterion_group'];
return self::$getIdCriterionGroupByTypeAndIdLinkedCache[$cacheKey];
}
return 0;
}
private static $getCriterionsGroupsFromIdSearchCache = array();
public static function getCriterionsGroupsFromIdSearch($id_search, $id_lang = false, $visible = false)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsGroupsFromIdSearchCache[$cacheKey])) {
return self::$getCriterionsGroupsFromIdSearchCache[$cacheKey];
}
$allowPriceGroup = As4SearchEngine::allowShowPrices();
if ($id_lang) {
self::$getCriterionsGroupsFromIdSearchCache[$cacheKey] = As4SearchEngineDb::query('
SELECT acg.*, acgl.*
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'_lang` acgl ON (acg.`id_criterion_group` = acgl.`id_criterion_group` AND acgl.`id_lang` = '.((int) $id_lang).' )
WHERE acg.`id_search` = '.((int)$id_search).'
'.($visible ? ' AND `visible` = 1' : '').'
'.(!$allowPriceGroup ? ' AND acg.`criterion_group_type` != "price"' : '').'
ORDER BY `position`');
} else {
self::$getCriterionsGroupsFromIdSearchCache[$cacheKey] = As4SearchEngineDb::query('
SELECT acg.*
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
WHERE acg.`id_search` = '.((int)$id_search).'
'.($visible ? ' AND `visible` = 1' : '').'
'.(!$allowPriceGroup ? ' AND acg.`criterion_group_type` != "price"' : '').'
ORDER BY `position`');
}
return self::$getCriterionsGroupsFromIdSearchCache[$cacheKey];
}
private static $getCriterionsGroupCache = array();
public static function getCriterionsGroup($id_search, $id_criterion_group, $id_lang)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsGroupCache[$cacheKey])) {
return self::$getCriterionsGroupCache[$cacheKey];
}
$allowPriceGroup = As4SearchEngine::allowShowPrices();
self::$getCriterionsGroupCache[$cacheKey] = As4SearchEngineDb::query('
SELECT acg.*, acgl.*
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'_lang` acgl ON (acg.`id_criterion_group` = acgl.`id_criterion_group` AND acgl.`id_lang` = '.((int) $id_lang).' )
WHERE acg.`id_criterion_group` '.((is_array($id_criterion_group) ? 'IN ('.implode(',', array_map('intval', $id_criterion_group)).')':'='.(int)$id_criterion_group)).'
'.(!$allowPriceGroup ? ' AND acg.`criterion_group_type` != "price"' : '').'
ORDER BY `position`');
return self::$getCriterionsGroupCache[$cacheKey];
}
private static $getCriterionsGroupByTypeCache = array();
public static function getCriterionsGroupByType($idSearch, $groupType)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionsGroupByTypeCache[$cacheKey])) {
return self::$getCriterionsGroupByTypeCache[$cacheKey];
}
self::$getCriterionsGroupByTypeCache[$cacheKey] = As4SearchEngineDb::query('
SELECT *
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'. (int)$idSearch .'`
WHERE criterion_group_type="'. pSQL($groupType) .'"
');
return self::$getCriterionsGroupByTypeCache[$cacheKey];
}
private static $getIdCriterionsGroupByURLIdentifierCache = array();
public static function getIdCriterionsGroupByURLIdentifier($idSearch, $idLang, $name)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getIdCriterionsGroupByURLIdentifierCache[$cacheKey])) {
return self::$getIdCriterionsGroupByURLIdentifierCache[$cacheKey];
}
self::$getIdCriterionsGroupByURLIdentifierCache[$cacheKey] = As4SearchEngineDb::value('
SELECT acg.`id_criterion_group`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_' . (int)$idSearch . '` acg
JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_' . (int)$idSearch . '_lang` acgl ON (acg.`id_criterion_group` = acgl.`id_criterion_group` AND acgl.`id_lang` = ' . (int)$idLang . ')
WHERE acg.visible = 1
AND acgl.`url_identifier`="'. pSQL($name) .'"');
return self::$getIdCriterionsGroupByURLIdentifierCache[$cacheKey];
}
private static $getNextIdCriterionGroupCache = array();
public static function getNextIdCriterionGroup($id_search, $id_criterion_group)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getNextIdCriterionGroupCache[$cacheKey])) {
return self::$getNextIdCriterionGroupCache[$cacheKey];
}
$result = As4SearchEngineDb::query('
SELECT acg.`id_criterion_group`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
WHERE `visible` = 1
ORDER BY acg.`position`');
$return = false;
foreach ($result as $row) {
if ($return) {
self::$getNextIdCriterionGroupCache[$cacheKey] = $row['id_criterion_group'];
return self::$getNextIdCriterionGroupCache[$cacheKey];
}
if ($row['id_criterion_group'] == $id_criterion_group) {
$return = true;
}
}
self::$getNextIdCriterionGroupCache[$cacheKey] = false;
return self::$getNextIdCriterionGroupCache[$cacheKey];
}
private static $getCriterionGroupTypeAndRangeSignCache = array();
public static function getCriterionGroupTypeAndRangeSign($id_search, $id_criterion_group, $id_lang)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionGroupTypeAndRangeSignCache[$cacheKey])) {
return self::$getCriterionGroupTypeAndRangeSignCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT acgl.`range_sign`, acg.`criterion_group_type`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'_lang` acgl ON (acg.`id_criterion_group` = acgl.`id_criterion_group` AND acgl.`id_lang` = '.((int) $id_lang).' )
WHERE acg.`id_criterion_group` = '.(int)$id_criterion_group);
self::$getCriterionGroupTypeAndRangeSignCache[$cacheKey] = (isset($row['range_sign'])) ? $row : '';
return self::$getCriterionGroupTypeAndRangeSignCache[$cacheKey];
}
private static $getCriterionGroupTypeCache = array();
public static function getCriterionGroupType($id_search, $id_criterion_group)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCriterionGroupTypeCache[$cacheKey])) {
return self::$getCriterionGroupTypeCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT acg.`criterion_group_type`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
WHERE acg.`id_criterion_group` = '.(int)$id_criterion_group);
self::$getCriterionGroupTypeCache[$cacheKey] = (isset($row['criterion_group_type'])) ? $row['criterion_group_type'] : false;
return self::$getCriterionGroupTypeCache[$cacheKey];
}
public static function disableAllCriterions($id_search, $id_criterion_group)
{
$result = As4SearchEngineDb::execute('
UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$id_search.'`
SET visible = 0
WHERE id_criterion_group = '.(int)$id_criterion_group);
return $result;
}
public static function enableAllCriterions($id_search, $id_criterion_group)
{
$result = As4SearchEngineDb::execute('
UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_'.(int)$id_search.'`
SET visible = 1
WHERE id_criterion_group = '.(int)$id_criterion_group);
return $result;
}
public static function forceUniqueUrlIdentifier($idSearch)
{
As4SearchEngineDb::setGroupConcatMaxLength();
$duplicateIdentifier = As4SearchEngineDb::query('
SELECT acgl.`id_lang`, GROUP_CONCAT(acgl.`id_criterion_group`) as `id_criterion_group_list`
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_' . (int)$idSearch . '_lang` acgl
GROUP BY acgl.`id_lang`, acgl.`url_identifier_original`
HAVING COUNT(*) > 1');
foreach ($duplicateIdentifier as $duplicateIdentifierRow) {
$duplicateIdentifierRow['id_criterion_group_list'] = rtrim($duplicateIdentifierRow['id_criterion_group_list'], ',');
As4SearchEngineDb::execute('SET @i=0');
As4SearchEngineDb::execute('
UPDATE `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_' . (int)$idSearch . '_lang` acgl
SET acgl.url_identifier = IF ((@i:=@i+1) > 1, CONCAT(acgl.`url_identifier_original`, "_", @i), acgl.`url_identifier_original` )
WHERE acgl.`id_criterion_group` IN (' . pSQL($duplicateIdentifierRow['id_criterion_group_list']) . ')
AND acgl.`id_lang` = ' . (int)$duplicateIdentifierRow['id_lang']);
}
}
public function clearCache($all = false)
{
if (!As4SearchEngineIndexation::$processingIndexation) {
parent::clearCache($all);
}
}
public function as4ForceClearCache($all = false)
{
self::$getIdCriterionGroupByTypeAndIdLinkedCache = array();
self::$getCriterionsGroupsFromIdSearchCache = array();
self::$getCriterionsGroupCache = array();
self::$getNextIdCriterionGroupCache = array();
self::$getCriterionGroupTypeAndRangeSignCache = array();
self::$getCriterionGroupTypeCache = array();
parent::clearCache($all);
}
}

View File

@@ -0,0 +1,354 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class AdvancedSearchSeoClass extends ObjectModel
{
public $id;
public $id_search;
public $id_currency;
public $meta_title;
public $meta_description;
public $meta_keywords;
public $title;
public $seo_url;
public $description;
public $criteria;
public $deleted;
public $seo_key;
public $cross_links;
protected $tables = array('pm_advancedsearch_seo','pm_advancedsearch_seo_lang');
protected $fieldsRequired = array('id_search','criteria','seo_key');
protected $fieldsSize = array();
protected $fieldsValidate = array();
protected $fieldsRequiredLang = array(
'meta_title',
'meta_description',
'title',
'seo_url',
);
protected $fieldsSizeLang = array(
'meta_title' => 128,
'meta_description' => 255,
'title' => 128,
'seo_url' => 128,
'meta_keywords' => 255,
);
protected $fieldsValidateLang = array(
'meta_title' =>'isGenericName',
'meta_description' =>'isGenericName',
'meta_keywords' =>'isGenericName',
'title' =>'isGenericName',
'description' =>'isString',
'seo_url' =>'isGenericName',
);
public static $definition = array(
'table' => 'pm_advancedsearch_seo',
'primary' => 'id_seo',
'multishop' => false,
'fields' => array(
'meta_title' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'meta_description' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'title' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'seo_url' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'meta_keywords' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
'description' => array('type' => self::TYPE_STRING, 'lang' => true, 'required' => false),
)
);
protected $table = 'pm_advancedsearch_seo';
public $identifier = 'id_seo';
public function __construct($id_seo = null, $id_lang = null, $id_shop = null)
{
parent::__construct($id_seo, $id_lang, $id_shop);
}
public function getFields()
{
parent::validateFields();
$fields = array();
if (isset($this->id)) {
$fields['id_seo'] = (int)$this->id;
}
$fields['id_search'] = (int)$this->id_search;
$fields['id_currency'] = (int)$this->id_currency;
$fields['criteria'] = pSQL($this->criteria);
$fields['deleted'] = (int)$this->deleted;
$fields['seo_key'] = pSQL($this->seo_key);
return $fields;
}
public function getTranslationsFieldsChild()
{
parent::validateFieldsLang();
$fieldsArray = array('meta_title','meta_description','title','seo_url','meta_keywords');
$fields = array();
$languages = Language::getLanguages(false);
$defaultLanguage = Configuration::get('PS_LANG_DEFAULT');
foreach ($languages as $language) {
$fields[$language['id_lang']]['id_lang'] = $language['id_lang'];
$fields[$language['id_lang']][$this->identifier] = (int)$this->id;
$fields[$language['id_lang']]['description'] = (isset($this->description[$language['id_lang']]) and !empty($this->description[$language['id_lang']])) ? pSQL($this->description[$language['id_lang']], true) : pSQL($this->description[$defaultLanguage], true);
foreach ($fieldsArray as $field) {
if (!Validate::isTableOrIdentifier($field)) {
die(Tools::displayError());
}
if (isset($this->{$field}[$language['id_lang']]) and !empty($this->{$field}[$language['id_lang']])) {
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$language['id_lang']]);
} else {
$fields[$language['id_lang']][$field] = pSQL($this->{$field}[$defaultLanguage]);
}
}
}
return $fields;
}
public function setUrlIdentifier()
{
if (is_array($this->seo_url)) {
foreach (array_keys($this->seo_url) as $idLang) {
$this->seo_url[$idLang] = Tools::str2url($this->seo_url[$idLang]);
}
} else {
$this->seo_url = Tools::str2url($this->seo_url);
}
}
public function save($nullValues = false, $autodate = true)
{
$newCriteria = array();
if (!preg_match('#\{i:#', $this->criteria)) {
$criteria = explode(',', $this->criteria);
if (sizeof($criteria)) {
foreach ($criteria as $value) {
$newCriteria[] = preg_replace('/^biscriterion_/', '', $value);
}
$this->criteria = serialize($newCriteria);
}
}
if ($this->id) {
$this->cleanCrossLinks();
}
if (!$this->id_currency) {
$this->id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
}
$this->setUrlIdentifier();
$ret = parent::save($nullValues, $autodate);
if (is_array($this->cross_links) && sizeof($this->cross_links)) {
$this->saveCrossLinks();
}
return $ret;
}
public function delete()
{
$this->cleanCrossLinks(true);
return parent::delete();
}
public static function deleteByIdSearch($id_search)
{
As4SearchEngineDb::execute('DELETE adss.*, adssl.*, ascl.* FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` )
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_crosslinks` ascl ON (ascl.`id_seo_linked` = adssl.`id_seo` )
WHERE `id_search` = '.(int)$id_search);
}
public function cleanCrossLinks($delete_seo_linked = false)
{
As4SearchEngineDb::execute('DELETE FROM `'._DB_PREFIX_.'pm_advancedsearch_seo_crosslinks` WHERE `id_seo` = '.(int)$this->id . ($delete_seo_linked ? ' OR `id_seo_linked` = '.(int)$this->id : ''));
}
public function saveCrossLinks()
{
foreach ($this->cross_links as $id_seo_linked) {
$row = array('id_seo' => (int)$this->id, 'id_seo_linked' => (int)$id_seo_linked);
Db::getInstance()->insert('pm_advancedsearch_seo_crosslinks', $row);
}
}
private static $getCrossLinksOptionsSelectedCache = array();
public function getCrossLinksOptionsSelected($id_lang)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCrossLinksOptionsSelectedCache[$cacheKey])) {
return self::$getCrossLinksOptionsSelectedCache[$cacheKey];
}
$result = As4SearchEngineDb::query('
SELECT ascl.`id_seo_linked`, adssl.`title`
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo_crosslinks` ascl
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (ascl.`id_seo_linked` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).' )
WHERE ascl.`id_seo` = '.(int)($this->id));
$return = array();
foreach ($result as $row) {
$return[$row['id_seo_linked']] = $row['title'];
}
self::$getCrossLinksOptionsSelectedCache[$cacheKey] = $return;
return self::$getCrossLinksOptionsSelectedCache[$cacheKey];
}
private static $getCrossLinksAvailableCache = array();
public static function getCrossLinksAvailable($id_lang, $id_excludes = false, $query_search = false, $count = false, $limit = false, $start = 0)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCrossLinksAvailableCache[$cacheKey])) {
return self::$getCrossLinksAvailableCache[$cacheKey];
}
if ($count) {
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
SELECT COUNT(adss.`id_seo`) AS nb
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).' )
WHERE '.($id_excludes ? ' adss.`id_seo` NOT IN ('.implode(',', array_map('intval', $id_excludes)).') AND ':'').'adss.`deleted` = 0
'.($query_search ? ' AND adssl.`title` LIKE "%'.pSQL($query_search).'%"' : '').'
ORDER BY adss.`id_seo`');
self::$getCrossLinksAvailableCache[$cacheKey] = (int)($result['nb']);
return self::$getCrossLinksAvailableCache[$cacheKey];
}
$result = As4SearchEngineDb::query('
SELECT adss.`id_seo`, adssl.`title`
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).' )
WHERE '.($id_excludes ? ' adss.`id_seo` NOT IN ('.implode(',', array_map('intval', $id_excludes)).') AND ':'').'adss.`deleted` = 0
'.($query_search ? ' AND adssl.`title` LIKE "%'.pSQL($query_search).'%"' : '').'
ORDER BY adss.`id_seo`
'.($limit? 'LIMIT '.$start.', '.(int)$limit : ''));
$return = array();
foreach ($result as $row) {
$return[$row['id_seo']] = $row['title'];
}
self::$getCrossLinksAvailableCache[$cacheKey] = $return;
return self::$getCrossLinksAvailableCache[$cacheKey];
}
private static $getSeoSearchsCache = array();
public static function getSeoSearchs($id_lang = false, $withDeleted = 0, $id_search = false)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getSeoSearchsCache[$cacheKey])) {
return self::$getSeoSearchsCache[$cacheKey];
}
self::$getSeoSearchsCache[$cacheKey] = As4SearchEngineDb::query('
SELECT *
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
'.($id_lang ? 'LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).' )' : '').'
WHERE 1
'.(!$withDeleted ? ' AND adss.`deleted` = 0':'').'
'.($id_search ? ' AND adss.`id_search` = '.(int)$id_search:'').'
GROUP BY adss.`id_seo`
ORDER BY adss.`id_seo`');
return self::$getSeoSearchsCache[$cacheKey];
}
private static $getCrossLinksSeoCache = array();
public static function getCrossLinksSeo($id_lang, $id_seo)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getCrossLinksSeoCache[$cacheKey])) {
return self::$getCrossLinksSeoCache[$cacheKey];
}
$link = Context::getContext()->link;
self::$getCrossLinksSeoCache[$cacheKey] = As4SearchEngineDb::query('
SELECT *
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_crosslinks` ascl ON (adss.`id_seo` = ascl.`id_seo_linked` )
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).' )
WHERE ascl.`id_seo` = '.(int)$id_seo.' AND adss.`id_seo` != '.(int)$id_seo.' AND adss.`deleted` = 0
GROUP BY adss.`id_seo`
ORDER BY adss.`id_seo`');
foreach (self::$getCrossLinksSeoCache[$cacheKey] as &$row) {
$params = array(
'id_seo' => $row['id_seo'],
'seo_url' => $row['seo_url'],
);
$row['public_url'] = $link->getModuleLink('pm_advancedsearch4', 'seo', $params);
}
return self::$getCrossLinksSeoCache[$cacheKey];
}
private static $getSeoSearchBySeoUrlCache = array();
public static function getSeoSearchBySeoUrl($seo_url, $id_lang)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getSeoSearchBySeoUrlCache[$cacheKey])) {
return self::$getSeoSearchBySeoUrlCache[$cacheKey];
}
self::$getSeoSearchBySeoUrlCache[$cacheKey] = As4SearchEngineDb::query('
SELECT *
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo`'.($id_lang?' AND adssl.`id_lang` = '.((int) $id_lang):'').' )
WHERE `seo_url` = "'.pSQL($seo_url).'"
LIMIT 1');
return self::$getSeoSearchBySeoUrlCache[$cacheKey];
}
private static $getSeoSearchByIdSeoCache = array();
public static function getSeoSearchByIdSeo($id_seo, $id_lang)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$getSeoSearchByIdSeoCache[$cacheKey])) {
return self::$getSeoSearchByIdSeoCache[$cacheKey];
}
self::$getSeoSearchByIdSeoCache[$cacheKey] = As4SearchEngineDb::query('
SELECT *
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` adss
LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` adssl ON (adss.`id_seo` = adssl.`id_seo` AND adssl.`id_lang` = '.((int) $id_lang).')
WHERE adss.`id_seo` = "'.((int) $id_seo).'"
GROUP BY adss.`id_seo`
LIMIT 1');
return self::$getSeoSearchByIdSeoCache[$cacheKey];
}
private static $seoExistsCache = array();
public static function seoExists($seo_key)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$seoExistsCache[$cacheKey])) {
return self::$seoExistsCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT `id_seo`
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo`
WHERE `seo_key` = "'.pSQL($seo_key).'"
AND `deleted`=0');
self::$seoExistsCache[$cacheKey] = (isset($row['id_seo']) ? $row['id_seo'] : false);
return self::$seoExistsCache[$cacheKey];
}
private static $seoDeletedExistsCache = array();
public static function seoDeletedExists($seo_key)
{
$cacheKey = sha1(serialize(func_get_args()));
if (isset(self::$seoDeletedExistsCache[$cacheKey])) {
return self::$seoDeletedExistsCache[$cacheKey];
}
$row = As4SearchEngineDb::row('
SELECT `id_seo`
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo`
WHERE `seo_key` = "'.pSQL($seo_key).'" AND `deleted` = 1');
self::$seoDeletedExistsCache[$cacheKey] = (isset($row['id_seo']) ? $row['id_seo'] : false);
return self::$seoDeletedExistsCache[$cacheKey];
}
public static function undeleteSeoBySeoKey($seo_key)
{
$row = array('deleted' => 0);
Db::getInstance()->update('pm_advancedsearch_seo', $row, '`seo_key` = "'.pSQL($seo_key).'" AND deleted = 1');
}
public static function getSeoPageUrlByKeys($seoKeys, $idLang)
{
$seoPageListTmp = As4SearchEngineDb::query('
SELECT s.`seo_key`, s.`id_seo`, sl.`seo_url`
FROM `'._DB_PREFIX_.'pm_advancedsearch_seo` s
JOIN `'._DB_PREFIX_.'pm_advancedsearch_seo_lang` sl ON (s.`id_seo`=sl.`id_seo` AND sl.`id_lang`=' . (int)$idLang . ')
WHERE s.`seo_key` IN ("'. implode('","', $seoKeys) . '")
AND s.`deleted`=0');
$seoPageList = array();
if (is_array($seoPageListTmp)) {
$context = Context::getContext();
foreach ($seoPageListTmp as $seoPage) {
$seoPageList[$seoPage['seo_key']] = array(
'id_seo' => (int)$seoPage['id_seo'],
'seo_page_url' => $context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => (int)$seoPage['id_seo'], 'seo_url' => $seoPage['seo_url'])),
);
}
}
return $seoPageList;
}
}

View File

@@ -0,0 +1,35 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
class AdvancedSearchWidgetProxy extends AdvancedSearchCoreClass implements PrestaShop\PrestaShop\Core\Module\WidgetInterface
{
public function renderWidget($hookName, array $configuration)
{
return parent::renderWidget($hookName, $configuration);
}
public function getWidgetVariables($hookName, array $configuration)
{
return parent::getWidgetVariables($hookName, $configuration);
}
}
} else {
class AdvancedSearchWidgetProxy extends AdvancedSearchCoreClass
{
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,99 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
abstract class As4SearchEngineDb
{
// Enable SQL log ?
public static $as4SqlLog = false;
// Only log if elasped time >= X ms
public static $as4SqlQueryThresholdTime = 0;
public static function query($query, $type = 1, $useArray = true, $useCache = true)
{
if (self::$as4SqlLog) {
$time = microtime(true);
$log = trim($query);
$finalOrigin = array(
'line' => 'UNKNWON',
'class' => 'UNKNWON',
'function' => 'UNKNWON',
);
$origin = debug_backtrace();
foreach ($origin as $originRow) {
if (!empty($originRow['class']) && $originRow['class'] != 'As4SearchEngineDb') {
$finalOrigin = $originRow;
break;
}
}
}
$instanceMaster = _PS_USE_SQL_SLAVE_;
if (!$useCache) {
$instanceMaster = true;
}
if ($type == 1) {
$result = Db::getInstance($instanceMaster)->ExecuteS($query, $useArray, $useCache);
} elseif ($type == 2) {
$result = Db::getInstance($instanceMaster)->getRow($query, $useCache);
} elseif ($type == 3) {
$result = Db::getInstance($instanceMaster)->getValue($query, $useCache);
} elseif ($type == 4) {
$result = Db::getInstance()->Execute($query);
}
if (self::$as4SqlLog) {
$elaspedTime = round((microtime(true) - $time)*1000, 2);
if ($elaspedTime >= self::$as4SqlQueryThresholdTime) {
$log .= "\n\n";
$log .= 'L' . $finalOrigin['line'] . ' - ' . $finalOrigin['class'] . '::' . $finalOrigin['function'] . ' => ';
$log .= $elaspedTime . 'ms';
$log .= "\n\n";
file_put_contents(dirname(__FILE__) . '/sql_log.txt', $log, FILE_APPEND);
}
}
return $result;
}
public static function queryNoCache($query, $type = 1, $useArray = true)
{
return self::query($query, $type, $useArray, false);
}
public static function row($query, $useCache = true)
{
return self::query($query, 2, true, $useCache);
}
public static function value($query, $useCache = true)
{
return self::query($query, 3, true, $useCache);
}
public static function valueList($query, $castFunction = false, $useCache = true)
{
$list = array();
foreach (self::query($query, 1, true, $useCache) as $row) {
$list[] = current($row);
}
if ($castFunction !== false) {
$list = array_map($castFunction, $list);
}
return $list;
}
public static function execute($query)
{
return self::query($query, 4);
}
public static function setGroupConcatMaxLength()
{
return self::execute('SET group_concat_max_len := @@max_allowed_packet');
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,45 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
abstract class As4SearchEngineLogger
{
const DEBUG = false;
private static $bench_start;
private static $bench_step;
public static function log($nom_etape)
{
if (self::DEBUG) {
if (!self::$bench_start) {
self::$bench_start = microtime(true);
}
if (self::$bench_step) {
$time_elapsed_step = microtime(true) - self::$bench_step;
}
self::$bench_step = microtime(true);
$time_elapsed_start = self::$bench_step - self::$bench_start;
if (!class_exists('FireLogger')) {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/lib/firelogger/FireLogger.php');
}
flog($nom_etape);
flog('=> Elasped time since start ' . $time_elapsed_start . ' s');
if (isset($time_elapsed_step)) {
flog('=> Elasped time since last step ' . $time_elapsed_step . ' s');
}
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
abstract class As4SearchEngineSeo
{
public static function getCriterionsGroupsIndexedForSEO($id_search, $id_lang = false)
{
$search = current(As4SearchEngine::getSearch($id_search, $id_lang, false));
return As4SearchEngineDb::query('
SELECT acg.* '.((int) $id_lang ? ', acgl.*':'').'
FROM `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'` acg
'.($id_lang ? 'LEFT JOIN `'._DB_PREFIX_.'pm_advancedsearch_criterion_group_'.(int) $id_search.'_lang` acgl ON (acg.`id_criterion_group` = acgl.`id_criterion_group` AND acgl.`id_lang` = '.(int) $id_lang.')' : '').'
WHERE acg.`id_search` = '.(int)($id_search).'
AND `visible` = 1 '.(isset($search['filter_by_emplacement']) && $search['filter_by_emplacement'] == 1 ? ' OR (`visible`=0 AND `criterion_group_type` IN ("category", "supplier", "manufacturer")) ' : '').'
GROUP BY acg.`id_criterion_group`
ORDER BY acg.`position`');
}
private static function sortSeoCriterion($criterions)
{
if (is_array($criterions)) {
asort($criterions);
foreach (array_keys($criterions) as $k) {
if (is_array($criterions[$k])) {
$criterions[$k] = self::sortSeoCriterion($criterions[$k]);
}
}
}
return $criterions;
}
public static function getSeoKeyFromCriteria($id_search, $criteria, $id_currency)
{
if (!$id_currency) {
$id_currency = Configuration::get('PS_CURRENCY_DEFAULT');
}
if (is_array($criteria)) {
$criteria = self::sortSeoCriterion($criteria);
}
$criteria = str_replace('biscriterion_', '', $criteria);
return md5((int)$id_search . '-' . implode('-', $criteria) . '-' . (int)$id_currency);
}
public static function addSeoPageUrlToCriterions($idSearch, &$criterionsList, $selectedCriterionsForSeo)
{
if (AdvancedSearchCoreClass::_isFilledArray($criterionsList)) {
$seoKeysList = array();
foreach ($criterionsList as &$criterion) {
$criterion['seo_key'] = self::getSeoKeyFromCriteria($idSearch, array_merge($selectedCriterionsForSeo, array((int)$criterion['id_criterion_group'].'_'.(int)$criterion['id_criterion'])), Context::getContext()->cookie->id_currency);
$seoKeysList[] = $criterion['seo_key'];
}
if (sizeof($seoKeysList)) {
$seoPageUrlByKeys = AdvancedSearchSeoClass::getSeoPageUrlByKeys($seoKeysList, (int)Context::getContext()->language->id);
foreach ($criterionsList as &$criterion) {
if (isset($seoPageUrlByKeys[$criterion['seo_key']])) {
$criterion['id_seo'] = $seoPageUrlByKeys[$criterion['seo_key']]['id_seo'];
$criterion['seo_page_url'] = $seoPageUrlByKeys[$criterion['seo_key']]['seo_page_url'];
} else {
$criterion['id_seo'] = false;
$criterion['seo_page_url'] = false;
}
}
}
}
}
}

View File

@@ -0,0 +1,80 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class LinkPM extends Link
{
public function getPaginationLink($type, $id_object, $nb = false, $sort = false, $pagination = false, $array = false)
{
$controllerName = Dispatcher::getInstance()->getController();
if (in_array($controllerName, array('seo', 'searchresults', 'advancedsearch4'))) {
if ($controllerName == 'seo') {
$params = array(
'id_seo' => (int)Tools::getValue('id_seo'),
'seo_url' => Tools::getValue('seo_url')
);
if (isset($array['p'])) {
$params['p'] = (int)$array['p'];
}
} elseif ($controllerName == 'searchresults') {
$params = array(
'id_search' => (int)Tools::getValue('id_search'),
'as4_sq' => Tools::getValue('as4_sq')
);
if (isset($array['p'])) {
$params['p'] = (int)$array['p'];
}
if (As4SearchEngine::getCurrentCategory()) {
$idCategorySearch = As4SearchEngine::getCurrentCategory();
$category = new Category($idCategorySearch, Context::getContext()->language->id);
if (Validate::isLoadedObject($category)) {
$params['id'] = $idCategorySearch;
$params['rewrite'] = $category->link_rewrite;
$controllerName .= '-categories';
}
}
} elseif ($controllerName == 'advancedsearch4') {
$selectedCriterions = Context::getContext()->controller->getCriterionsList();
return As4SearchEngine::generateURLFromCriterions((int)Tools::getValue('id_search'), $selectedCriterions, null, $array, $pagination);
}
if (Tools::getIsset('n') && (int)Tools::getValue('n') > 0) {
$params['n'] = (int)Tools::getValue('n');
}
if (Tools::getIsset('orderby') && Tools::getValue('orderby')) {
$params['orderby'] = Tools::getValue('orderby');
}
if (Tools::getIsset('orderway') && Tools::getValue('orderway')) {
$params['orderway'] = Tools::getValue('orderway');
}
$url = $this->getModuleLink('pm_advancedsearch4', $controllerName, $params);
if (!$array) {
return $url;
} else {
unset($params['id_seo']);
unset($params['seo_url']);
unset($params['id_search']);
unset($params['as4_sq']);
unset($params['id']);
unset($params['rewrite']);
$params['requestUrl'] = $url;
return $params;
}
} else {
return parent::getPaginationLink($type, $id_object, $nb, $sort, $pagination, $array);
}
}
}

View File

@@ -0,0 +1,8 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;

View File

@@ -0,0 +1,63 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchProviderInterface;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
use Symfony\Component\Translation\TranslatorInterface;
if (!defined('_PS_VERSION_')) {
exit;
}
class As4FullTreeSearchProvider implements ProductSearchProviderInterface
{
private $module;
private $translator;
private $sortOrderFactory;
public function __construct(PM_AdvancedSearch4 $module, TranslatorInterface $translator)
{
$this->module = $module;
$this->translator = $translator;
$this->sortOrderFactory = new SortOrderFactory($this->translator);
}
public function runQuery(
ProductSearchContext $context,
ProductSearchQuery $query
) {
$result = new ProductSearchResult();
$result->setAvailableSortOrders(
$this->sortOrderFactory->getDefaultSortOrders()
);
$continue = true;
$realContext = Context::getContext();
if (As4SearchEngine::isSPAModuleActive()) {
$pm_productsbyattributes = Module::getInstanceByName('pm_productsbyattributes');
if (version_compare($pm_productsbyattributes->version, '1.0.4', '>=')) {
$continue = false;
$productCount = $pm_productsbyattributes->getCategoryProducts((int)$realContext->controller->getCategory()->id_category, null, null, null, $query->getSortOrder()->toLegacyOrderBy(), $query->getSortOrder()->toLegacyOrderWay(), true, true);
$productList = $pm_productsbyattributes->getCategoryProducts((int)$realContext->controller->getCategory()->id_category, (int)$context->getIdLang(), (int)$query->getResultsPerPage(), (int)$query->getPage(), $query->getSortOrder()->toLegacyOrderBy(), $query->getSortOrder()->toLegacyOrderWay(), false, true);
$result->setTotalProductsCount($productCount);
$result->setProducts($productList);
$pm_productsbyattributes->splitProductsList($productList);
}
}
if ($continue) {
$result->setTotalProductsCount($this->module->getCategoryProducts(null, null, null, $query->getSortOrder()->toLegacyOrderBy(), $query->getSortOrder()->toLegacyOrderWay(), true));
$result->setProducts($this->module->getCategoryProducts((int)$context->getIdLang(), (int)$query->getPage(), (int)$query->getResultsPerPage(), $query->getSortOrder()->toLegacyOrderBy(), $query->getSortOrder()->toLegacyOrderWay()));
}
return $result;
}
}

View File

@@ -0,0 +1,149 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchProviderInterface;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchContext;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrderFactory;
use Symfony\Component\Translation\TranslatorInterface;
if (!defined('_PS_VERSION_')) {
exit;
}
class As4SearchProvider implements ProductSearchProviderInterface
{
private $module;
private $translator;
private $sortOrderFactory;
private $idSearch;
private $criterionsList;
private $searchInstance;
public function __construct(PM_AdvancedSearch4 $module, TranslatorInterface $translator, $searchInstance, $criterionsList)
{
$this->module = $module;
$this->translator = $translator;
$this->searchInstance = $searchInstance;
$this->idSearch = $searchInstance->id;
$this->criterionsList = $criterionsList;
$this->sortOrderFactory = new SortOrderFactory($this->translator);
}
public function getSortOrders($includeAll = false, $includeDefaultSortOrders = true)
{
$config = pm_advancedsearch4::getModuleConfigurationStatic();
if ($includeDefaultSortOrders) {
$sortOrders = $this->sortOrderFactory->getDefaultSortOrders();
if (version_compare(_PS_VERSION_, '1.7.3.1', '>=')) {
$sortOrders[] = (new SortOrder('product', 'position', 'asc'))->setLabel($this->module->l('Relevance (reverse)', 'as4searchprovider'));
} else {
$sortOrders[] = (new SortOrder('product', 'position', 'desc'))->setLabel($this->module->l('Relevance (reverse)', 'as4searchprovider'));
}
usort($sortOrders, function ($a, $b) {
if ($a->getField() == $b->getField()) {
if ($a->getDirection() == $b->getDirection()) {
return 0;
}
return ($a->getDirection() < $b->getDirection()) ? -1 : 1;
}
return ($a->getField() < $b->getField()) ? -1 : 1;
});
} else {
$sortOrders = array();
}
if ($includeAll || !empty($config['sortOrders']['product.sales.asc'])) {
$sortOrders[] = (new SortOrder('product', 'sales', 'asc'))->setLabel($this->module->l('Sales, Lower first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.sales.desc'])) {
$sortOrders[] = (new SortOrder('product', 'sales', 'desc'))->setLabel($this->module->l('Sales, Highest first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.quantity.asc'])) {
$sortOrders[] = (new SortOrder('product', 'quantity', 'asc'))->setLabel($this->module->l('Quantity, Lower first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.quantity.desc'])) {
$sortOrders[] = (new SortOrder('product', 'quantity', 'desc'))->setLabel($this->module->l('Quantity, Highest first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.manufacturer_name.asc'])) {
$sortOrders[] = (new SortOrder('product', 'manufacturer_name', 'asc'))->setLabel($this->module->l('Brand, A to Z', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.manufacturer_name.desc'])) {
$sortOrders[] = (new SortOrder('product', 'manufacturer_name', 'desc'))->setLabel($this->module->l('Brand, Z to A', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.date_add.desc'])) {
$sortOrders[] = (new SortOrder('product', 'date_add', 'desc'))->setLabel($this->module->l('New products first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.date_add.asc'])) {
$sortOrders[] = (new SortOrder('product', 'date_add', 'asc'))->setLabel($this->module->l('Old products first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.date_upd.desc'])) {
$sortOrders[] = (new SortOrder('product', 'date_upd', 'desc'))->setLabel($this->module->l('Latest updated products first', 'as4searchprovider'));
}
if ($includeAll || !empty($config['sortOrders']['product.date_upd.asc'])) {
$sortOrders[] = (new SortOrder('product', 'date_upd', 'asc'))->setLabel($this->module->l('Oldest updated products first', 'as4searchprovider'));
}
return $sortOrders;
}
public function runQuery(
ProductSearchContext $context,
ProductSearchQuery $query
) {
$query->setResultsPerPage((int)Tools::getValue('resultsPerPage', $this->searchInstance->products_per_page));
$result = new ProductSearchResult();
$sortOrders = $this->getSortOrders();
$result->setAvailableSortOrders(
$sortOrders
);
if (!$result->getCurrentSortOrder()) {
$currentSearchEngine = new AdvancedSearchClass($this->idSearch);
if ((Tools::getIsset('order') || Tools::getIsset('orderby')) && $query->getSortOrder() != null) {
$defaultSortOrder = As4SearchEngine::getOrderByValue($currentSearchEngine, $query);
$defaultSortWay = As4SearchEngine::getOrderWayValue($currentSearchEngine, $query);
} else {
$defaultSortOrder = As4SearchEngine::getOrderByValue($currentSearchEngine);
$defaultSortWay = As4SearchEngine::getOrderWayValue($currentSearchEngine);
}
$sortOrderSet = false;
foreach ($sortOrders as $sortOrder) {
if ($sortOrder->getField() == $defaultSortOrder) {
if ($sortOrder->getDirection() == $defaultSortWay) {
$sortOrderSet = true;
$query->setSortOrder($sortOrder);
break;
}
}
}
}
$nbProducts = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterionsList,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterionsList)),
null,
null,
true,
$query
);
$products = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterionsList,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterionsList)),
(int)$query->getPage(),
(int)$query->getResultsPerPage(),
false,
$query
);
$result->setProducts($products);
$result->setTotalProductsCount($nbProducts);
return $result;
}
}

View File

@@ -0,0 +1,8 @@
<?php
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");
header("Location: ../");
exit;