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,237 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
if (!defined('_PS_VERSION_')) {
exit;
}
abstract class AdvancedSearchProductListingFrontController extends ProductListingFrontController
{
public function getListingLabel()
{
return $this->getTranslator()->trans('Search results', array(), 'Shop.Theme.Catalog');
}
protected function getProductSearchQuery()
{
$query = new ProductSearchQuery();
return $query;
}
protected function getDefaultProductSearchProvider()
{
return new As4SearchProvider(
$this->module,
$this->getTranslator(),
$this->getSearchEngine(),
$this->getCriterionsList()
);
}
private function getProductSearchProviderFromModules($query)
{
return null;
}
protected function getProductSearchVariables()
{
$context = $this->getProductSearchContext();
$query = $this->getProductSearchQuery();
$provider = $this->getProductSearchProviderFromModules($query);
if (null === $provider) {
$provider = $this->getDefaultProductSearchProvider();
}
$resultsPerPage = (int) Tools::getValue('resultsPerPage');
if ($resultsPerPage <= 0 || $resultsPerPage > 36) {
$resultsPerPage = Configuration::get('PS_PRODUCTS_PER_PAGE');
}
$query
->setResultsPerPage($resultsPerPage)
->setPage(max((int) Tools::getValue('page'), 1))
;
if (Tools::getValue('order')) {
$encodedSortOrder = Tools::getValue('order');
} else {
$encodedSortOrder = Tools::getValue('orderby', null);
}
if ($encodedSortOrder) {
try {
$selectedSortOrder = SortOrder::newFromString($encodedSortOrder);
} catch (Exception $e) {
$defaultSearchEngineOrderBy = As4SearchEngine::getOrderByValue($this->getSearchEngine());
$defaultSearchEngineOrderWay = As4SearchEngine::getOrderWayValue($this->getSearchEngine());
$selectedSortOrder = new SortOrder('product', $defaultSearchEngineOrderBy, $defaultSearchEngineOrderWay);
}
$query->setSortOrder($selectedSortOrder);
}
$encodedFacets = Tools::getValue('q');
$query->setEncodedFacets($encodedFacets);
$result = $provider->runQuery(
$context,
$query
);
if (!$result->getCurrentSortOrder()) {
$result->setCurrentSortOrder($query->getSortOrder());
}
$products = $this->prepareMultipleProductsForTemplate(
$result->getProducts()
);
if ($provider instanceof FacetsRendererInterface) {
$rendered_facets = $provider->renderFacets(
$context,
$result
);
$rendered_active_filters = $provider->renderActiveFilters(
$context,
$result
);
} else {
$rendered_facets = $this->renderFacets(
$result
);
$rendered_active_filters = $this->renderActiveFilters(
$result
);
}
$pagination = $this->getTemplateVarPagination(
$query,
$result
);
$sort_orders = $this->getTemplateVarSortOrders(
$result->getAvailableSortOrders(),
$query->getSortOrder()->toString()
);
$sort_selected = false;
if (!empty($sort_orders)) {
foreach ($sort_orders as $order) {
if (isset($order['current']) && true === $order['current']) {
$sort_selected = $order['label'];
break;
}
}
}
$currentUrlParams = array(
'q' => $result->getEncodedFacets(),
);
if ((Tools::getIsset('order') || Tools::getIsset('orderby')) && $result->getCurrentSortOrder() != null) {
$currentUrlParams['order'] = $result->getCurrentSortOrder()->toString();
}
$searchVariables = array(
'result' => $result,
'label' => $this->getListingLabel(),
'products' => $products,
'sort_orders' => $sort_orders,
'sort_selected' => $sort_selected,
'pagination' => $pagination,
'rendered_facets' => $rendered_facets,
'rendered_active_filters' => $rendered_active_filters,
'js_enabled' => $this->ajax,
'current_url' => $this->updateQueryString($currentUrlParams),
);
Hook::exec('actionProductSearchComplete', $searchVariables);
if (version_compare(_PS_VERSION_, '1.7.1.0', '>=')) {
Hook::exec('filterProductSearch', array('searchVariables' => &$searchVariables));
Hook::exec('actionProductSearchAfter', $searchVariables);
}
return $searchVariables;
}
protected function getTemplateVarPagination(
ProductSearchQuery $query,
ProductSearchResult $result
) {
$pagination = parent::getTemplateVarPagination($query, $result);
foreach ($pagination['pages'] as &$p) {
$p['url'] = $this->updateQueryString(array(
'page' => $p['page'],
'order' => $query->getSortOrder()->toString(),
'from_as4' => $this->getSearchEngine()->id,
));
}
return $pagination;
}
protected function getTemplateVarSortOrders(array $sortOrders, $currentSortOrderURLParameter)
{
$sortOrders = parent::getTemplateVarSortOrders($sortOrders, $currentSortOrderURLParameter);
foreach ($sortOrders as &$order) {
$order['url'] = $this->updateQueryString(array(
'order' => $order['urlParameter'],
'page' => null,
'from_as4' => $this->getSearchEngine()->id,
));
}
return $sortOrders;
}
protected function getAjaxProductSearchVariables()
{
$data = parent::getAjaxProductSearchVariables();
$data['id_search'] = null;
$data['remind_selection'] = null;
if (method_exists($this, 'getIdSeo')) {
$data['id_seo'] = (int)$this->getIdSeo();
}
$searchEngine = $this->getSearchEngine();
if (Tools::getIsset('with_product') && !Tools::getValue('with_product')) {
$data['rendered_products_top'] = null;
$data['rendered_products'] = null;
$data['rendered_products_bottom'] = null;
} else {
if (!empty($searchEngine->redirect_one_product) && $searchEngine->search_method == 2 && !empty($data['products']) && is_array($data['products']) && sizeof($data['products']) == 1) {
$product = current($data['products']);
if (!empty($product['url'])) {
$data['redirect_to_url'] = $product['url'];
} elseif (!empty($product['link'])) {
$data['redirect_to_url'] = $product['link'];
}
}
if ($searchEngine->search_method == 3) {
$searchs = As4SearchEngine::getSearch($searchEngine->id, (int)$this->context->language->id);
$criterions = $this->getCriterionsList();
$searchs = $this->module->getCriterionsGroupsAndCriterionsForSearch($searchs, (int)$this->context->language->id, $criterions, 0, false);
$realAvailableGroups = 0;
$selectedGroupCount = 0;
foreach ($searchs[0]['criterions'] as $idCriterionGroup => $criterionsList) {
if (isset($criterions[$idCriterionGroup])) {
$selectedGroupCount++;
}
if (is_array($criterionsList) && sizeof($criterionsList)) {
$realAvailableGroups++;
}
}
if ($selectedGroupCount != $realAvailableGroups) {
$data['rendered_products_top'] = null;
$data['rendered_products'] = null;
$data['rendered_products_bottom'] = null;
}
}
}
if (Validate::isLoadedObject($searchEngine)) {
$data['id_search'] = $searchEngine->id;
$data['remind_selection'] = (int)$searchEngine->remind_selection;
}
return $data;
}
protected function renderFacets(ProductSearchResult $result)
{
$this->assignGeneralPurposeVariables();
$this->module->setSmartyVarsForTpl($this->getSearchEngine(), $this->getCriterionsList());
return $this->module->display('pm_advancedsearch4.php', 'views/templates/hook/1.7/pm_advancedsearch.tpl');
}
protected function renderActiveFilters(ProductSearchResult $result)
{
$this->assignGeneralPurposeVariables();
$this->module->setSmartyVarsForTpl($this->getSearchEngine(), $this->getCriterionsList());
return $this->module->display('pm_advancedsearch4.php', 'views/templates/hook/1.7/pm_advancedsearch_selection_block.tpl');
}
}

