diff --git a/modules/blocklayered/blocklayered-15.css b/modules/blocklayered/blocklayered-15.css index 0f4ac820e..615e2b3fb 100644 --- a/modules/blocklayered/blocklayered-15.css +++ b/modules/blocklayered/blocklayered-15.css @@ -90,11 +90,16 @@ color: #666; } #layered_block_left .color-option { - border: 1px solid #666666; - height: 16px; - margin-left: 0; - padding: 0; - width: 16px; + border: 1px solid #666666; + height: 16px; + margin-left: 0; + padding: 0; + width: 16px; +} +#layered_block_left .color-option.disable { + opacity: 0.5; + filter:alpha(opacity=50); + -moz-opacity:0.5; } #layered_block_left .nomargin a { display: inline; diff --git a/modules/blocklayered/blocklayered.css b/modules/blocklayered/blocklayered.css index 6c91d2961..25b271a1f 100644 --- a/modules/blocklayered/blocklayered.css +++ b/modules/blocklayered/blocklayered.css @@ -107,6 +107,11 @@ padding:0; border: 1px solid #666; } +#layered_block_left .color-option.disable { + opacity: 0.5; + filter:alpha(opacity=50); + -moz-opacity:0.5; +} #layered_form .color-option.on { border: 1px solid red; } diff --git a/modules/blocklayered/blocklayered.js b/modules/blocklayered/blocklayered.js index e2f384f06..53572ad35 100644 --- a/modules/blocklayered/blocklayered.js +++ b/modules/blocklayered/blocklayered.js @@ -37,10 +37,10 @@ $(document).ready(function() // Click on color $('#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')+'][type=hidden]').length) $('').attr('type', 'hidden').attr('name', $(this).attr('name')).val($(this).attr('rel')).appendTo('#layered_form'); else - $('\'input[name='+$(this).attr('name')+']:hidden\'').remove(); + $('input[name='+$(this).attr('name')+'][type=hidden]').remove(); reloadContent(); }); @@ -235,7 +235,7 @@ function cancelFilter() { $('#'+$(this).attr('rel')).attr('checked', false); $('.'+$(this).attr('rel')).attr('checked', false); - $('#layered_form input[name='+$(this).attr('rel')+']').remove(); + $('#layered_form input[type=hidden][name='+$(this).attr('rel')+']').remove(); } } reloadContent(); diff --git a/modules/blocklayered/blocklayered.php b/modules/blocklayered/blocklayered.php index 1f353ae73..109b5970a 100644 --- a/modules/blocklayered/blocklayered.php +++ b/modules/blocklayered/blocklayered.php @@ -2382,7 +2382,7 @@ class BlockLayered extends Module $filterBlocks = array(); foreach ($filters as $filter) { - $sqlQuery = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => ''); + $sqlQuery = array('select' => '', 'from' => '', 'join' => '', 'where' => '', 'group' => '', 'second_query' => ''); switch ($filter['type']) { // conditions + quantities + weight + price @@ -2422,6 +2422,24 @@ class BlockLayered extends Module AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1 '; $sqlQuery['group'] = ' GROUP BY p.id_manufacturer '; + + if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) + { + $sqlQuery['second_query'] = ' + SELECT m.name, 0 nbr, m.id_manufacturer + + FROM `'._DB_PREFIX_.'category_product` cp + INNER JOIN `'._DB_PREFIX_.'category` c ON (c.id_category = cp.id_category) + INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = cp.id_product AND p.active = 1) + INNER JOIN '._DB_PREFIX_.'manufacturer m ON (m.id_manufacturer = p.id_manufacturer) + + WHERE '.(Configuration::get('PS_LAYERED_FULL_TREE') ? 'c.nleft >= '.(int)$parent->nleft.' + AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' + AND c.active = 1 + + GROUP BY p.id_manufacturer'; + } + break; case 'id_attribute_group':// attribute group @@ -2460,6 +2478,37 @@ class BlockLayered extends Module GROUP BY lpa.id_attribute ORDER BY id_attribute_group, id_attribute '; + if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) + { + $sqlQuery['second_query'] = ' + SELECT 0 nbr, lpa.id_attribute_group, + a.color, al.name attribute_name, agl.public_name attribute_group_name , lpa.id_attribute, ag.is_color_group, + liagl.url_name name_url_name, liagl.meta_title name_meta_title, lial.url_name value_url_name, lial.meta_title value_meta_title + + FROM '._DB_PREFIX_.'layered_product_attribute lpa + INNER JOIN '._DB_PREFIX_.'attribute a + ON a.id_attribute = lpa.id_attribute + INNER JOIN '._DB_PREFIX_.'attribute_lang al + ON al.id_attribute = a.id_attribute + AND al.id_lang = '.(int)$cookie->id_lang.' + INNER JOIN '._DB_PREFIX_.'product as p + ON p.id_product = lpa.id_product + AND p.active = 1 + INNER JOIN '._DB_PREFIX_.'attribute_group ag + ON ag.id_attribute_group = lpa.id_attribute_group + INNER JOIN '._DB_PREFIX_.'attribute_group_lang agl + ON agl.id_attribute_group = lpa.id_attribute_group + AND agl.id_lang = '.(int)$cookie->id_lang.' + LEFT JOIN '._DB_PREFIX_.'layered_indexable_attribute_group_lang_value liagl + ON (liagl.id_attribute_group = lpa.id_attribute_group AND liagl.id_lang = '.(int)$cookie->id_lang.') + LEFT JOIN '._DB_PREFIX_.'layered_indexable_attribute_lang_value lial + ON (lial.id_attribute = lpa.id_attribute AND lial.id_lang = '.(int)$cookie->id_lang.') + + WHERE a.id_attribute_group = '.(int)$filter['id_value'].' + + GROUP BY lpa.id_attribute + ORDER BY id_attribute_group, id_attribute'; + } break; case 'id_feature': @@ -2485,6 +2534,27 @@ class BlockLayered extends Module AND c.nright <= '.(int)$parent->nright : 'c.id_category = '.(int)$id_parent).' AND c.active = 1)) '; $sqlQuery['group'] = 'GROUP BY fv.id_feature_value '; + + if (!Configuration::get('PS_LAYERED_HIDE_0_VALUES')) + { + $sqlQuery['second_query'] = ' + SELECT fl.name feature_name, fp.id_feature, fv.id_feature_value, fvl.value, + 0 nbr, + lifl.url_name name_url_name, lifl.meta_title name_meta_title, lifvl.url_name value_url_name, lifvl.meta_title value_meta_title + + FROM '._DB_PREFIX_.'feature_product fp + INNER JOIN '._DB_PREFIX_.'product p ON (p.id_product = fp.id_product AND p.active = 1) + LEFT JOIN '._DB_PREFIX_.'feature_lang fl ON (fl.id_feature = fp.id_feature AND fl.id_lang = '.(int)$cookie->id_lang.') + INNER JOIN '._DB_PREFIX_.'feature_value fv ON (fv.id_feature_value = fp.id_feature_value AND (fv.custom IS NULL OR fv.custom = 0)) + LEFT JOIN '._DB_PREFIX_.'feature_value_lang fvl ON (fvl.id_feature_value = fp.id_feature_value AND fvl.id_lang = '.(int)$cookie->id_lang.') + LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_lang_value lifl + ON (lifl.id_feature = fp.id_feature AND lifl.id_lang = '.(int)$cookie->id_lang.') + LEFT JOIN '._DB_PREFIX_.'layered_indexable_feature_value_lang_value lifvl + ON (lifvl.id_feature_value = fp.id_feature_value AND lifvl.id_lang = '.(int)$cookie->id_lang.') + WHERE p.`active` = 1 AND fp.id_feature = '.(int)$filter['id_value'].' + GROUP BY fv.id_feature_value'; + } + break; case 'category': @@ -2547,6 +2617,13 @@ class BlockLayered extends Module else $products = self::$methodName(@$selectedFilters[$filterTmp['type']], $products); } + + if (!empty($sqlQuery['second_query'])) + { + $res = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sqlQuery['second_query']); + if ($res) + $products = array_merge($products, $res); + } switch ($filter['type']) { @@ -2714,7 +2791,8 @@ class BlockLayered extends Module $manufaturersArray = array(); foreach ($products as $manufacturer) { - $manufaturersArray[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']); + if (!isset($manufaturersArray[$manufacturer['id_manufacturer']])) + $manufaturersArray[$manufacturer['id_manufacturer']] = array('name' => $manufacturer['name'], 'nbr' => $manufacturer['nbr']); if (isset($selectedFilters['manufacturer']) && in_array((int)$manufacturer['id_manufacturer'], $selectedFilters['manufacturer'])) $manufaturersArray[$manufacturer['id_manufacturer']]['checked'] = true; } @@ -2750,14 +2828,15 @@ class BlockLayered extends Module 'filter_type' => $filter['filter_type'] ); - $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array( - 'color' => $attributes['color'], - 'name' => $attributes['attribute_name'], - 'nbr' => (int)$attributes['nbr'], - 'url_name' => $attributes['value_url_name'], - 'meta_title' => $attributes['value_meta_title'] - ); - + if (!isset($attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']])) + $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']] = array( + 'color' => $attributes['color'], + 'name' => $attributes['attribute_name'], + 'nbr' => (int)$attributes['nbr'], + 'url_name' => $attributes['value_url_name'], + 'meta_title' => $attributes['value_meta_title'] + ); + if (isset($selectedFilters['id_attribute_group'][$attributes['id_attribute']])) $attributesArray[$attributes['id_attribute_group']]['values'][$attributes['id_attribute']]['checked'] = true; } @@ -2783,12 +2862,13 @@ class BlockLayered extends Module 'filter_type' => $filter['filter_type'] ); - $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']] = array( - 'nbr' => (int)$feature['nbr'], - 'name' => $feature['value'], - 'url_name' => $feature['value_url_name'], - 'meta_title' => $feature['value_meta_title'] - ); + if (!isset($featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']])) + $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']] = array( + 'nbr' => (int)$feature['nbr'], + 'name' => $feature['value'], + 'url_name' => $feature['value_url_name'], + 'meta_title' => $feature['value_meta_title'] + ); if (isset($selectedFilters['id_feature'][$feature['id_feature_value']])) $featureArray[$feature['id_feature']]['values'][$feature['id_feature_value']]['checked'] = true; @@ -2801,6 +2881,7 @@ class BlockLayered extends Module $tmpArray = array(); if (isset($products) && $products) { + $categoriesWithProductsCount = 0; foreach ($products as $category) { $tmpArray[$category['id_category']] = array( @@ -2808,17 +2889,21 @@ class BlockLayered extends Module 'nbr' => (int)$category['count_products'] ); + if ((int)$category['count_products']) + $categoriesWithProductsCount++; + if (isset($selectedFilters['category']) && in_array($category['id_category'], $selectedFilters['category'])) $tmpArray[$category['id_category']]['checked'] = true; } - $filterBlocks[] = array ( - 'type_lite' => 'category', - 'type' => 'category', - 'id_key' => 0, 'name' => $this->l('Categories'), - 'values' => $tmpArray, - 'filter_show_limit' => $filter['filter_show_limit'], - 'filter_type' => $filter['filter_type'] - ); + if ($categoriesWithProductsCount || !Configuration::get('PS_LAYERED_HIDE_0_VALUES')) + $filterBlocks[] = array ( + 'type_lite' => 'category', + 'type' => 'category', + 'id_key' => 0, 'name' => $this->l('Categories'), + 'values' => $tmpArray, + 'filter_show_limit' => $filter['filter_show_limit'], + 'filter_type' => $filter['filter_type'] + ); } break; diff --git a/modules/blocklayered/blocklayered.tpl b/modules/blocklayered/blocklayered.tpl index ff6408f7f..f5cb4234b 100644 --- a/modules/blocklayered/blocklayered.tpl +++ b/modules/blocklayered/blocklayered.tpl @@ -87,9 +87,10 @@ param_product_url = ''; {if !isset($filter.slider)} {if $filter.filter_type == 0} {foreach from=$filter.values key=id_value item=value name=fe} + {if $value.nbr || !Configuration::get('PS_LAYERED_HIDE_0_VALUES')}
  • {if isset($filter.is_color_group) && $filter.is_color_group} - + {if isset($value.checked) && $value.checked}{/if} {else} @@ -102,13 +103,15 @@ param_product_url = ''; {/if}
  • + {/if} {/foreach} {else} {if $filter.filter_type == 1} {foreach from=$filter.values key=id_value item=value name=fe} + {if $value.nbr || !Configuration::get('PS_LAYERED_HIDE_0_VALUES')}
  • {if isset($filter.is_color_group) && $filter.is_color_group} - + {if isset($value.checked) && $value.checked}{/if} {else} @@ -121,14 +124,17 @@ param_product_url = ''; {/if}
  • + {/if} {/foreach} {else} {/if}