From 557e05ae014c11fa1687da79f5f71fa5a692fed3 Mon Sep 17 00:00:00 2001 From: mDeflotte Date: Tue, 29 Nov 2011 18:03:21 +0000 Subject: [PATCH] // Now blocklayered work with PS1.5 and 1.4 // Adding some improvement to the blocklayered : Filters are now customizable (checkbox, radio, ...) git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@10763 b9a71923-0436-4b27-9f14-aed3839534dd --- classes/Controller.php | 6 +- classes/Media.php | 4 +- modules/blocklayered/blocklayered.css | 40 ++- modules/blocklayered/blocklayered.js | 54 +++- modules/blocklayered/blocklayered.php | 354 +++++++++++++++++++++----- modules/blocklayered/blocklayered.tpl | 64 +++-- modules/blocklayered/config.xml | 2 +- modules/blocklayered/fr.php | 8 +- 8 files changed, 446 insertions(+), 86 deletions(-) diff --git a/classes/Controller.php b/classes/Controller.php index ed66cd8ea..8579d8e89 100644 --- a/classes/Controller.php +++ b/classes/Controller.php @@ -143,6 +143,9 @@ abstract class ControllerCore if ($this->checkAccess()) { + if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) + $this->setMedia(); + // postProcess handles ajaxProcess $this->postProcess(); @@ -150,10 +153,7 @@ abstract class ControllerCore $this->redirect(); if (!$this->content_only && ($this->display_header || (isset($this->className) && $this->className))) - { - $this->setMedia(); $this->initHeader(); - } $this->initContent(); diff --git a/classes/Media.php b/classes/Media.php index 5f7dfe164..1ff804680 100755 --- a/classes/Media.php +++ b/classes/Media.php @@ -36,7 +36,7 @@ class MediaCore 'ui.droppable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('uicore', 'ui.widget', 'ui.mouse', 'ui.draggable'), 'theme' => false), 'ui.resizable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true), 'ui.selectable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true), - 'ui.sortable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => false), + 'ui.sortable' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.mouse'), 'theme' => true), 'ui.accordion' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true), 'ui.autocomplete' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget', 'ui.position'), 'theme' => true), 'ui.button' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('ui.core', 'ui.widget'), 'theme' => true), @@ -58,7 +58,7 @@ class MediaCore 'effects.scale' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false), 'effects.shake' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false), 'effects.slide' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false), - 'effects.transfer' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core')) + 'effects.transfer' => array('fileName' => 'jquery.ui.mouse.min.js', 'dependencies' => array('effects.core'), 'theme' => false) ); public static function minifyHTML($html_content) diff --git a/modules/blocklayered/blocklayered.css b/modules/blocklayered/blocklayered.css index 5ee9d203e..8ac36f2d5 100644 --- a/modules/blocklayered/blocklayered.css +++ b/modules/blocklayered/blocklayered.css @@ -4,6 +4,26 @@ #layered_block_left ul { padding-left: 0; + max-height: 100px; + overflow-y: auto; + overflow-x: hidden; + padding-left: 1px; + padding-right: 1px; +} + +#layered_form > div > div { + border-bottom: 1px dotted #CCCCCC; + padding-bottom: 5px; + margin-bottom: 5px; +} + +#layered_block_left .hide-action { + display: block; + text-align: right; + padding-right: 5px; +} +#layered_block_left .hide-action:hover { + text-decoration: underline; } #layered_block_left ul li { @@ -12,11 +32,9 @@ list-style-type: none; } -#layered_block_left #enabled_filters , #layered_url_filter_block{ +#layered_block_left #enabled_filters , #layered_url_filter_block { font-size: 10px; - padding-bottom: 10px; - margin-bottom: 5px; - border-bottom: 1px dotted #CCC; + padding-bottom: 5px; } #layered_block_left #enabled_filters ul li { @@ -75,4 +93,18 @@ } #product_list .warning { margin-top: 13px; +} + +#layered_form .select { + width: 165px; +} +#layered_form .color-option { + margin-left: 0; + width: 16px; + height: 16px; + padding:0; + border: 1px solid #666; +} +#layered_form .color-option.on { + border: 1px solid red; } \ No newline at end of file diff --git a/modules/blocklayered/blocklayered.js b/modules/blocklayered/blocklayered.js index 77cfcc26a..fc66b147b 100644 --- a/modules/blocklayered/blocklayered.js +++ b/modules/blocklayered/blocklayered.js @@ -45,10 +45,20 @@ $(document).ready(function() }); // Click on checkbox - $('#layered_form input[type=checkbox]').live('click', function() + $('#layered_form input, #layered_form select').live('change', function() { reloadContent(); }); + + $('.radio').live('click', function() { + var name = $(this).attr('name'); + $.each($(this).parent().parent().find('input[type=button]'), function (it, item) { + if ($(item).hasClass('on') && $(item).attr('name') != name) { + $(item).click(); + } + }); + return true; + }); // Click on label $('label a').live({ @@ -58,13 +68,45 @@ $(document).ready(function() $(this).parent().parent().find('input').click(); reloadContent(); } - return false; } }); + + layered_hidden_list = {}; + $('.hide-action').live('click', function() { + if (typeof(layered_hidden_list[$(this).parent().find('ul').attr('id')]) == 'undefined' || layered_hidden_list[$(this).parent().find('ul').attr('id')] == false) + { + layered_hidden_list[$(this).parent().find('ul').attr('id')] = true; + } + else + { + layered_hidden_list[$(this).parent().find('ul').attr('id')] = false; + } + hideFilterValueAction(this); + }); + $('.hide-action').each(function() { + hideFilterValueAction(this); + }); + paginationButton(); initLayered(); }); + +function hideFilterValueAction(it) +{ + if (typeof(layered_hidden_list[$(it).parent().find('ul').attr('id')]) == 'undefined' || layered_hidden_list[$(it).parent().find('ul').attr('id')] == false) + { + $(it).parent().find('.hiddable').hide(); + $(it).parent().find('.hide-action.less').hide(); + $(it).parent().find('.hide-action.more').show(); + } + else + { + $(it).parent().find('.hiddable').show(); + $(it).parent().find('.hide-action.less').show(); + $(it).parent().find('.hide-action.more').hide(); + } +} function addSlider(type, data, unit) { @@ -198,6 +240,10 @@ function reloadContent(params_plus) data += '&'+$(this).attr('id')+'='+sliderStart+'_'+sliderStop; }); + $('#layered_form .select option:checked').each( function () { + data += '&'+$(this).attr('id') + '=' + $(this).val(); + }); + if ($('#selectPrductSort').length) { var splitData = $('#selectPrductSort').val().split(':'); @@ -281,6 +327,10 @@ function reloadContent(params_plus) if(slideUp) $.scrollTo('#product_list', 400); updateProductUrl(); + + $('.hide-action').each(function() { + hideFilterValueAction(this); + }); } }); ajaxQueries.push(ajaxQuery); diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index e8f9796c1..f0eacb40f 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -1158,31 +1158,44 @@ class BlockLayered extends Module foreach ($_POST['categoryBox'] as $idc) $filterValues['categories'][] = (int)$idc; - $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position) VALUES '; + $sqlToInsert = 'INSERT INTO '._DB_PREFIX_.'layered_category (id_category, id_value, type, position, filter_show_limit, filter_type) VALUES '; foreach ($_POST['categoryBox'] as $id_category_layered) { $n = 0; foreach ($_POST as $key => $value) if (substr($key, 0, 17) == 'layered_selection' && $value == 'on') { - $filterValues[$key] = $value; + $type = 0; + $limit = 0; + if (Tools::getValue($key.'_filter_type')) + $type = Tools::getValue($key.'_filter_type'); + if (Tools::getValue($key.'_filter_show_limit')) + $limit = Tools::getValue($key.'_filter_show_limit'); + + $filterValues[$key] = array( + 'filter_type' => (int)$type, + 'filter_show_limit' => (int)$limit + ); $n++; + if ($key == 'layered_selection_stock') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'quantity\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'quantity\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if ($key == 'layered_selection_subcategories') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'category\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'category\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if ($key == 'layered_selection_condition') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'condition\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'condition\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if ($key == 'layered_selection_weight_slider') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'weight\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'weight\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if ($key == 'layered_selection_price_slider') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'price\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'price\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if ($key == 'layered_selection_manufacturer') - $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'manufacturer\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.',NULL,\'manufacturer\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if (substr($key, 0, 21) == 'layered_selection_ag_') - $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_ag_', '', $key).',\'id_attribute_group\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_ag_', '', $key).', + \'id_attribute_group\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; else if (substr($key, 0, 23) == 'layered_selection_feat_') - $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_feat_', '', $key).',\'id_feature\','.(int)$n.'),'; + $sqlToInsert .= '('.(int)$id_category_layered.','.(int)str_replace('layered_selection_feat_', '', $key).', + \'id_feature\','.(int)$n.', '.(int)$limit.', '.(int)$type.'),'; } } @@ -1198,8 +1211,8 @@ class BlockLayered extends Module Db::getInstance()->AutoExecute(_DB_PREFIX_.'layered_filter', $valuesToInsert, 'INSERT'); - echo '
- '.$this->l('Your filter').' "'.Tools::safeOutput(Tools::getValue('layered_tpl_name')).'" '. + echo '
'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : ''). + $this->l('Your filter').' "'.Tools::safeOutput(Tools::getValue('layered_tpl_name')).'" '. ((isset($_POST['id_layered_filter']) && $_POST['id_layered_filter']) ? $this->l('was updated successfully.') : $this->l('was added successfully.')).'
'; } } @@ -1211,8 +1224,8 @@ class BlockLayered extends Module Configuration::updateValue('PS_LAYERED_FULL_TREE', Tools::getValue('ps_layered_full_tree')); $html .= ' -
- '.$this->l('Settings saved successfully').' +
'. + (version_compare(_PS_VERSION_,'1.5','>') ? '' : '').$this->l('Settings saved successfully').'
'; } else if (isset($_GET['deleteFilterTemplate'])) @@ -1227,8 +1240,8 @@ class BlockLayered extends Module Db::getInstance()->Execute('DELETE FROM '._DB_PREFIX_.'layered_filter WHERE id_layered_filter = '.(int)$_GET['id_layered_filter'].' LIMIT 1'); $html .= ' -
- '.$this->l('Filters template deleted, categories updated (reverted to default Filters template).').' +
'.(version_compare(_PS_VERSION_,'1.5','>') ? '' : '').' + '.$this->l('Filters template deleted, categories updated (reverted to default Filters template).').'
'; } else @@ -1242,10 +1255,10 @@ class BlockLayered extends Module $html .= '