View File

@@ -0,0 +1,315 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4advancedsearch4ModuleFrontController extends ModuleFrontController
{
private $id_seo = false;
private $id_search = false;
private $searchInstance;
protected $context;
public $display_column_left = true;
public $display_column_right = true;
protected $display_header = true;
protected $display_footer = true;
private $criterions = array();
private $criterions_hidden = array();
private $next_id_criterion_group = false;
private $reset = false;
public function __construct()
{
parent::__construct();
if (Tools::getValue('ajaxMode')) {
$this->ajax = true;
$this->display_column_left = false;
$this->display_column_right = false;
$this->display_header = false;
$this->display_footer = false;
}
}
public function setMedia()
{
parent::setMedia();
if ((method_exists($this->context, 'getMobileDevice') && $this->context->getMobileDevice() == false || !method_exists($this->context, 'getMobileDevice'))) {
$this->addCSS(array(
_THEME_CSS_DIR_.'scenes.css' => 'all',
_THEME_CSS_DIR_.'category.css' => 'all',
_THEME_CSS_DIR_.'product_list.css' => 'all',
));
if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0) {
$this->addJS(_THEME_JS_DIR_.'products-comparison.js');
}
}
}
public function init()
{
parent::init();
$this->setCustomContextLink();
$this->setSEOTags();
$this->setProductFilterList();
}
private function setCustomContextLink()
{
$link_pm = new LinkPM($this->context->link->protocol_link, $this->context->link->protocol_content);
$this->context->smarty->assign(array(
'link' => $link_pm
));
}
private function setProductFilterList()
{
$productFilterListSource = Tools::getValue('productFilterListSource');
if (in_array($productFilterListSource, As4SearchEngine::$validPageName)) {
As4SearchEngine::$productFilterListSource = $productFilterListSource;
if ($productFilterListSource == 'search' || $productFilterListSource == 'jolisearch' || $productFilterListSource == 'module-ambjolisearch-jolisearch') {
$productFilterListData = AdvancedSearchCoreClass::getDataUnserialized(Tools::getValue('productFilterListData'));
if ($productFilterListData !== false) {
As4SearchEngine::$productFilterListData = $productFilterListData;
}
}
$this->module->setProductFilterContext();
}
}
private function setSEOTags()
{
$this->id_seo = Tools::getValue('id_seo', false);
$seo_url = Tools::getValue('seo_url', false);
if ($seo_url && $this->id_seo) {
$resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int)$this->id_seo, (int)$this->context->language->id);
if (!$resultSeoUrl) {
Tools::redirect('404');
}
if ($resultSeoUrl[0]['deleted']) {
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect('index');
}
$pageNumber = (int)Tools::getValue('p');
$this->context->smarty->assign(array(
'page_name' => 'advancedsearch-seo-'.(int)$this->id_seo,
'meta_title' => $resultSeoUrl[0]['meta_title'].(!empty($pageNumber) ? ' ('.$pageNumber.')' : ''),
'meta_description' => $resultSeoUrl[0]['meta_description'],
'meta_keywords' => $resultSeoUrl[0]['meta_keywords'],
'as_seo_title' => $resultSeoUrl[0]['title'],
'as_seo_description' => $resultSeoUrl[0]['description']
));
}
if (Tools::getValue('ajaxMode')) {
if (!headers_sent()) {
// header('X-Robots-Tag: noindex, nofollow', true);
}
$this->context->smarty->assign(array(
'nofollow' => true,
'nobots' => true,
));
} elseif (Tools::getValue('only_products')) {
if ($this->id_seo && (Tools::getValue('p') || Tools::getValue('n'))) {
// header('X-Robots-Tag: noindex, follow', true);
} else {
// header('X-Robots-Tag: noindex, nofollow', true);
}
$this->context->smarty->assign(array(
'nofollow' => true,
'nobots' => true,
));
}
}
public function process()
{
$seo_url = Tools::getValue('seo_url', false);
if ($seo_url == 'products-comparison') {
ob_end_clean();
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect('products-comparison.php?ajax='.(int)Tools::getValue('ajax').'&action='.Tools::getValue('action').'&id_product='.(int)Tools::getValue('id_product'));
}
if ($seo_url && $this->id_seo) {
$resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int)$this->id_seo, (int)$this->context->language->id);
if (!$resultSeoUrl) {
Tools::redirect('404');
}
if ($resultSeoUrl[0]['deleted']) {
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect('index');
}
$this->id_search = $resultSeoUrl[0]['id_search'];
$this->searchInstance = new AdvancedSearchClass((int)$this->id_search, (int)$this->context->language->id);
if (!$this->searchInstance->active) {
header("Status: 307 Temporary Redirect", false, 307);
Tools::redirect('index');
}
$seoUrlCheck = current(explode('/', $seo_url));
if ($resultSeoUrl[0]['seo_url'] != $seoUrlCheck) {
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect($this->context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => $this->idSeo, 'seo_url' => $resultSeoUrl[0]['seo_url'])));
die();
}
$criteria = unserialize($resultSeoUrl[0]['criteria']);
if (is_array($criteria) && sizeof($criteria)) {
$this->criterions = PM_AdvancedSearch4::getArrayCriteriaFromSeoArrayCriteria($criteria);
}
$hasPriceCriterionGroup = false;
if (is_array($this->criterions) && sizeof($this->criterions)) {
$selected_criteria_groups_type = As4SearchEngine::getCriterionGroupsTypeAndDisplay((int)$this->id_search, array_keys($this->criterions));
if (is_array($selected_criteria_groups_type) && sizeof($selected_criteria_groups_type)) {
foreach ($selected_criteria_groups_type as $criterionGroup) {
if ($criterionGroup['criterion_group_type'] == 'price') {
$hasPriceCriterionGroup = true;
break;
}
}
}
}
if ($hasPriceCriterionGroup && $resultSeoUrl[0]['id_currency'] && $this->context->cookie->id_currency != (int)$resultSeoUrl[0]['id_currency']) {
$this->context->cookie->id_currency = $resultSeoUrl[0]['id_currency'];
header('Refresh: 1; URL='.$_SERVER['REQUEST_URI']);
die;
}
$this->context->smarty->assign('as_cross_links', AdvancedSearchSeoClass::getCrossLinksSeo((int)$this->context->language->id, $resultSeoUrl[0]['id_seo']));
} else {
if (Tools::getValue('setHideCriterionStatus')) {
ob_end_clean();
$this->id_search = (int)Tools::getValue('id_search');
$state = (int)Tools::getValue('state') > 0;
if (isset($this->context->cookie->hidden_criteria_state)) {
$hidden_criteria_state = unserialize($this->context->cookie->hidden_criteria_state);
if (is_array($hidden_criteria_state)) {
$hidden_criteria_state[$this->id_search] = $state;
} else {
$hidden_criteria_state = array();
}
$this->context->cookie->hidden_criteria_state = serialize($hidden_criteria_state);
} else {
$this->context->cookie->hidden_criteria_state = serialize(array($this->id_search => $state));
}
die;
}
$this->id_search = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->id_search, (int)$this->context->language->id);
$this->criterions = Tools::getValue('as4c', array());
if (is_array($this->criterions)) {
$this->criterions = As4SearchEngine::cleanArrayCriterion($this->criterions);
} else {
$this->criterions = array();
}
$this->criterions_hidden = Tools::getValue('as4c_hidden', array());
if (is_array($this->criterions_hidden)) {
$this->criterions_hidden = As4SearchEngine::cleanArrayCriterion($this->criterions_hidden);
} else {
$this->criterions_hidden = array();
}
$this->next_id_criterion_group = (int)Tools::getValue('next_id_criterion_group', false);
$this->reset = (int)Tools::getValue('reset', false);
$this->reset_group = (int)Tools::getValue('reset_group', false);
if ($this->reset) {
$this->criterions = array();
}
if ($this->reset_group && isset($this->criterions[$this->reset_group])) {
unset($this->criterions[$this->reset_group]);
if ($this->searchInstance->step_search) {
$criterionsGroups = AdvancedSearchCriterionGroupClass::getCriterionsGroupsFromIdSearch((int)$this->id_search, (int)$this->context->language->id, false);
if (AdvancedSearchCoreClass::_isFilledArray($criterionsGroups)) {
$deleteAfter = false;
foreach ($criterionsGroups as $criterionGroup) {
if ((int)$criterionGroup['id_criterion_group'] == $this->reset_group) {
$deleteAfter = true;
}
if ($deleteAfter && isset($this->criterions[(int)$criterionGroup['id_criterion_group']])) {
unset($this->criterions[(int)$criterionGroup['id_criterion_group']]);
}
}
}
}
}
if ($this->searchInstance->filter_by_emplacement) {
$criterionsFromEmplacement = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id, $this->searchInstance->id_category_root);
foreach ($criterionsFromEmplacement as $idCriterionGroup => $idCriterionList) {
if (!isset($this->criterions[$idCriterionGroup])) {
$this->criterions[$idCriterionGroup] = $idCriterionList;
} elseif (is_array($this->criterions[$idCriterionGroup]) && !sizeof($this->criterions[$idCriterionGroup])) {
$this->criterions[$idCriterionGroup] = $idCriterionList;
}
}
}
$this->context->cookie->{'next_id_criterion_group_'.(int)$this->id_search} = $this->next_id_criterion_group;
}
}
public function displayAjax()
{
$this->displayContent();
}
public function displayContent()
{
if (!$this->id_search) {
die;
}
if (Tools::getValue('ajaxMode')) {
$this->ajax = true;
}
if (!Tools::getValue('ajaxMode')) {
echo $this->module->displayAjaxSearchBlocks($this->id_search, 'pm_advancedsearch.tpl', (int)Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden, true);
} else {
try {
Hook::exec('displayHeader');
} catch (SmartyException $e) {
}
if (Tools::getValue('only_products')) {
$this->module->displayAjaxSearchBlocks($this->id_search, 'pm_advancedsearch.tpl', (int)Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden, true);
} elseif ($this->next_id_criterion_group && !$this->reset) {
if (is_array($this->criterions) && sizeof($this->criterions)) {
$this->module->displayAjaxSearchBlocks($this->id_search, 'pm_advancedsearch.tpl', (int)Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden);
} else {
$this->module->displayNextStepSearch($this->id_search, $this->next_id_criterion_group, (int)Tools::getValue('with_product', true), $this->criterions, $this->criterions_hidden);
}
} else {
$withProducts = (int)Tools::getValue('with_product', true);
if ($this->searchInstance->search_method == 3) {
$searchs = As4SearchEngine::getSearch($this->searchInstance->id, (int)$this->context->language->id);
$searchs = $this->module->getCriterionsGroupsAndCriterionsForSearch($searchs, (int)$this->context->language->id, $this->criterions, 0, false);
$realAvailableGroups = 0;
$selectedGroupCount = 0;
foreach ($searchs[0]['criterions'] as $idCriterionGroup => $criterionsList) {
if (isset($this->criterions[$idCriterionGroup])) {
$selectedGroupCount++;
}
if (is_array($criterionsList) && sizeof($criterionsList)) {
$realAvailableGroups++;
}
}
if ($selectedGroupCount == $realAvailableGroups) {
$withProducts = true;
} else {
$withProducts = false;
}
}
$this->module->displayAjaxSearchBlocks($this->id_search, 'pm_advancedsearch.tpl', $withProducts, $this->criterions, $this->criterions_hidden);
}
}
if ($this->ajax) {
die;
}
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getCriterionsList()
{
return $this->criterions;
}
public function getHiddenCriterionsList()
{
return $this->criterions_hidden;
}
}

