Говорю сразу, фильтр писал очень быстро, т.к. срочно нужно было закрыть проект.
Во вложение изображение моего фильтра.
/components/com_virtuemart/views/category/tmpl/default.php
<?php // Show child categories
if (!empty($this->products)) {
?>
Сюда написал сам фильтр. Вот пример
<form action="<?php echo JRoute::_('index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id); ?>" method="get">
<style>.mat .sb{width:200px !important}</style>
<!--BEGIN Search Box -->
<?php
$dbo =& JFactory::getDBO();
// выбераем цвета продуктов
$sql2 = '
SELECT
p.virtuemart_product_id,
p.product_color,
c.virtuemart_product_id,
c.virtuemart_category_id
FROM
jos_virtuemart_product_categories AS c,
jos_virtuemart_products_ru_ru AS p
WHERE
p.virtuemart_product_id = c.virtuemart_product_id
AND p.product_color IS NOT NULL
AND c.virtuemart_category_id ="'.$this->category->virtuemart_category_id.'"
GROUP BY
p.product_color';
$result2 = mysql_query($sql2);
// выбераем материал продуктов
$sql3 = '
SELECT
p.virtuemart_product_id,
c.virtuemart_product_id,
c.virtuemart_category_id,
cu.virtuemart_product_id,
cu.virtuemart_custom_id,
cu.custom_value
FROM
jos_virtuemart_product_categories AS c,
jos_virtuemart_products_ru_ru AS p,
jos_virtuemart_product_customfields AS cu
WHERE
p.virtuemart_product_id = c.virtuemart_product_id
AND cu.virtuemart_product_id=p.virtuemart_product_id
AND cu.virtuemart_custom_id = 4
AND c.virtuemart_category_id ="'.$this->category->virtuemart_category_id.'"
AND cu.custom_value IS NOT NULL
GROUP BY
cu.custom_value';
$result3 = mysql_query($sql3);
// выбераем размер продуктов типов L, XL
$sql4 = '
SELECT
p.virtuemart_product_id,
p.product_size,
c.virtuemart_product_id,
c.virtuemart_category_id
FROM
jos_virtuemart_product_categories AS c,
jos_virtuemart_products_ru_ru AS p
WHERE
p.virtuemart_product_id = c.virtuemart_product_id
AND p.product_size IS NOT NULL
AND c.virtuemart_category_id ="'.$this->category->virtuemart_category_id.'"
GROUP BY
p.product_size';
$result4 = mysql_query($sql4);
// выбераем размер продуктов типов 100*100
$sql5 = '
SELECT
pr.virtuemart_product_id,
pr.product_width,
pr.product_width2,
pr.product_height,
pr.product_height2,
c.virtuemart_product_id,
c.virtuemart_category_id
FROM
jos_virtuemart_product_categories AS c,
jos_virtuemart_products AS pr
WHERE
pr.virtuemart_product_id = c.virtuemart_product_id
AND pr.product_width IS NOT NULL
AND pr.product_width2 IS NOT NULL
AND pr.product_height IS NOT NULL
AND pr.product_height2 IS NOT NULL
AND c.virtuemart_category_id ="'.$this->category->virtuemart_category_id.'"
GROUP BY
pr.product_width,
pr.product_width2,
pr.product_height,
pr.product_height2';
$result5 = mysql_query($sql5);
// выбераем состав продуктов
$sql6 = '
SELECT
p.virtuemart_product_id,
c.virtuemart_product_id,
c.virtuemart_category_id,
cu.virtuemart_product_id,
cu.virtuemart_custom_id,
cu.custom_value
FROM
jos_virtuemart_product_categories AS c,
jos_virtuemart_products_ru_ru AS p,
jos_virtuemart_product_customfields AS cu
WHERE
p.virtuemart_product_id = c.virtuemart_product_id
AND cu.virtuemart_product_id=p.virtuemart_product_id
AND cu.virtuemart_custom_id = 9
AND c.virtuemart_category_id ="'.$this->category->virtuemart_category_id.'"
AND cu.custom_value IS NOT NULL
GROUP BY
cu.custom_value';
$result6 = mysql_query($sql6);
?>
<div class="virtuemart_search">
<div id = "menuSort" style = "width: 1000px; margin:0px; position: relative; width:800px; float:right;">
<div style = "float: left;">
<select id="color" style = "width: 60px; background-color: white; border: 0px; color: #666; font-family: 'Century Schoolbook'; font-size: 14px;" name="color" >
<option value="">Цвет</option>
<?php
if (mysql_num_rows($result2) > 0)
{
$myrow2 = mysql_fetch_array($result2);
do
{
if($myrow2["product_color"] == $_GET['color']){
$color = 'selected="selected"';
}else{
$color = '';
}
printf ("<option value='%s' %s>%s</option>",$myrow2["product_color"],$color,$myrow2["product_color"]);
}
while ($myrow2 = mysql_fetch_array($result2));
}
?>
</select>
</div>
<div style = "float: left; margin-left: 25px;">
<?php
if (mysql_num_rows($result4) == 1){
?>
<select id="size" style = "width: 60px; background-color: white; border: 0px; color: #666; font-family: 'Century Schoolbook'; font-size: 14px;" name="size2">
<option value="">Размер</option>
<?php
if (mysql_num_rows($result5) > 0){
$myrow5 = mysql_fetch_array($result5);
do
{
if($myrow5["product_width"].'*'.$myrow5["product_height"] == $_GET['size2']){
$size2 = 'selected="selected"';
}else{
$size2 = '';
}
printf ("<option value='%s*%s' %s>%s*%s</option>",$myrow5["product_width"],$myrow5["product_height"],$size2,$myrow5["product_width"],$myrow5["product_height"]);
}
while ($myrow5 = mysql_fetch_array($result5));
}
?>
</select>
<?php }else{ ?>
<select id="size" style = "width: 60px; background-color: white; border: 0px; color: #666; font-family: 'Century Schoolbook'; font-size: 14px;" name="size">
<option value="">Размер</option>
<?php
if (mysql_num_rows($result4) > 0)
{
$myrow4 = mysql_fetch_array($result4);
do
{
if($myrow4["product_size"] == $_GET['size']){
$size = 'selected="selected"';
}else{
$size = '';
}
printf ("<option value='%s' %s>%s</option>",$myrow4["product_size"],$size,$myrow4["product_size"]);
}
while ($myrow4 = mysql_fetch_array($result4));
}
?>
</select>
<?php } ?>
</div>
<div style = "float: left; margin-left: 25px;" class="mat">
<select id="material" name="material" style = "width: 225px; background-color: white; border: 0px; color: #666; font-family: 'Century Schoolbook'; font-size: 14px;" >
<option value="">Материал</option>
<?php
if (mysql_num_rows($result3) > 0)
{
$myrow3 = mysql_fetch_array($result3);
do
{
if($myrow3["custom_value"] == $_GET['material']){
$custom = 'selected="selected"';
}else{
$custom = '';
}
printf ("<option value='%s' %s>%s</option>",$myrow3["custom_value"],$custom,$myrow3["custom_value"]);
}
while ($myrow3 = mysql_fetch_array($result3));
}
?>
</select>
<br /><br />
<select id="material" name="sostav" style = "width: 225px; background-color: white; border: 0px; color: #666; font-family: 'Century Schoolbook'; font-size: 14px;" >
<option value="">Состав</option>
<?php
if (mysql_num_rows($result6) > 0)
{
$myrow6 = mysql_fetch_array($result6);
do
{
if($myrow6["custom_value"] == $_GET['sostav']){
$custom = 'selected="selected"';
}else{
$custom = '';
}
printf ("<option value='%s' %s>%s</option>",$myrow6["custom_value"],$custom,$myrow6["custom_value"]);
}
while ($myrow6 = mysql_fetch_array($result6));
}
?>
</select>
</div>
<div style ="float: left;margin-left: 40px;">Цена</div>
<label for="amount"></label>
<input type="text" id="amount" disabled="disabled" style="border:0;background-color: white; width:205px; font-weight:bold; position: absolute; top: -20px; right: 80px" />
<div id="slid" style = "float: left; width: 200px !important; margin-top: 7px; margin-left: 25px;"></div>
<div style = "float: left; margin-left: 5px;">грн.</div>
<input type="hidden" name="price_min" id="price_min" value="">
<input type="hidden" name="price_max" id="price_max" value="">
<?php echo $this->searchcustomvalues ?>
<input name="keyword" class="inputbox" type="text" style="display:none;" size="20" value="<?php echo $this->keyword ?>" />
<div class="limit_box" style="float: right;margin-right: 12px;margin-top: 15px;">
<div style="color:#525452;font-size:14px;float:left;">Показать кол-ство товаров на страницу: </div><div style="width:50px;overflow-x:hidden;float:left;background:url(/images/select_arrow.gif) no-repeat right center;"><?php echo $this->vmPagination->getLimitBox (); ?></div>
</div>
<div class="clear">
<input type="submit" style="font-family: Arial;border-left: medium none;float:left;border-top: medium none;margin-top: 15px;width: 178px;" value="<?php echo JText::_('COM_VIRTUEMART_SEARCH')?>" class="continue_link" onclick="this.form.keyword.focus();"/>
<a class="continue_link2" href="<?php echo 'index.php?option=com_virtuemart&view=category&limitstart=0&virtuemart_category_id='.$this->category->virtuemart_category_id?>">Сбросить фильтр</a>
</div>
<input type="hidden" name="search" value="true" />
<input type="hidden" name="limit" value="300" />
<input type="hidden" name="view" value="category" /></div></div>
</form>
Поля:
- Цвет
- Размер
я создавал дополнительно
Поля:
- Материал
- состав
Настраиваемые поля
Слайдер цены реализован с помощу jquery ui slider
По работе фильтра:
/administrator/components/com_virtuemart/models/product.php
в функцию "function __construct() {"
додал переменные
var $price_min = '';
var $price_max = '';
var $size = '';
var $size2 = '';
var $material = '';
var $color = '';
в функцию "function initialiseRequests(){"
$this->price_min = '';
$this->price_max = '';
$this->size = '';
$this->size2 = '';
$this->material = '';
$this->color = '';
далее принимал параметры фильтра
в функцию " function sortSearchListQuery($onlyPublished=true,$virtuemart_category_id = false, $group=false,$nbrReturnProducts=false){"
перед
if(count($where)>0){
$whereString = ' WHERE ('.implode(' AND ', $where ).') ';
} else {
$whereString = '';
}
Добавил вот
if ($_GET['price_min'] == '') {
}else{
$joinedTables .= ' LEFT JOIN `#__virtuemart_product_prices` as pp ON p.`virtuemart_product_id` = pp.`virtuemart_product_id` ';
$where[] = 'pp.`product_price`>='.$_GET['price_min'].' and pp.`product_price`<='.$_GET['price_max'].'';
}
if ($_GET['size'] == '') {
}else{
$where[] = 'l.`product_size`="'.$_GET['size'].'"';
}
if ($_GET['size2'] == '') {
}else{
$sizes = explode("*", $_GET['size2']);
//print_r($sizes);
$where[] = 'p.`product_width`="'.$sizes['0'].'" and p.`product_height`="'.$sizes['1'].'"';
}
if ($_GET['color'] == '') {
}else{
$where[] = 'l.`product_color`="'.$_GET['color'].'"';
}
if ($_GET['material'] == '') {
}else{
$joinedTables .= ' LEFT JOIN `#__virtuemart_product_customfields` as pf ON p.`virtuemart_product_id` = pf.`virtuemart_product_id` ';
$where[] = 'pf.`custom_value` like "%'.$_GET['material'].'%"';
}
if ($_GET['sostav'] == '') {
}else{
$joinedTables .= ' LEFT JOIN `#__virtuemart_product_customfields` as pf ON p.`virtuemart_product_id` = pf.`virtuemart_product_id` ';
$where[] = 'pf.`custom_value` like "%'.$_GET['sostav'].'%"';
}
А и еще в шаблоне темы сайта, дописал:
jQuery( "#slid" ).slider({
range: "true",
<?php
$min = (!empty($_GET['price_min']))? $_GET['price_min'] : 0 ;
$max = (!empty($_GET['price_max']))? $_GET['price_max'] : 9999 ;
?>
<?php echo 'values: [ '.$min.', '.$max.' ],';?>
min: 0,
max: 9999,
slide: function( event, ui ) {
jQuery( "#amount" ).val(ui.values[ 0 ] + " грн. - " + ui.values[ 1 ] + " грн." );
},
change: function(event, ui) {
var min = ui.values[0];
var max = ui.values[1];
$('#price_min').val(min);
$('#price_max').val(max);
}
});
jQuery( "#amount" ).val(jQuery( "#slid" ).slider( "values", 0 ) + " грн. - " + jQuery( "#slid" ).slider( "values", 1 ) + " грн." );
[вложение удалено Администратором]