// Merge -> revision 8589
This commit is contained in:
1 parent
cfd6d2a2ab
commit
c405e1a55b
3 files changed
+107
-148
No files matched your search
@@ -171,6 +171,7 @@ class CategoryControllerCore extends FrontController
|
|||||||
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
|
Module::hookExec('productListAssign', array('nbProducts' => &$this->nbProducts, 'catProducts' => &$this->cat_products, 'hookExecuted' => &$hookExecuted));
|
||||||
if (!$hookExecuted)
|
if (!$hookExecuted)
|
||||||
{
|
{
|
||||||
|
self::$smarty->assign('categoryNameComplement', '');
|
||||||
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
|
$this->nbProducts = $this->category->getProducts(NULL, NULL, NULL, $this->orderBy, $this->orderWay, true);
|
||||||
$this->pagination((int)$this->nbProducts);
|
$this->pagination((int)$this->nbProducts);
|
||||||
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
|
$this->cat_products = $this->category->getProducts($this->context->language->id, (int)$this->p, (int)$this->n, $this->orderBy, $this->orderWay);
|
||||||
|
|||||||
@@ -34,30 +34,39 @@ $(document).ready(function()
|
|||||||
cancelFilter();
|
cancelFilter();
|
||||||
openCloseFilter();
|
openCloseFilter();
|
||||||
|
|
||||||
|
// Click on color
|
||||||
$('#layered_form input[type=button], #layered_form label.layered_color').live('click', function()
|
$('#layered_form input[type=button], #layered_form label.layered_color').live('click', function()
|
||||||
{
|
{
|
||||||
if (!$('\'input[name='+$(this).attr('name')+']:hidden\'').length)
|
if (!$('\'input[name='+$(this).attr('name')+']:hidden\'').length)
|
||||||
$('<input />').attr('type', 'hidden').attr('name', $(this).attr('name')).val($(this).attr('rel')).appendTo('#layered_form');
|
$('<input />').attr('type', 'hidden').attr('name', $(this).attr('name')).val($(this).attr('rel')).appendTo('#layered_form');
|
||||||
else
|
else
|
||||||
$('\'input[name='+$(this).attr('name')+']:hidden\'').remove();
|
$('\'input[name='+$(this).attr('name')+']:hidden\'').remove();
|
||||||
|
window.location = '#'+$(this).next().children(1).attr('href').replace(/https?:\/\/.*\/\d+-[^\/]+/, '');
|
||||||
reloadContent();
|
reloadContent();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Click on checkbox
|
||||||
$('#layered_form input[type=checkbox]').live('click', function()
|
$('#layered_form input[type=checkbox]').live('click', function()
|
||||||
{
|
{
|
||||||
|
window.location = '#'+$(this).next().children(1).attr('href').replace(/https?:\/\/.*\/\d+-[^\/]+/, '');
|
||||||
reloadContent();
|
reloadContent();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Click on label
|
||||||
$("label a").live({
|
$("label a").live({
|
||||||
click: function() {
|
click: function() {
|
||||||
|
if($(this).parent().parent().find('input').attr('disabled') == '')
|
||||||
|
{
|
||||||
|
window.location = '#'+this.href.replace(/https?:\/\/.*\/\d+-[^\/]+/, '');
|
||||||
$(this).parent().parent().find('input').click();
|
$(this).parent().parent().find('input').click();
|
||||||
reloadContent();
|
reloadContent();
|
||||||
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
paginationButton();
|
paginationButton();
|
||||||
initLayered();
|
initLayered();
|
||||||
reloadContent();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
function addSlider(type, data, unit)
|
function addSlider(type, data, unit)
|
||||||
@@ -81,7 +90,14 @@ function initSliders()
|
|||||||
function initLayered()
|
function initLayered()
|
||||||
{
|
{
|
||||||
initSliders();
|
initSliders();
|
||||||
var params = document.location.toString();
|
if (window.location.href.split('#').length == 2)
|
||||||
|
{
|
||||||
|
var params = window.location.href.split('#')[1];
|
||||||
|
reloadContent('&selected_filters='+params, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var params = window.location.href;
|
||||||
params = friendlyUrl(params, 'long');
|
params = friendlyUrl(params, 'long');
|
||||||
params = params.split('#');
|
params = params.split('#');
|
||||||
params.shift();
|
params.shift();
|
||||||
@@ -99,6 +115,8 @@ function initLayered()
|
|||||||
$('#'+val.split('=')[0]).click();
|
$('#'+val.split('=')[0]).click();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
reloadContent();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatelink(link)
|
function updatelink(link)
|
||||||
@@ -216,15 +234,14 @@ function openCloseFilter()
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function reloadContent(params_plus)
|
function reloadContent(params_plus, force)
|
||||||
{
|
{
|
||||||
if (typeof(allowReload) == 'undefined')
|
if (typeof(allowReload) == 'undefined' && typeof(force) != 'undefined' && force != true)
|
||||||
{
|
{
|
||||||
allowReload = true;
|
allowReload = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
window.location = updatelink( window.location.href);
|
|
||||||
for(i = 0; i < ajaxQueries.length; i++)
|
for(i = 0; i < ajaxQueries.length; i++)
|
||||||
ajaxQueries[i].abort();
|
ajaxQueries[i].abort();
|
||||||
ajaxQueries = new Array();
|
ajaxQueries = new Array();
|
||||||
|
|||||||
@@ -66,6 +66,9 @@ class BlockLayered extends Module
|
|||||||
self::_installFriendlyUrlTable();
|
self::_installFriendlyUrlTable();
|
||||||
self::_installIndexableAttributeTable();
|
self::_installIndexableAttributeTable();
|
||||||
|
|
||||||
|
$this->indexUrl();
|
||||||
|
self::fullIndexProcess();
|
||||||
|
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -75,12 +78,12 @@ class BlockLayered extends Module
|
|||||||
Configuration::deleteByName('PS_LAYERED_HIDE_0_VALUES');
|
Configuration::deleteByName('PS_LAYERED_HIDE_0_VALUES');
|
||||||
Configuration::deleteByName('PS_LAYERED_SHOW_QTIES');
|
Configuration::deleteByName('PS_LAYERED_SHOW_QTIES');
|
||||||
|
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'price_static_index');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'price_static_index');
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_friendly_url');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_friendly_url');
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_indexable_attribute_group');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_indexable_attribute_group');
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_indexable_feature');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_indexable_feature');
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_category');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_category');
|
||||||
Db::getInstance()->Execute('DROP TABLE '._DB_PREFIX_.'layered_filter');
|
Db::getInstance()->Execute('DROP TABLE IF EXISTS '._DB_PREFIX_.'layered_filter');
|
||||||
|
|
||||||
return parent::uninstall();
|
return parent::uninstall();
|
||||||
}
|
}
|
||||||
@@ -138,20 +141,15 @@ class BlockLayered extends Module
|
|||||||
/*
|
/*
|
||||||
* Url indexation
|
* Url indexation
|
||||||
*/
|
*/
|
||||||
public function indexUrl($cursor = array(), $ajax = false, $truncate = true)
|
public function indexUrl($ajax = false, $truncate = true)
|
||||||
{
|
{
|
||||||
if($truncate)
|
if($truncate)
|
||||||
Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_friendly_url');
|
Db::getInstance()->execute('TRUNCATE '._DB_PREFIX_.'layered_friendly_url');
|
||||||
|
|
||||||
if(!empty($idCategory))
|
|
||||||
$categorySubQuery = ' AND lc.id_category = '.(int)$idCategory;
|
|
||||||
else
|
|
||||||
$categorySubQuery = '';
|
|
||||||
|
|
||||||
$attributeValues = array();
|
$attributeValues = array();
|
||||||
$filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT lc.*, id_lang, name, link_rewrite, cl.id_category
|
$filters = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT lc.*, id_lang, name, link_rewrite, cl.id_category
|
||||||
FROM '._DB_PREFIX_.'layered_category lc
|
FROM '._DB_PREFIX_.'layered_category lc
|
||||||
INNER JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = lc.id_category AND lc.id_category <> 1'.$categorySubQuery.')
|
INNER JOIN '._DB_PREFIX_.'category_lang cl ON (cl.id_category = lc.id_category AND lc.id_category <> 1 )
|
||||||
ORDER BY position ASC');
|
ORDER BY position ASC');
|
||||||
if (!$filters)
|
if (!$filters)
|
||||||
return;
|
return;
|
||||||
@@ -177,7 +175,7 @@ class BlockLayered extends Module
|
|||||||
if (!isset($attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']]))
|
if (!isset($attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']]))
|
||||||
$attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']] = array();
|
$attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']] = array();
|
||||||
$attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']][] = array('name' => $attribute['name'],
|
$attributeValues[$attribute['id_lang']][$filter['id_category']]['c'.$attribute['id_name']][] = array('name' => $attribute['name'],
|
||||||
'id_name' => 'c'.$attribute['id_name'], 'value' => $attribute['value'], 'id_value' => $attribute['id_value'].'_'.$attribute['id_name'],
|
'id_name' => 'c'.$attribute['id_name'], 'value' => $attribute['value'], 'id_value' => $attribute['id_name'].'_'.$attribute['id_value'],
|
||||||
'id_id_value' => $attribute['id_value'], 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']);
|
'id_id_value' => $attribute['id_value'], 'category_name' => $filter['link_rewrite'], 'type' => $filter['type']);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -209,8 +207,9 @@ class BlockLayered extends Module
|
|||||||
SELECT cl.name, cl.id_lang, c.id_category
|
SELECT cl.name, cl.id_lang, c.id_category
|
||||||
FROM '._DB_PREFIX_.'category c
|
FROM '._DB_PREFIX_.'category c
|
||||||
INNER JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category)
|
INNER JOIN '._DB_PREFIX_.'category_lang cl ON (c.id_category = cl.id_category)
|
||||||
WHERE nleft > (SELECT nleft FROM '._DB_PREFIX_.'category WHERE id_category = 2)
|
WHERE nleft > (SELECT nleft FROM '._DB_PREFIX_.'category WHERE id_category = '.$filter['id_category'].')
|
||||||
AND nright < (SELECT nright FROM '._DB_PREFIX_.'category WHERE id_category = 2)
|
AND nright < (SELECT nright FROM '._DB_PREFIX_.'category WHERE id_category = '.$filter['id_category'].')
|
||||||
|
AND cl.id_lang = '.(int)$filter['id_lang'].'
|
||||||
');
|
');
|
||||||
foreach($categories as $category)
|
foreach($categories as $category)
|
||||||
{
|
{
|
||||||
@@ -230,6 +229,7 @@ class BlockLayered extends Module
|
|||||||
$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
||||||
SELECT m.name as name,l.id_lang as id_lang, id_manufacturer
|
SELECT m.name as name,l.id_lang as id_lang, id_manufacturer
|
||||||
FROM '._DB_PREFIX_.'manufacturer m , '._DB_PREFIX_.'lang l
|
FROM '._DB_PREFIX_.'manufacturer m , '._DB_PREFIX_.'lang l
|
||||||
|
WHERE l.id_lang = '.(int)$filter['id_lang'].'
|
||||||
');
|
');
|
||||||
|
|
||||||
foreach ($manufacturers as $manufacturer)
|
foreach ($manufacturers as $manufacturer)
|
||||||
@@ -264,107 +264,23 @@ class BlockLayered extends Module
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
$maxExecutionTime = ini_get('max_execution_time') * 0.9; // 90% of safety margin
|
|
||||||
if ($maxExecutionTime > 5)
|
|
||||||
$maxExecutionTime = 5;
|
|
||||||
$startTime = microtime(true);
|
|
||||||
$memoryLimit = (Tools::getMemoryLimit() * 0.9);
|
|
||||||
|
|
||||||
if (empty($cursor))
|
|
||||||
{
|
|
||||||
$cursor = array(
|
|
||||||
'attribute_values' => 0,
|
|
||||||
'tmp1' => 0,
|
|
||||||
'possibility' => 0,
|
|
||||||
'total' => 0
|
|
||||||
);
|
|
||||||
|
|
||||||
if ($ajax)
|
|
||||||
{
|
|
||||||
// Calculation, to eval progression
|
|
||||||
$nbPosibilities = 0;
|
|
||||||
foreach ($attributeValues as $idLang => $tmp1)
|
|
||||||
foreach ($tmp1 as $key => $tmp2)
|
|
||||||
{
|
|
||||||
$nbPosibilitiesTmp = 1;
|
|
||||||
foreach ($tmp2 as $name)
|
|
||||||
{
|
|
||||||
$count = count($name)+1;
|
|
||||||
$nbPosibilitiesTmp *= $count;
|
|
||||||
}
|
|
||||||
$nbPosibilities += $nbPosibilitiesTmp;
|
|
||||||
}
|
|
||||||
$cursor['nb_posibilities'] = $nbPosibilities;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Foreach langs
|
// Foreach langs
|
||||||
$attributeValuesKeys = array_keys($attributeValues);
|
$attributeValuesKeys = array_keys($attributeValues);
|
||||||
for (;$cursor['attribute_values'] < count($attributeValuesKeys); $cursor['attribute_values']++)
|
foreach($attributeValues as $id_lang => $attributesByCategoriesByLang)
|
||||||
{
|
{
|
||||||
$id_lang = $attributeValuesKeys[$cursor['attribute_values']];
|
|
||||||
$tmp1 = &$attributeValues[$id_lang];
|
|
||||||
|
|
||||||
// Foreach categories
|
// Foreach categories
|
||||||
$tmp1Keys = array_keys($tmp1);
|
foreach($attributesByCategoriesByLang as $id_category => $attributesByCategory)
|
||||||
for(; $cursor['tmp1'] < count($tmp1Keys); $cursor['tmp1']++)
|
|
||||||
{
|
{
|
||||||
$id_category = $tmp1Keys[$cursor['tmp1']];
|
foreach($attributesByCategory as $attribute)
|
||||||
$tmp2 = &$tmp1[$id_category];
|
|
||||||
|
|
||||||
$cursors = array_fill(0, count($tmp2), 0);
|
|
||||||
$limits = array();
|
|
||||||
$nbName = count($tmp2);
|
|
||||||
$nbPosibilities = 1;
|
|
||||||
$tmp2 = array_values($tmp2);
|
|
||||||
|
|
||||||
// fill limits and calculate the number of combination possible
|
|
||||||
foreach ($tmp2 as $name)
|
|
||||||
{
|
{
|
||||||
$count = count($name)+1;
|
foreach($attribute as $param)
|
||||||
$limits[] = $count;
|
|
||||||
$nbPosibilities *= $count;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Loop all url posibilities
|
|
||||||
for (; $cursor['possibility'] < $nbPosibilities; $cursor['possibility']++)
|
|
||||||
{
|
{
|
||||||
if ($memoryLimit < memory_get_peak_usage() OR (microtime(true) - $startTime) > $maxExecutionTime)
|
$selectedFilters = array();
|
||||||
{
|
$link = '/'.str_replace('-', '_', Tools::link_rewrite($param['name'])).'-'.str_replace('-', '_', Tools::link_rewrite($param['value']));
|
||||||
if ($ajax)
|
$selectedFilters[$param['type']] = array();
|
||||||
return Tools::jsonEncode(array('cursor' => Tools::jsonEncode($cursor)));
|
if (!isset($param['id_id_value']))
|
||||||
Tools::file_get_contents(Tools::getProtocol().Tools::getHttpHost().'/modules/blocklayered/blocklayered-url-indexer.php'.'?token='.substr(Tools::encrypt('blocklayered/index'), 0, 10).'&cursor='.Tools::jsonEncode($cursor));
|
$param['id_id_value'] = $param['id_value'];
|
||||||
return 1;
|
$selectedFilters[$param['type']][$param['id_id_value']] = $param['id_value'];
|
||||||
}
|
|
||||||
|
|
||||||
$cursor['total']++;
|
|
||||||
// generate all parameters posibilities
|
|
||||||
$a = 1;
|
|
||||||
foreach ($cursors as $position => $cursorP)
|
|
||||||
{
|
|
||||||
// Get all possible combination (one by group)
|
|
||||||
// 0 means no combinations selected in the group
|
|
||||||
$cursors[$position] = (($cursor['possibility'] / ($a)) % $limits[$position]);
|
|
||||||
$a *= $limits[$position];
|
|
||||||
}
|
|
||||||
$link = '';
|
|
||||||
$selectedFilters = array('category' => array());
|
|
||||||
|
|
||||||
// Generate url with selected filters
|
|
||||||
foreach ($cursors as $position => $cursorP)
|
|
||||||
{
|
|
||||||
if ($cursorP != 0)
|
|
||||||
{
|
|
||||||
$link .= '/'.Tools::link_rewrite($tmp2[$position][$cursorP-1]['name'].'-'.$tmp2[$position][$cursorP-1]['value']);
|
|
||||||
if (!isset($selectedFilters[$tmp2[$position][$cursorP-1]['type']]))
|
|
||||||
$selectedFilters[$tmp2[$position][$cursorP-1]['type']] = array();
|
|
||||||
if (!isset($tmp2[$position][$cursorP-1]['id_id_value']))
|
|
||||||
$tmp2[$position][$cursorP-1]['id_id_value'] = $tmp2[$position][$cursorP-1]['id_value'];
|
|
||||||
$selectedFilters[$tmp2[$position][$cursorP-1]['type']][$tmp2[$position][$cursorP-1]['id_id_value']] = $tmp2[$position][$cursorP-1]['id_value'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$urlKey = md5($link);
|
$urlKey = md5($link);
|
||||||
$idLayeredFriendlyUrl = Db::getInstance()->getValue('SELECT id_layered_friendly_url FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `id_lang` = '.$id_lang.' AND `url_key` = \''.$urlKey.'\'');
|
$idLayeredFriendlyUrl = Db::getInstance()->getValue('SELECT id_layered_friendly_url FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `id_lang` = '.$id_lang.' AND `url_key` = \''.$urlKey.'\'');
|
||||||
if ($idLayeredFriendlyUrl == false)
|
if ($idLayeredFriendlyUrl == false)
|
||||||
@@ -373,9 +289,8 @@ class BlockLayered extends Module
|
|||||||
$idLayeredFriendlyUrl = Db::getInstance()->Insert_ID();
|
$idLayeredFriendlyUrl = Db::getInstance()->Insert_ID();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$cursor['possibility'] = 0;
|
|
||||||
}
|
}
|
||||||
$cursor['tmp1'] = 0;
|
}
|
||||||
}
|
}
|
||||||
if ($ajax)
|
if ($ajax)
|
||||||
return '{"result": 1}';
|
return '{"result": 1}';
|
||||||
@@ -545,7 +460,7 @@ class BlockLayered extends Module
|
|||||||
WHERE `active` = 1 AND psi.id_product IS NULL');
|
WHERE `active` = 1 AND psi.id_product IS NULL');
|
||||||
|
|
||||||
$maxExecutionTime = ini_get('max_execution_time') * 0.9; // 90% of safety margin
|
$maxExecutionTime = ini_get('max_execution_time') * 0.9; // 90% of safety margin
|
||||||
if ($maxExecutionTime > 5)
|
if ($maxExecutionTime > 5 || $maxExecutionTime <= 0)
|
||||||
$maxExecutionTime = 5;
|
$maxExecutionTime = 5;
|
||||||
|
|
||||||
$startTime = microtime(true);
|
$startTime = microtime(true);
|
||||||
@@ -949,9 +864,6 @@ class BlockLayered extends Module
|
|||||||
'.$this->l('A nightly rebuild is recommended.').'
|
'.$this->l('A nightly rebuild is recommended.').'
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
$(\'#url-indexer\').click(function() {
|
$(\'#url-indexer\').click(function() {
|
||||||
if (this.cursor == undefined)
|
|
||||||
this.cursor = {};
|
|
||||||
|
|
||||||
if (this.legend == undefined)
|
if (this.legend == undefined)
|
||||||
this.legend = $(this).html();
|
this.legend = $(this).html();
|
||||||
|
|
||||||
@@ -980,19 +892,13 @@ class BlockLayered extends Module
|
|||||||
success: function(res)
|
success: function(res)
|
||||||
{
|
{
|
||||||
this.running = false;
|
this.running = false;
|
||||||
if (res.result)
|
this.restartAllowed = true;
|
||||||
{
|
|
||||||
this.cursor = 0;
|
this.cursor = 0;
|
||||||
$(\'#indexing-warning\').hide();
|
$(\'#indexing-warning\').hide();
|
||||||
$(this).html(this.legend);
|
$(this).html(this.legend);
|
||||||
$(\'#ajax-message-ok span\').html(\''.$this->l('Url indexation finished').'\');
|
$(\'#ajax-message-ok span\').html(\''.$this->l('Url indexation finished').'\');
|
||||||
$(\'#ajax-message-ok\').show();
|
$(\'#ajax-message-ok\').show();
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
this.cursor = res.cursor;
|
|
||||||
var cursorObj = JSON.parse(this.cursor);
|
|
||||||
$(this).html(this.legend+\' (in progress, \'+(cursorObj.total / cursorObj.nb_posibilities * 100).toFixed(2) +\'%)\');
|
|
||||||
this.click();
|
|
||||||
},
|
},
|
||||||
error: function(res)
|
error: function(res)
|
||||||
{
|
{
|
||||||
@@ -1052,7 +958,7 @@ class BlockLayered extends Module
|
|||||||
}
|
}
|
||||||
this.cursor = parseInt(res.cursor);
|
this.cursor = parseInt(res.cursor);
|
||||||
$(this).html(this.legend+\' (in progress, \'+res.count+\' products to index)\');
|
$(this).html(this.legend+\' (in progress, \'+res.count+\' products to index)\');
|
||||||
this.click();
|
$(this).click();
|
||||||
},
|
},
|
||||||
error: function(res)
|
error: function(res)
|
||||||
{
|
{
|
||||||
@@ -1396,11 +1302,41 @@ class BlockLayered extends Module
|
|||||||
if ($id_parent == 1)
|
if ($id_parent == 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (strpos($_SERVER['SCRIPT_FILENAME'], 'blocklayered-ajax.php') === false)
|
if (strpos($_SERVER['SCRIPT_FILENAME'], 'blocklayered-ajax.php') === false || Tools::getValue('selected_filters') !== false)
|
||||||
{
|
{
|
||||||
$data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5(preg_replace('/\/(\w*)\/([0-9]+[-\w]*)/', '',$_SERVER['REQUEST_URI'])).'\'');
|
if(Tools::getValue('selected_filters'))
|
||||||
if($data !== false)
|
$url = Tools::getValue('selected_filters');
|
||||||
return unserialize($data);
|
else
|
||||||
|
$url = preg_replace('/\/(\w*)\/([0-9]+[-\w]*)/', '', $_SERVER['REQUEST_URI']);
|
||||||
|
|
||||||
|
$urlAttributes = explode('/',$url);
|
||||||
|
array_shift($urlAttributes);
|
||||||
|
$selectedFilters = array('category' => array());
|
||||||
|
if(!empty($urlAttributes))
|
||||||
|
{
|
||||||
|
foreach($urlAttributes as $urlAttribute)
|
||||||
|
{
|
||||||
|
$urlParameters = explode('-', $urlAttribute);
|
||||||
|
$attributeName = array_shift($urlParameters);
|
||||||
|
foreach($urlParameters as $urlParameter)
|
||||||
|
{
|
||||||
|
$data = Db::getInstance()->getValue('SELECT data FROM `'._DB_PREFIX_.'layered_friendly_url` WHERE `url_key` = \''.md5('/'.$attributeName.'-'.$urlParameter).'\'');
|
||||||
|
if($data)
|
||||||
|
foreach(unserialize($data) as $keyParams => $params)
|
||||||
|
{
|
||||||
|
if(!isset($selectedFilters[$keyParams]))
|
||||||
|
$selectedFilters[$keyParams] = array();
|
||||||
|
foreach($params as $keyParam => $param)
|
||||||
|
{
|
||||||
|
if(!isset($selectedFilters[$keyParams][$keyParam]))
|
||||||
|
$selectedFilters[$keyParams][$keyParam] = array();
|
||||||
|
$selectedFilters[$keyParams][$keyParam] = $param;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $selectedFilters;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Analyze all the filters selected by the user and store them into a tab */
|
/* Analyze all the filters selected by the user and store them into a tab */
|
||||||
@@ -1936,13 +1872,15 @@ class BlockLayered extends Module
|
|||||||
}
|
}
|
||||||
|
|
||||||
//generate SEO link
|
//generate SEO link
|
||||||
|
$paramSelected = '';
|
||||||
$optionCheckedArray = array();
|
$optionCheckedArray = array();
|
||||||
$paramGroupSelectedArray = array();
|
$paramGroupSelectedArray = array();
|
||||||
$titleValues = array();
|
$titleValues = array();
|
||||||
$link = new Link();
|
$link = new Link();
|
||||||
|
|
||||||
$linkBase = $link->getCategoryLink($id_parent,Category::getLinkRewrite($id_parent, (int)($cookie->id_lang)), (int)($cookie->id_lang));
|
$linkBase = $link->getCategoryLink($id_parent,Category::getLinkRewrite($id_parent, (int)($cookie->id_lang),(int)($cookie->id_lang) ), (int)($cookie->id_lang));
|
||||||
$filterBlockList = array();
|
$filterBlockList = array();
|
||||||
|
//get filters checked by group
|
||||||
foreach ($filterBlocks as $typeFilter)
|
foreach ($filterBlocks as $typeFilter)
|
||||||
{
|
{
|
||||||
$paramGroupSelected = '';
|
$paramGroupSelected = '';
|
||||||
@@ -1952,6 +1890,7 @@ class BlockLayered extends Module
|
|||||||
{
|
{
|
||||||
$paramGroupSelected .= '-'.Tools::link_rewrite($value['name']);
|
$paramGroupSelected .= '-'.Tools::link_rewrite($value['name']);
|
||||||
$paramGroupSelectedArray [Tools::link_rewrite($typeFilter['name'])][] = Tools::link_rewrite($value['name']);
|
$paramGroupSelectedArray [Tools::link_rewrite($typeFilter['name'])][] = Tools::link_rewrite($value['name']);
|
||||||
|
|
||||||
if (!isset($titleValues[$typeFilter['name']]))
|
if (!isset($titleValues[$typeFilter['name']]))
|
||||||
$titleValues[$typeFilter['name']] = array();
|
$titleValues[$typeFilter['name']] = array();
|
||||||
$titleValues[$typeFilter['name']][] = $value['name'];
|
$titleValues[$typeFilter['name']][] = $value['name'];
|
||||||
@@ -1960,35 +1899,37 @@ class BlockLayered extends Module
|
|||||||
$paramGroupSelectedArray [Tools::link_rewrite($typeFilter['name'])][] = array();
|
$paramGroupSelectedArray [Tools::link_rewrite($typeFilter['name'])][] = array();
|
||||||
}
|
}
|
||||||
if(!empty($paramGroupSelected))
|
if(!empty($paramGroupSelected))
|
||||||
|
{
|
||||||
|
$paramSelected .= '/'.Tools::link_rewrite($typeFilter['name']).$paramGroupSelected;
|
||||||
$optionCheckedArray[Tools::link_rewrite($typeFilter['name'])] = $paramGroupSelected;
|
$optionCheckedArray[Tools::link_rewrite($typeFilter['name'])] = $paramGroupSelected;
|
||||||
|
|
||||||
$filterBlockList[] = Tools::link_rewrite($typeFilter['name']);
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$blackList = array('weight','price');
|
$blackList = array('weight','price');
|
||||||
|
|
||||||
foreach ($filterBlocks as &$typeFilter)
|
foreach ($filterBlocks as &$typeFilter)
|
||||||
if (count($typeFilter) > 0 AND !in_array($typeFilter['type'], $blackList)){
|
{
|
||||||
|
if(count($typeFilter) > 0 AND !in_array($typeFilter['type'], $blackList))
|
||||||
|
{
|
||||||
foreach ($typeFilter['values'] as $key => $values)
|
foreach ($typeFilter['values'] as $key => $values)
|
||||||
{
|
{
|
||||||
$optionCheckedCloneArray = $optionCheckedArray;
|
$optionCheckedCloneArray = $optionCheckedArray;
|
||||||
//if not filters checked, add parameter
|
//if not filters checked, add parameter
|
||||||
if(!in_array(Tools::link_rewrite($values['name']), $paramGroupSelectedArray[Tools::link_rewrite($typeFilter['name'])]))
|
if(!in_array(Tools::link_rewrite($values['name']), $paramGroupSelectedArray[Tools::link_rewrite($typeFilter['name'])]))
|
||||||
{
|
{
|
||||||
//filter checked
|
//update parameter filter checked before
|
||||||
$optionCheckedCloneArray[Tools::link_rewrite($typeFilter['name'])] = '-'.Tools::link_rewrite($values['name']);
|
if(array_key_exists(Tools::link_rewrite($typeFilter['name']), $optionCheckedArray))
|
||||||
}
|
$optionCheckedCloneArray[Tools::link_rewrite($typeFilter['name'])] = $optionCheckedCloneArray[Tools::link_rewrite($typeFilter['name'])].'-'.str_replace('-', '_', Tools::link_rewrite($values['name']));
|
||||||
$parametersLink = '';
|
else
|
||||||
//create order order by filter position
|
$optionCheckedCloneArray[Tools::link_rewrite($typeFilter['name'])] = '-'.str_replace('-', '_', Tools::link_rewrite($values['name']));
|
||||||
foreach ($filterBlockList as $keyFilter => $valueFilter)
|
|
||||||
{
|
|
||||||
if(!empty($optionCheckedCloneArray[$valueFilter]))
|
|
||||||
$parametersLink .= '/'.$valueFilter.$optionCheckedCloneArray[$valueFilter];
|
|
||||||
}
|
}
|
||||||
|
$parameters = '';
|
||||||
|
foreach ($optionCheckedCloneArray as $keyGroup => $valueGroup)
|
||||||
|
$parameters .= '/'.str_replace('-', '_',$keyGroup).$valueGroup;
|
||||||
//write link
|
//write link
|
||||||
$typeFilter['values'][$key]['link'] = $linkBase.$parametersLink;
|
$typeFilter['values'][$key]['link'] = $linkBase.$parameters;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$nFilters = 0;
|
$nFilters = 0;
|
||||||
if(isset($selectedFilters['price']))
|
if(isset($selectedFilters['price']))
|
||||||
|
|||||||
Reference in new issue
Block a user