View File

@@ -0,0 +1,198 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4advancedsearch4ModuleFrontController extends AdvancedSearchProductListingFrontController
{
private $idSeo = false;
private $idSearch = false;
private $searchInstance;
protected $context;
public $display_column_left = true;
public $display_column_right = true;
protected $display_header = true;
protected $display_footer = true;
private $criterions = array();
private $criterions_hidden = array();
private $next_id_criterion_group = false;
private $reset = false;
public function __construct()
{
parent::__construct();
if (Tools::getValue('ajaxMode')) {
$this->ajax = true;
$this->display_column_left = false;
$this->display_column_right = false;
$this->display_header = false;
$this->display_footer = false;
}
}
public function init()
{
if (!isset($this->module) || !is_object($this->module)) {
$this->module = Module::getInstanceByName('pm_advancedsearch4');
}
$this->idSearch = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
parent::init();
$this->setSEOTags();
$this->setCriterions();
$this->setProductFilterList();
$this->processActions();
$this->doProductSearch('');
}
private function setProductFilterList()
{
$productFilterListSource = Tools::getValue('productFilterListSource');
if (in_array($productFilterListSource, As4SearchEngine::$validPageName)) {
As4SearchEngine::$productFilterListSource = $productFilterListSource;
if ($productFilterListSource == 'search' || $productFilterListSource == 'jolisearch' || $productFilterListSource == 'module-ambjolisearch-jolisearch') {
$productFilterListData = AdvancedSearchCoreClass::getDataUnserialized(Tools::getValue('productFilterListData'));
if ($productFilterListData !== false) {
As4SearchEngine::$productFilterListData = $productFilterListData;
}
}
$this->module->setProductFilterContext();
}
}
private function setSEOTags()
{
$this->idSeo = Tools::getValue('id_seo', false);
if (Tools::getValue('ajaxMode')) {
if (!headers_sent()) {
// header('X-Robots-Tag: noindex, nofollow', true);
}
$this->context->smarty->assign(array(
'nofollow' => true,
'nobots' => true,
));
} elseif (Tools::getValue('only_products')) {
if ($this->idSeo && (Tools::getValue('p') || Tools::getValue('n'))) {
// header('X-Robots-Tag: noindex, follow', true);
} else {
// header('X-Robots-Tag: noindex, nofollow', true);
}
$this->context->smarty->assign(array(
'nofollow' => true,
'nobots' => true,
));
}
}
private function setCriterions()
{
$this->idSearch = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
$this->criterions = Tools::getValue('as4c', array());
if (is_array($this->criterions)) {
$this->criterions = As4SearchEngine::cleanArrayCriterion($this->criterions);
} else {
$this->criterions = array();
}
$this->criterions_hidden = Tools::getValue('as4c_hidden', array());
if (is_array($this->criterions_hidden)) {
$this->criterions_hidden = As4SearchEngine::cleanArrayCriterion($this->criterions_hidden);
} else {
$this->criterions_hidden = array();
}
$this->reset = (int)Tools::getValue('reset', false);
$this->reset_group = (int)Tools::getValue('reset_group', false);
if ($this->reset) {
$this->criterions = array();
}
if ($this->reset_group && isset($this->criterions[$this->reset_group])) {
unset($this->criterions[$this->reset_group]);
if ($this->searchInstance->step_search) {
$criterionsGroups = AdvancedSearchCriterionGroupClass::getCriterionsGroupsFromIdSearch((int)$this->idSearch, (int)$this->context->language->id, false);
if (AdvancedSearchCoreClass::_isFilledArray($criterionsGroups)) {
$deleteAfter = false;
foreach ($criterionsGroups as $criterionGroup) {
if ((int)$criterionGroup['id_criterion_group'] == $this->reset_group) {
$deleteAfter = true;
}
if ($deleteAfter && isset($this->criterions[(int)$criterionGroup['id_criterion_group']])) {
unset($this->criterions[(int)$criterionGroup['id_criterion_group']]);
}
}
}
}
}
if ($this->searchInstance->filter_by_emplacement) {
$criterionsFromEmplacement = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id, $this->searchInstance->id_category_root);
foreach ($criterionsFromEmplacement as $idCriterionGroup => $idCriterionList) {
if (!isset($this->criterions[$idCriterionGroup])) {
$this->criterions[$idCriterionGroup] = $idCriterionList;
} elseif (is_array($this->criterions[$idCriterionGroup]) && !sizeof($this->criterions[$idCriterionGroup])) {
$this->criterions[$idCriterionGroup] = $idCriterionList;
}
}
}
$this->next_id_criterion_group = (int)Tools::getValue('next_id_criterion_group', false);
$this->context->cookie->{'next_id_criterion_group_'.(int)$this->idSearch} = $this->next_id_criterion_group;
}
public function processActions()
{
if (Tools::getValue('setHideCriterionStatus')) {
ob_end_clean();
$this->idSearch = (int)Tools::getValue('id_search');
$state = (int)Tools::getValue('state') > 0;
if (isset($this->context->cookie->hidden_criteria_state)) {
$hidden_criteria_state = unserialize($this->context->cookie->hidden_criteria_state);
if (is_array($hidden_criteria_state)) {
$hidden_criteria_state[$this->idSearch] = $state;
} else {
$hidden_criteria_state = array();
}
$this->context->cookie->hidden_criteria_state = serialize($hidden_criteria_state);
} else {
$this->context->cookie->hidden_criteria_state = serialize(array($this->idSearch => $state));
}
die;
}
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getCriterionsList()
{
return $this->criterions;
}
public function getHiddenCriterionsList()
{
return $this->criterions_hidden;
}
public function getCanonicalURL()
{
return As4SearchEngine::generateURLFromCriterions($this->getSearchEngine()->id, $this->getCriterionsList());
}
public function getListingLabel()
{
return $this->getTranslator()->trans('Search results', array(), 'Shop.Theme.Catalog');
}
protected function updateQueryString(array $extraParams = null)
{
if ($extraParams === null) {
$extraParams = array();
}
return As4SearchEngine::generateURLFromCriterions($this->getSearchEngine()->id, $this->getCriterionsList(), null, $extraParams);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
// Load Search Providers for PrestaShop 1.7
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/advancedsearch4-17.php');
} else {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/advancedsearch4-16.php');
}

View File

@@ -0,0 +1,34 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
// PHP Cli only
if ('cli' == php_sapi_name()) {
include(dirname(__FILE__).'/../../../../config/config.inc.php');
include(dirname(__FILE__).'/../../../../init.php');
$module = Module::getInstanceByName('pm_advancedsearch4');
$idSearch = false;
// Retrieve id_search into args
if (isset($argv) && is_array($argv) && isset($argv[1]) && is_numeric($argv[1]) && !empty($argv[1])) {
$idSearch = (int)$argv[1];
$searchInstance = new AdvancedSearchClass((int)$idSearch);
if (!Validate::isLoadedObject($searchInstance)) {
die(Tools::jsonEncode(array('result' => false)));
}
}
die(Tools::jsonEncode($module->cronTask($idSearch)));
} else {
header('HTTP/1.0 403 Forbidden', true, 403);
die;
}

View File

@@ -0,0 +1,54 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4cronModuleFrontController extends ModuleFrontController
{
private $idSearch;
private $searchInstance;
public $ajax = true;
public $display_header = false;
public $display_footer = false;
public $display_column_left = false;
public $display_column_right = false;
public function init()
{
if (ob_get_length() > 0) {
ob_clean();
}
// header('X-Robots-Tag: noindex, nofollow', true);
header('Content-type: application/json');
$secureKey = Configuration::getGlobalValue('PM_AS4_SECURE_KEY');
if (empty($secureKey) || $secureKey !== Tools::getValue('secure_key')) {
Tools::redirect('404');
die;
}
$this->idSearch = (int)Tools::getValue('id_search');
if (!empty($this->idSearch)) {
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
if (!Validate::isLoadedObject($this->searchInstance)) {
Tools::redirect('404');
}
}
if (!empty($this->searchInstance->id)) {
$indexationStats = $this->module->cronTask($this->searchInstance->id);
} else {
$indexationStats = $this->module->cronTask();
}
die(Tools::jsonEncode($indexationStats));
}
}

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,171 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4searchresultsModuleFrontController extends ModuleFrontController
{
// Récupérer la config thème des catégories et l'associer à ce controlleur (colonnes)
// Remplacer s-<id_search> par le nom du moteur ?
protected $idSearch;
protected $searchInstance;
protected $currentIdCategory;
protected $currentIdManufacturer;
protected $currentIdSupplier;
protected $criterionsList = array();
public function init()
{
parent::init();
// if (!headers_sent()) {
// header('X-Robots-Tag: noindex', true);
// }
$this->idSearch = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->cookie->id_lang);
if (!Validate::isLoadedObject($this->searchInstance)) {
Tools::redirect('404');
} else {
if (!$this->searchInstance->active) {
header("Status: 307 Temporary Redirect", false, 307);
Tools::redirect('index');
}
}
$this->currentIdCategory = As4SearchEngine::getCurrentCategory();
$this->currentIdManufacturer = As4SearchEngine::getCurrentManufacturer();
$this->currentIdSupplier = As4SearchEngine::getCurrentSupplier();
if (Tools::getValue('as4_from') == 'category' && empty($this->currentIdCategory)) {
Tools::redirect('404');
} elseif (Tools::getValue('as4_from') == 'manufacturer' && empty($this->currentIdManufacturer)) {
Tools::redirect('404');
} elseif (Tools::getValue('as4_from') == 'supplier' && empty($this->currentIdSupplier)) {
Tools::redirect('404');
}
$this->setCriterions();
$this->setSmartyVars();
$this->setTemplate('search-results.tpl');
}
public function getSelectedCriterions()
{
return $this->criterionsList;
}
protected function setCriterions()
{
$searchQuery = trim(Tools::getValue('as4_sq'));
if (!empty($searchQuery)) {
$this->criterionsList = As4SearchEngine::getCriterionsFromURL($this->idSearch, $searchQuery);
if ($this->searchInstance->filter_by_emplacement) {
$criterionsFromEmplacement = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id);
foreach ($criterionsFromEmplacement as $idCriterionGroup => $idCriterionList) {
if (!isset($this->criterionsList[$idCriterionGroup])) {
$this->criterionsList[$idCriterionGroup] = $idCriterionList;
} else {
$this->criterionsList[$idCriterionGroup] = $this->criterionsList[$idCriterionGroup] + $idCriterionList;
}
}
}
$this->criterionsList = As4SearchEngine::cleanArrayCriterion($this->criterionsList);
if (!sizeof($this->criterionsList)) {
Tools::redirect('404');
} else {
if (!headers_sent()) {
header('Link: <' . As4SearchEngine::generateURLFromCriterions($this->idSearch, $this->criterionsList) . '>; rel="canonical"', true);
}
}
} else {
Tools::redirect('404');
}
}
public function setMedia()
{
parent::setMedia();
if ((method_exists($this->context, 'getMobileDevice') && $this->context->getMobileDevice() == false || !method_exists($this->context, 'getMobileDevice'))) {
$this->addCSS(array(
_THEME_CSS_DIR_.'scenes.css' => 'all',
_THEME_CSS_DIR_.'category.css' => 'all',
_THEME_CSS_DIR_.'product_list.css' => 'all',
));
if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0) {
$this->addJS(_THEME_JS_DIR_.'products-comparison.js');
}
}
}
protected function setSmartyVars()
{
$pageNb = (int)Tools::getValue('p', 1);
$this->module->setProductFilterContext();
$nb_products = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterionsList,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterionsList)),
null,
null,
true
);
$products = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterionsList,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterionsList)),
(int)$pageNb,
(int)Tools::getValue('n', $this->searchInstance->products_per_page),
false
);
$this->module->_assignPagination($this->searchInstance->products_per_page, $nb_products);
$this->module->_assignProductSort($this->searchInstance);
$link_pm = new LinkPM($this->context->link->protocol_link, $this->context->link->protocol_content);
if ($this->currentIdCategory) {
if ($this->currentIdCategory == (int)Context::getContext()->shop->getCategory()) {
$this->context->smarty->assign(array(
'path' => As4SearchEngine::getCategoryName($this->currentIdCategory, (int)$this->context->cookie->id_lang),
));
} else {
$this->context->smarty->assign(array(
'path' => Tools::getPath($this->currentIdCategory),
));
}
} elseif ($this->currentIdManufacturer) {
$manufacturer = new Manufacturer($this->currentIdManufacturer, (int)$this->context->cookie->id_lang);
$this->context->smarty->assign(array(
'path' => $manufacturer->name,
));
} elseif ($this->currentIdSupplier) {
$supplier = new Supplier($this->currentIdSupplier, (int)$this->context->cookie->id_lang);
$this->context->smarty->assign(array(
'path' => $supplier->name,
));
} else {
$this->context->smarty->assign(array(
'path' => $this->searchInstance->title,
));
}
$this->context->smarty->assign(array(
'products' => $products,
'nb_products' => $nb_products,
'id_search' => $this->idSearch,
'request' => $link_pm->getPaginationLink(false, false, false, true),
'link' => $link_pm,
'as_seo_description' => $this->searchInstance->description,
'as_seo_title' => $this->searchInstance->title,
'nobots' => true,
));
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getCriterionsList()
{
return $this->criterionsList;
}
}