'.$this->l('Layered navigation').'

@@ -1471,11 +1484,13 @@ class BlockLayered extends Module ul#selected_filters li, #layered_container_right ul li { width: 326px; font-size: 11px; padding: 8px 9px 7px 20px; height: 14px; margin-bottom: 5px; } ul#selected_filters li span.ui-icon { position: absolute; margin-top: -2px; margin-left: -18px; } #layered_container_right ul li span { display: none; } - #layered_container_right ul li { padding-left: 8px; } - #layered_container_left ul li { cursor: move; } + #layered_container_right ul li { padding-left: 8px; position: relative; } + #layered_container_left ul li { cursor: move; position: relative; } #layered-cat-counter { display: none; } #layered-step-2, #layered-step-3 { display: none; } #table-filter-templates tr th, #table-filter-templates tr td { text-align: center; } + .filter_type { width: 70px; position: absolute; right: 53px; top: 5px;} + .filter_show_limit { position: absolute; width: 40px; right: 5px; top: 5px; }
'; @@ -1499,10 +1514,33 @@ class BlockLayered extends Module
  • '.$this->l('Press "Save this selection" or close the window to save').'
  • '; - $trads = array(); $selectedCat = array(); - foreach (Helper::$translationsKeysForAdminCategorieTree as $key) - $trads[$key] = $this->l($key); + // Translations are not automatic for the moment ;) + $trads = array( + 'Home' => $this->l('Home'), + 'selected' => $this->l('selected'), + 'Collapse All' => $this->l('Collapse All'), + 'Expand All' => $this->l('Expand All'), + 'Check All' => $this->l('Check All'), + 'Uncheck All' => $this->l('Uncheck All'), + 'search' => $this->l('Search a category') + ); + + if (version_compare(_PS_VERSION_,'1.5','>')) + { + $this->context->controller->addJQueryPlugin('fancybox'); + $this->context->controller->addJQueryUI('ui.sortable'); + $this->context->controller->addJQueryUI('ui.draggable'); + $this->context->controller->addJQueryUI('effects.transfer'); + } + else + { + $html .= ' + + '; + + } + $html .= Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox'); $html .= ' @@ -1525,9 +1563,6 @@ class BlockLayered extends Module

    - - - {/if} + {if count($filter.values) > $filter.filter_show_limit && $filter.filter_type != 2} + {l s='Show more' mod='blocklayered'} + {l s='Show less' mod='blocklayered'} + {/if}
    {/if} {/foreach}
    {foreach from=$filters item=filter} - {if $filter.type_lite == 'id_attribute_group' && isset($filter.is_color_group) && $filter.is_color_group} + {if $filter.type_lite == 'id_attribute_group' && isset($filter.is_color_group) && $filter.is_color_group && $filter.filter_type != 2} {foreach from=$filter.values key=id_value item=value} {if isset($value.checked)} diff --git a/modules/blocklayered/config.xml b/modules/blocklayered/config.xml index 118864c31..c5ca9d292 100644 --- a/modules/blocklayered/config.xml +++ b/modules/blocklayered/config.xml @@ -2,7 +2,7 @@ blocklayered - + diff --git a/modules/blocklayered/fr.php b/modules/blocklayered/fr.php index 728332a99..3d6a763a3 100644 --- a/modules/blocklayered/fr.php +++ b/modules/blocklayered/fr.php @@ -56,7 +56,7 @@ $_MODULE['<{blocklayered}prestashop>blocklayered_62f5d708d6ad1fa1ddd9429a65cccbe $_MODULE['<{blocklayered}prestashop>blocklayered_fe0619d5f4999e09c622e32da7e7566a'] = 'spécifiques'; $_MODULE['<{blocklayered}prestashop>blocklayered_b0b5ccb4a195a07fd3eed14affb8695f'] = 'Catégories'; $_MODULE['<{blocklayered}prestashop>blocklayered_ef7de3f485174ff47f061ad27d83d0ee'] = 'sélectionnée(s)'; -$_MODULE['<{blocklayered}prestashop>blocklayered_f72c75bdf80dc88b2529162f4947edc8'] = 'S\'il vous plaît sélectionner au moins une catégorie spécifique ou choisissez « Toutes catégories ».'; +$_MODULE['<{blocklayered}prestashop>blocklayered_f72c75bdf80dc88b2529162f4947edc8'] = 'S\'il vous plaît sélectionnez au moins une catégorie spécifique ou choisissez « Toutes catégories ».'; $_MODULE['<{blocklayered}prestashop>blocklayered_64646db703ca003a37bd1e73977a3a4d'] = 'Catégories utilisant ce modèle'; $_MODULE['<{blocklayered}prestashop>blocklayered_d758a9754eb9f36db05c22ad0c77e38e'] = 'Sélectionnez une ou plusieurs catégories utilisant ce modèle'; $_MODULE['<{blocklayered}prestashop>blocklayered_5965d2ce192837f00d743d8a674382c1'] = 'Cliquez sur \"Sauvegarder cette sélection\" ou fermez la fenêtre pour sauvegarder'; @@ -79,6 +79,7 @@ $_MODULE['<{blocklayered}prestashop>blocklayered_9868c3ac0748acf3b981a96cfe163ee $_MODULE['<{blocklayered}prestashop>blocklayered_93cba07454f06a4a960172bbd6e2a435'] = 'Oui'; $_MODULE['<{blocklayered}prestashop>blocklayered_bafd7322c6e97d25b6299b5d6fe8920b'] = 'Non'; $_MODULE['<{blocklayered}prestashop>blocklayered_8531c73de81b9ed94322dda7cf947daa'] = 'Afficher le nombre de produits qui correspondent'; +$_MODULE['<{blocklayered}prestashop>blocklayered_ee61c015043c79c1370fc14980dd27b9'] = 'Montrez les produits des sous-catégories'; $_MODULE['<{blocklayered}prestashop>blocklayered_cf565402d32b79d33f626252949a6941'] = 'Configuration enregistré'; $_MODULE['<{blocklayered}prestashop>blocklayered_3601146c4e948c32b6424d2c0a7f0118'] = 'Prix'; $_MODULE['<{blocklayered}prestashop>blocklayered_8c489d0946f66d17d73f26366a4bf620'] = 'Poids'; @@ -92,6 +93,9 @@ $_MODULE['<{blocklayered}prestashop>blocklayered_faeaec9eda6bc4c8cb6e1a9156a858b $_MODULE['<{blocklayered}prestashop>blocklayered_c0bd7654d5b278e65f21cf4e9153fdb4'] = 'Fabricant'; $_MODULE['<{blocklayered}prestashop>blocklayered_308edffd52afae39cc6277e246ec5df8'] = 'Filtres disponibles'; $_MODULE['<{blocklayered}prestashop>blocklayered_cfbc982f8fb7a0cc3abb3c85c795ab41'] = 'Filtre sous-catégories'; +$_MODULE['<{blocklayered}prestashop>blocklayered_af605ea55ee39e54c444f217e346048f'] = 'Pas de limite'; +$_MODULE['<{blocklayered}prestashop>blocklayered_f7e8e9adfb9fbb546ae8b9b6ec2849b4'] = 'Autoriser la selection de plusieur valeur de filtre'; +$_MODULE['<{blocklayered}prestashop>blocklayered_3c151970b422e3e3cbf927166e4eade4'] = 'Une seul value par filtre'; $_MODULE['<{blocklayered}prestashop>blocklayered_cd50ff1c5332f9920acf8173c4aab425'] = 'Filtre stock du produit'; $_MODULE['<{blocklayered}prestashop>blocklayered_048c1728a0a6cf36f56c9dcdd23d8a14'] = 'Filtre état du produit'; $_MODULE['<{blocklayered}prestashop>blocklayered_02ecc2cbb645a2b859deba6907334cc8'] = 'Filtre fabriquant du produit'; @@ -108,4 +112,6 @@ $_MODULE['<{blocklayered}prestashop>blocklayered_c32516babc5b6c47eb8ce1bfc223253 $_MODULE['<{blocklayered}prestashop>blocklayered_1262d1b9fbffb3a8e85ac9e4b449e989'] = 'Filtres actifs :'; $_MODULE['<{blocklayered}prestashop>blocklayered_ea4788705e6873b424c65e91c2846b19'] = 'Annuler'; $_MODULE['<{blocklayered}prestashop>blocklayered_853ae90f0351324bd73ea615e6487517'] = ' :'; +$_MODULE['<{blocklayered}prestashop>blocklayered_146ffe2fd9fa5bec3b63b52543793ec7'] = 'Voir plus'; +$_MODULE['<{blocklayered}prestashop>blocklayered_c74ea6dbff701bfa23819583c52ebd97'] = 'Voir moins'; $_MODULE['<{blocklayered}prestashop>blocklayered_75954a3c6f2ea54cb9dff249b6b5e8e6'] = 'Tranche';