View File

@@ -0,0 +1,244 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4searchresultsModuleFrontController extends AdvancedSearchProductListingFrontController
{
protected $idSearch;
protected $searchInstance;
protected $currentIdCategory;
protected $currentCategoryObject;
protected $currentIdManufacturer;
protected $currentIdSupplier;
protected $criterionsList = array();
public function init()
{
if (!isset($this->module) || !is_object($this->module)) {
$this->module = Module::getInstanceByName('pm_advancedsearch4');
}
parent::init();
$this->php_self = 'module-pm_advancedsearch4-searchresults';
// if (!headers_sent()) {
// header('X-Robots-Tag: noindex', true);
// }
$this->idSearch = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->cookie->id_lang);
if (!Validate::isLoadedObject($this->searchInstance)) {
Tools::redirect('404');
} else {
if (!$this->searchInstance->active) {
header("Status: 307 Temporary Redirect", false, 307);
Tools::redirect('index');
}
}
$this->currentIdCategory = As4SearchEngine::getCurrentCategory();
$this->currentIdManufacturer = As4SearchEngine::getCurrentManufacturer();
$this->currentIdSupplier = As4SearchEngine::getCurrentSupplier();
if (Tools::getValue('as4_from') == 'category' && empty($this->currentIdCategory)) {
Tools::redirect('404');
} elseif (Tools::getValue('as4_from') == 'manufacturer' && empty($this->currentIdManufacturer)) {
Tools::redirect('404');
} elseif (Tools::getValue('as4_from') == 'supplier' && empty($this->currentIdSupplier)) {
Tools::redirect('404');
}
$this->setCriterions();
$this->setSmartyVars();
if (Tools::getValue('order')) {
try {
$selectedSortOrder = SortOrder::newFromString(trim(Tools::getValue('order')));
} catch (Exception $e) {
$fixedSearchUrl = $this->rewriteOrderParameter();
header('Location:' . $fixedSearchUrl, true, 301);
}
}
if (Tools::getIsset('from-xhr')) {
$this->doProductSearch('');
} else {
$this->template = 'module:pm_advancedsearch4/views/templates/front/'.Tools::substr(_PS_VERSION_, 0, 3).'/search-results.tpl';
}
}
protected function rewriteOrderParameter()
{
$defaultSearchEngineOrderBy = As4SearchEngine::getOrderByValue($this->getSearchEngine());
$defaultSearchEngineOrderWay = As4SearchEngine::getOrderWayValue($this->getSearchEngine());
$selectedSortOrder = new SortOrder('product', $defaultSearchEngineOrderBy, $defaultSearchEngineOrderWay);
return As4SearchEngine::generateURLFromCriterions($this->idSearch, $this->criterionsList, null, array('order' => $selectedSortOrder->toString()));
}
public function getSelectedCriterions()
{
return $this->criterionsList;
}
protected function setCriterions()
{
$searchQuery = trim(Tools::getValue('as4_sq'));
if (!empty($searchQuery)) {
$this->criterionsList = As4SearchEngine::getCriterionsFromURL($this->idSearch, $searchQuery);
if ($this->searchInstance->filter_by_emplacement) {
$criterionsFromEmplacement = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id);
foreach ($criterionsFromEmplacement as $idCriterionGroup => $idCriterionList) {
if (!isset($this->criterionsList[$idCriterionGroup])) {
$this->criterionsList[$idCriterionGroup] = $idCriterionList;
} else {
$this->criterionsList[$idCriterionGroup] = $this->criterionsList[$idCriterionGroup] + $idCriterionList;
}
}
}
$this->criterionsList = As4SearchEngine::cleanArrayCriterion($this->criterionsList);
$ignoreNoCriterions = false;
if (!sizeof($this->criterionsList) && empty($this->searchInstance->filter_by_emplacement)) {
$ignoreNoCriterions = true;
}
if (!$ignoreNoCriterions && !sizeof($this->criterionsList)) {
if (!Tools::getIsset('from-xhr') && !Tools::getIsset('order') && !Tools::getIsset('page')) {
Tools::redirect('404');
}
} else {
if (!headers_sent()) {
header('Link: <' . As4SearchEngine::generateURLFromCriterions($this->idSearch, $this->criterionsList) . '>; rel="canonical"', true);
}
}
} else {
if ($this->searchInstance->filter_by_emplacement) {
$criterionsFromEmplacement = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id);
foreach ($criterionsFromEmplacement as $idCriterionGroup => $idCriterionList) {
if (!isset($this->criterionsList[$idCriterionGroup])) {
$this->criterionsList[$idCriterionGroup] = $idCriterionList;
} else {
$this->criterionsList[$idCriterionGroup] = $this->criterionsList[$idCriterionGroup] + $idCriterionList;
}
}
$this->criterionsList = As4SearchEngine::getCriteriaFromEmplacement($this->searchInstance->id);
$this->criterionsList = As4SearchEngine::cleanArrayCriterion($this->criterionsList);
if (sizeof($this->criterionsList)) {
if (!headers_sent()) {
header('Link: <' . As4SearchEngine::generateURLFromCriterions($this->idSearch, $this->criterionsList) . '>; rel="canonical"', true);
}
}
}
}
}
protected function getImage($object, $id_image)
{
$retriever = new ImageRetriever(
$this->context->link
);
return $retriever->getImage($object, $id_image);
}
protected function getTemplateVarCategory()
{
$category = $this->objectPresenter->present($this->currentCategoryObject);
$category['image'] = $this->getImage(
$this->currentCategoryObject,
$this->currentCategoryObject->id_image
);
return $category;
}
protected function getTemplateVarSubCategories()
{
return array_map(function (array $category) {
$object = new Category(
$category['id_category'],
$this->context->language->id
);
$category['image'] = $this->getImage(
$object,
$object->id_image
);
$category['url'] = $this->context->link->getCategoryLink(
$category['id_category'],
$category['link_rewrite']
);
return $category;
}, $this->currentCategoryObject->getSubCategories($this->context->language->id));
}
protected function setSmartyVars()
{
$this->module->setProductFilterContext();
if (!empty($this->currentIdCategory) && !empty($this->searchInstance->keep_category_information)) {
$this->currentCategoryObject = new Category($this->currentIdCategory, $this->context->language->id);
$this->context->smarty->assign(array(
'category' => $this->getTemplateVarCategory(),
'subcategories' => $this->getTemplateVarSubCategories(),
));
}
$variables = $this->getProductSearchVariables();
$this->context->smarty->assign(array(
'listing' => $variables,
'id_search' => $this->idSearch,
'as_seo_description' => $this->searchInstance->description,
'as_seo_title' => $this->searchInstance->title,
));
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getCriterionsList()
{
return $this->criterionsList;
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadCrumbTitle = (!empty($this->searchInstance->title) ? $this->searchInstance->title : $this->getTranslator()->trans('Search results', array(), 'Shop.Theme.Catalog'));
$breadcrumb['links'][] = array(
'title' => $breadCrumbTitle,
'url' => $this->getCanonicalURL(),
);
return $breadcrumb;
}
public function getCanonicalURL()
{
return As4SearchEngine::generateURLFromCriterions($this->idSearch, $this->criterionsList);
}
public function getListingLabel()
{
return $this->getTranslator()->trans('Search results', array(), 'Shop.Theme.Catalog');
}
protected function getDefaultProductSearchProvider()
{
return new As4SearchProvider(
$this->module,
$this->getTranslator(),
$this->searchInstance,
$this->criterionsList
);
}
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['robots'] = 'noindex';
$page['body_classes']['as4-search-results'] = true;
$page['body_classes']['as4-search-results-' . (int)$this->idSearch] = true;
return $page;
}
protected function updateQueryString(array $extraParams = null)
{
if ($extraParams === null) {
$extraParams = array();
}
if (array_key_exists('q', $extraParams)) {
return parent::updateQueryString($extraParams);
}
return As4SearchEngine::generateURLFromCriterions($this->getSearchEngine()->id, $this->getCriterionsList(), null, $extraParams);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
// Load Search Providers for PrestaShop 1.7
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/searchresults-17.php');
} else {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/searchresults-16.php');
}

View File

@@ -0,0 +1,213 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4seoModuleFrontController extends ModuleFrontController
{
protected $idSeo;
protected $idSearch;
protected $searchInstance;
protected $seoUrl;
protected $pageNb = 1;
protected $criterions;
protected $originalCriterions;
public function init()
{
parent::init();
$this->setSEOTags();
$this->setProductFilterList();
$this->setSmartyVars();
if (version_compare(_PS_VERSION_, '1.7.0.0', '<')) {
$this->setTemplate('seo-page.tpl');
} else {
$this->setTemplate('module:pm_advancedsearch4/views/templates/front/'.Tools::substr(_PS_VERSION_, 0, 3).'/seo-page.tpl');
}
}
public function setMedia()
{
parent::setMedia();
if ((method_exists($this->context, 'getMobileDevice') && $this->context->getMobileDevice() == false || !method_exists($this->context, 'getMobileDevice'))) {
$this->addCSS(array(
_THEME_CSS_DIR_.'scenes.css' => 'all',
_THEME_CSS_DIR_.'category.css' => 'all',
_THEME_CSS_DIR_.'product_list.css' => 'all',
));
if (Configuration::get('PS_COMPARATOR_MAX_ITEM') > 0) {
$this->addJS(_THEME_JS_DIR_.'products-comparison.js');
}
}
}
protected function redirectToSeoPageIndex()
{
$seoObj = new AdvancedSearchSeoClass($this->idSeo, $this->context->language->id);
if (Validate::isLoadedObject($seoObj)) {
Tools::redirect($this->context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => (int)$seoObj->id, 'seo_url' => $seoObj->seo_url), null, (int)$this->context->language->id));
} else {
Tools::redirect('index');
}
}
protected function setSEOTags()
{
$this->idSeo = Tools::getValue('id_seo');
$this->seoUrl = Tools::getValue('seo_url');
$this->pageNb = (int)Tools::getValue('p', 1);
if ($this->seoUrl && $this->idSeo) {
$resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int)$this->idSeo, (int)$this->context->language->id);
if (!$resultSeoUrl) {
Tools::redirect('404');
}
$this->idSearch = (int)$resultSeoUrl[0]['id_search'];
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
if ($resultSeoUrl[0]['deleted']) {
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect('index');
}
if (!$this->searchInstance->active) {
header("Status: 307 Temporary Redirect", false, 307);
Tools::redirect('index');
}
$seoUrlCheck = current(explode('/', $this->seoUrl));
if ($resultSeoUrl[0]['seo_url'] != $seoUrlCheck) {
header("Status: 301 Moved Permanently", false, 301);
$this->redirectToSeoPageIndex();
die();
}
$hasPriceCriterionGroup = false;
if (is_array($this->criterions) && sizeof($this->criterions)) {
$selected_criteria_groups_type = As4SearchEngine::getCriterionGroupsTypeAndDisplay((int)$this->id_search, array_keys($this->criterions));
if (is_array($selected_criteria_groups_type) && sizeof($selected_criteria_groups_type)) {
foreach ($selected_criteria_groups_type as $criterionGroup) {
if ($criterionGroup['criterion_group_type'] == 'price') {
$hasPriceCriterionGroup = true;
break;
}
}
}
}
if ($hasPriceCriterionGroup && $resultSeoUrl[0]['id_currency'] && $this->context->cookie->id_currency != (int)$resultSeoUrl[0]['id_currency']) {
$this->context->cookie->id_currency = $resultSeoUrl[0]['id_currency'];
header('Refresh: 1; URL='.$_SERVER['REQUEST_URI']);
die;
}
$criteria = unserialize($resultSeoUrl[0]['criteria']);
if (is_array($criteria) && sizeof($criteria)) {
$this->criterions = PM_AdvancedSearch4::getArrayCriteriaFromSeoArrayCriteria($criteria);
$this->criterions = As4SearchEngine::cleanArrayCriterion($this->criterions);
}
$searchQuery = implode('/', array_slice(explode('/', $this->seoUrl), 1));
$criterionsList = As4SearchEngine::getCriterionsFromURL($this->idSearch, $searchQuery);
if (is_array($criterionsList) && sizeof($criterionsList)) {
if (is_array($this->criterions) && sizeof($this->criterions)) {
$arrayDiff = $criterionsList;
foreach ($arrayDiff as $arrayDiffKey => $arrayDiffRow) {
if (isset($this->criterions[$arrayDiffKey]) && $this->criterions[$arrayDiffKey] == $arrayDiffRow) {
unset($arrayDiff[$arrayDiffKey]);
}
}
if (is_array($arrayDiff) && sizeof($arrayDiff)) {
$this->context->smarty->assign(array(
'nobots' => true,
));
}
unset($arrayDiff);
} else {
$this->context->smarty->assign(array(
'nobots' => true,
));
}
}
$this->originalCriterions = $this->criterions;
$this->criterions += $criterionsList;
$this->context->smarty->assign(array(
'page_name' => 'advancedsearch-seo-' . (int)$this->idSeo,
'as_is_seo_page' => true,
'meta_title' => $resultSeoUrl[0]['meta_title'] . ((int)$this->pageNb > 1 ? ' ('.$this->pageNb.')' : ''),
'meta_description' => $resultSeoUrl[0]['meta_description'],
'meta_keywords' => $resultSeoUrl[0]['meta_keywords'],
'path' => $resultSeoUrl[0]['title'],
'as_seo_title' => $resultSeoUrl[0]['title'],
'as_seo_description' => $resultSeoUrl[0]['description'],
'as_cross_links' => AdvancedSearchSeoClass::getCrossLinksSeo((int)$this->context->language->id, $resultSeoUrl[0]['id_seo']),
));
} else {
Tools::redirect('404');
}
}
protected function setProductFilterList()
{
$productFilterListSource = Tools::getValue('productFilterListSource');
if (in_array($productFilterListSource, As4SearchEngine::$validPageName)) {
As4SearchEngine::$productFilterListSource = $productFilterListSource;
if ($productFilterListSource == 'search' || $productFilterListSource == 'jolisearch' || $productFilterListSource == 'module-ambjolisearch-jolisearch') {
$productFilterListData = AdvancedSearchCoreClass::getDataUnserialized(Tools::getValue('productFilterListData'));
if ($productFilterListData !== false) {
As4SearchEngine::$productFilterListData = $productFilterListData;
}
}
$this->module->setProductFilterContext();
}
}
protected function setSmartyVars()
{
$nb_products = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterions,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterions)),
(int)$this->pageNb,
(int)Tools::getValue('n', $this->searchInstance->products_per_page),
true
);
$products = As4SearchEngine::getProductsSearched(
$this->idSearch,
$this->criterions,
As4SearchEngine::getCriterionGroupsTypeAndDisplay($this->idSearch, array_keys($this->criterions)),
(int)$this->pageNb,
(int)Tools::getValue('n', $this->searchInstance->products_per_page),
false
);
if ($this->pageNb > 1 && !$products) {
$this->redirectToSeoPageIndex();
}
$this->module->_assignPagination($this->searchInstance->products_per_page, $nb_products);
$this->module->_assignProductSort($this->searchInstance);
$link_pm = new LinkPM($this->context->link->protocol_link, $this->context->link->protocol_content);
$this->context->smarty->assign(array(
'products' => $products,
'nb_products' => $nb_products,
'id_search' => $this->idSearch,
'request' => $link_pm->getPaginationLink(false, false, false, true),
'link' => $link_pm,
'as_obj' => $this->module,
));
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getIdSeo()
{
return $this->idSeo;
}
public function getSelectedCriterions()
{
return $this->criterions;
}
public function getOriginalCriterions()
{
return $this->originalCriterions;
}
}

View File

@@ -0,0 +1,230 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchQuery;
use PrestaShop\PrestaShop\Core\Product\Search\SortOrder;
use PrestaShop\PrestaShop\Adapter\Category\CategoryProductSearchProvider;
use PrestaShop\PrestaShop\Adapter\Image\ImageRetriever;
use PrestaShop\PrestaShop\Core\Product\Search\ProductSearchResult;
class pm_advancedsearch4seoModuleFrontController extends AdvancedSearchProductListingFrontController
{
protected $idSeo;
protected $idSearch;
protected $searchInstance;
protected $seoUrl;
protected $pageNb = 1;
protected $criterions;
protected $originalCriterions;
protected $seoPageInstance;
protected $indexState = 'index';
public function init()
{
if (!isset($this->module) || !is_object($this->module)) {
$this->module = Module::getInstanceByName('pm_advancedsearch4');
}
parent::init();
$this->php_self = 'module-pm_advancedsearch4-seo';
$this->setSEOTags();
$this->setProductFilterList();
$this->setSmartyVars();
if (Tools::getIsset('from-xhr')) {
$this->doProductSearch('');
} else {
$this->template = 'module:pm_advancedsearch4/views/templates/front/'.Tools::substr(_PS_VERSION_, 0, 3).'/seo-page.tpl';
}
}
protected function redirectToSeoPageIndex()
{
$seoObj = new AdvancedSearchSeoClass($this->idSeo, $this->context->language->id);
if (Validate::isLoadedObject($seoObj)) {
Tools::redirect($this->context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => (int)$seoObj->id, 'seo_url' => $seoObj->seo_url), null, (int)$this->context->language->id));
} else {
Tools::redirect('index');
}
}
protected function setSEOTags()
{
$this->idSeo = (int)Tools::getValue('id_seo');
$this->seoUrl = Tools::getValue('seo_url');
$this->pageNb = (int)Tools::getValue('page', 1);
if ($this->seoUrl && $this->idSeo) {
$resultSeoUrl = AdvancedSearchSeoClass::getSeoSearchByIdSeo((int)$this->idSeo, (int)$this->context->language->id);
if (!$resultSeoUrl) {
Tools::redirect('404');
}
$this->seoPageInstance = new AdvancedSearchSeoClass($this->idSeo, $this->context->language->id);
$this->idSearch = (int)$resultSeoUrl[0]['id_search'];
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
if ($resultSeoUrl[0]['deleted']) {
header("Status: 301 Moved Permanently", false, 301);
Tools::redirect('index');
}
if (!$this->searchInstance->active) {
header("Status: 307 Temporary Redirect", false, 307);
Tools::redirect('index');
}
$seoUrlCheck = current(explode('/', $this->seoUrl));
if ($resultSeoUrl[0]['seo_url'] != $seoUrlCheck) {
header("Status: 301 Moved Permanently", false, 301);
$this->redirectToSeoPageIndex();
die();
}
$hasPriceCriterionGroup = false;
if (is_array($this->criterions) && sizeof($this->criterions)) {
$selected_criteria_groups_type = As4SearchEngine::getCriterionGroupsTypeAndDisplay((int)$this->id_search, array_keys($this->criterions));
if (is_array($selected_criteria_groups_type) && sizeof($selected_criteria_groups_type)) {
foreach ($selected_criteria_groups_type as $criterionGroup) {
if ($criterionGroup['criterion_group_type'] == 'price') {
$hasPriceCriterionGroup = true;
break;
}
}
}
}
if ($hasPriceCriterionGroup && $resultSeoUrl[0]['id_currency'] && $this->context->cookie->id_currency != (int)$resultSeoUrl[0]['id_currency']) {
$this->context->cookie->id_currency = $resultSeoUrl[0]['id_currency'];
header('Refresh: 1; URL='.$_SERVER['REQUEST_URI']);
die;
}
$criteria = unserialize($resultSeoUrl[0]['criteria']);
if (is_array($criteria) && sizeof($criteria)) {
$this->criterions = PM_AdvancedSearch4::getArrayCriteriaFromSeoArrayCriteria($criteria);
$this->criterions = As4SearchEngine::cleanArrayCriterion($this->criterions);
}
$searchQuery = implode('/', array_slice(explode('/', $this->seoUrl), 1));
$criterionsList = As4SearchEngine::getCriterionsFromURL($this->idSearch, $searchQuery);
if (is_array($criterionsList) && sizeof($criterionsList)) {
if (is_array($this->criterions) && sizeof($this->criterions)) {
$arrayDiff = $criterionsList;
foreach ($arrayDiff as $arrayDiffKey => $arrayDiffRow) {
if (isset($this->criterions[$arrayDiffKey]) && $this->criterions[$arrayDiffKey] == $arrayDiffRow) {
unset($arrayDiff[$arrayDiffKey]);
}
}
if (is_array($arrayDiff) && sizeof($arrayDiff)) {
$this->indexState = 'noindex';
}
unset($arrayDiff);
} else {
$this->indexState = 'noindex';
}
}
$this->originalCriterions = $this->criterions;
$this->criterions += $criterionsList;
$this->context->smarty->assign(array(
'as_is_seo_page' => true,
'as_cross_links' => AdvancedSearchSeoClass::getCrossLinksSeo((int)$this->context->language->id, $resultSeoUrl[0]['id_seo']),
));
} else {
Tools::redirect('404');
}
}
protected function setProductFilterList()
{
$productFilterListSource = Tools::getValue('productFilterListSource');
if (in_array($productFilterListSource, As4SearchEngine::$validPageName)) {
As4SearchEngine::$productFilterListSource = $productFilterListSource;
if ($productFilterListSource == 'search' || $productFilterListSource == 'jolisearch' || $productFilterListSource == 'module-ambjolisearch-jolisearch') {
$productFilterListData = AdvancedSearchCoreClass::getDataUnserialized(Tools::getValue('productFilterListData'));
if ($productFilterListData !== false) {
As4SearchEngine::$productFilterListData = $productFilterListData;
}
}
$this->module->setProductFilterContext();
}
}
protected function setSmartyVars()
{
$variables = $this->getProductSearchVariables();
if ($this->pageNb < 1 || ($this->pageNb > 1 && empty($variables['products']))) {
$this->redirectToSeoPageIndex();
}
$this->context->smarty->assign(array(
'listing' => $variables,
'id_search' => $this->idSearch,
'as_seo_description' => $this->seoPageInstance->description,
'as_seo_title' => $this->seoPageInstance->title,
'as_see_also_txt' => $this->module->l('See also', 'seo-17'),
));
}
public function getBreadcrumbLinks()
{
$breadcrumb = parent::getBreadcrumbLinks();
$breadcrumb['links'][] = array(
'title' => $this->seoPageInstance->title,
'url' => $this->seoPageInstance->seo_url,
);
return $breadcrumb;
}
public function getSearchEngine()
{
return $this->searchInstance;
}
public function getIdSeo()
{
return $this->idSeo;
}
public function getSelectedCriterions()
{
return $this->criterions;
}
public function getCriterionsList()
{
return $this->getSelectedCriterions();
}
public function getOriginalCriterions()
{
return $this->originalCriterions;
}
public function getCanonicalURL()
{
return $this->context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => (int)$this->seoPageInstance->id, 'seo_url' => $this->seoPageInstance->seo_url), null, (int)$this->context->language->id);
}
public function getListingLabel()
{
return $this->seoPageInstance->title;
}
protected function getDefaultProductSearchProvider()
{
return new As4SearchProvider(
$this->module,
$this->getTranslator(),
$this->searchInstance,
$this->getSelectedCriterions()
);
}
public function getTemplateVarPage()
{
$page = parent::getTemplateVarPage();
$page['meta']['robots'] = $this->indexState;
$page['meta']['title'] = $this->seoPageInstance->meta_title;
$page['meta']['description'] = $this->seoPageInstance->meta_description;
$page['meta']['keywords'] = $this->seoPageInstance->meta_keywords;
$page['page_name'] = 'advancedsearch-seo-' . (int)$this->idSeo;
$page['body_classes']['advancedsearch-seo'] = true;
$page['body_classes']['advancedsearch-seo-' . (int)$this->idSeo] = true;
return $page;
}
protected function updateQueryString(array $extraParams = null)
{
if ($extraParams === null) {
$extraParams = array();
}
return As4SearchEngine::generateURLFromCriterions($this->getSearchEngine()->id, $this->getCriterionsList(), null, $extraParams);
}
}

View File

@@ -0,0 +1,24 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
// Load Search Providers for PrestaShop 1.7
if (version_compare(_PS_VERSION_, '1.7.0.0', '>=')) {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/seo-17.php');
} else {
include_once(_PS_ROOT_DIR_ . '/modules/pm_advancedsearch4/controllers/front/seo-16.php');
}

View File

@@ -0,0 +1,60 @@
<?php
/**
*
* @author Presta-Module.com <support@presta-module.com>
* @copyright Presta-Module
* @license Commercial
*
* ____ __ __
* | _ \ | \/ |
* | |_) | | |\/| |
* | __/ | | | |
* |_| |_| |_|
*
****/
if (!defined('_PS_VERSION_')) {
exit;
}
class pm_advancedsearch4seositemapModuleFrontController extends ModuleFrontController
{
private $idSearch;
private $searchInstance;
public function init()
{
if (ob_get_length() > 0) {
ob_clean();
}
header('Content-type: text/xml');
$this->idSearch = (int)Tools::getValue('id_search');
$this->searchInstance = new AdvancedSearchClass((int)$this->idSearch, (int)$this->context->language->id);
if (Validate::isLoadedObject($this->searchInstance)) {
$xmlSiteMapHeader = <<<XML
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
</urlset>
XML;
$xml = new SimpleXMLElement($xmlSiteMapHeader);
foreach (Language::getLanguages(true, (int)$this->context->shop->id) as $language) {
$seoSearchs = AdvancedSearchSeoClass::getSeoSearchs($language['id_lang'], false, $this->idSearch);
foreach ($seoSearchs as $seoSearch) {
$nbCriteria = count(unserialize($seoSearch['criteria']));
if ($nbCriteria <= 3) {
$priority = 0.7;
} elseif ($nbCriteria <= 5) {
$priority = 0.6;
} else {
$priority = 0.5;
}
$sitemap = $xml->addChild('url');
$sitemap->addChild('loc', $this->context->link->getModuleLink('pm_advancedsearch4', 'seo', array('id_seo' => (int)$seoSearch['id_seo'], 'seo_url' => $seoSearch['seo_url']), null, (int)$language['id_lang']));
$sitemap->addChild('priority', $priority);
$sitemap->addChild('changefreq', 'weekly');
}
}
die($xml->asXML());
} else {
Tools::redirect('404');
}
}
}