Подбор товаров по параметрам (дополнительным свойствам) на главной
marinok
25 декабря 2012 г.
Есть интернет-магазин, где товары лежат не в корне, а в категориях (группах). У товаров есть дополнительные свойства.
Задача: на главной странице сайта реализовать подбор товаров по дополнительным свойствам.
Решение:
1. Создаем Xsl шаблон "Фильтр"
2. Подключаем шаблон в макете в нужном месте, не забываем указывать свой id магазина
3. В ТДС интернет магазина добавляем
4. В Xsl шаблоне вывода каталога товаров (по умолчанию это "МагазинКаталогТоваров" нужно добавить условие, что если выбран фильтр, группы товаров не отображаются. Для этого вносим поправку в код( поправка выделена жирным)
В 5 версии работает!
Задача: на главной странице сайта реализовать подбор товаров по дополнительным свойствам.
Решение:
1. Создаем Xsl шаблон "Фильтр"
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:decimal-format name="my" decimal-separator="," grouping-separator=" "/>
<xsl:template match="/">
<xsl:apply-templates select="/shop"/>
</xsl:template>
<!-- Шаблон для магазина -->
<xsl:template match="/shop">
<!-- Получаем ID родительской группы и записываем в переменную $parent_group_id -->
<xsl:variable name="parent_group_id" select="@current_group_id"/>
<xsl:variable name="count">1</xsl:variable>
<form method="get" action="{/shop/path}{//group[@id=$parent_group_id]/fullpath}">
<div class="search2">
<div>
<!-- Если есть доступные производители -->
Производитель: 
<select name="producer_id">
<option value="0">…</option>
<xsl:apply-templates select="producerslist/producer"/>
</select> 
<!-- Если есть доступные продавцы -->
<xsl:if test="count(sallers/saller) > 0">
Продавец: 
<select name="saller_id">
<option value="0">…</option>
<xsl:apply-templates select="sallers/saller"/>
</select> 
</xsl:if>
</div>
<xsl:if test="count(properties_for_group/property[property_show_kind != 0 and (shop_list_of_properties_type = 0 or shop_list_of_properties_type = 2 or shop_list_of_properties_type = 7)]) > 0">
<xsl:apply-templates select="properties_for_group/property[property_show_kind != 0 and (shop_list_of_properties_type = 0 or shop_list_of_properties_type = 2 or shop_list_of_properties_type = 7)]"/>
</xsl:if>
<span style="white-space: nowrap">Товаров на странице:</span> 
<select name="on_page">
<option value="0">…</option>
<xsl:call-template name="for_on_page">
<xsl:with-param name="i" select="10"/>
<xsl:with-param name="n" select="50"/>
</xsl:call-template>
</select> <br/>
Цена
до: 
<input name="price_to" size="5" type="text">
<xsl:if test="/shop/price_to != 0">
<xsl:attribute name="value">
<xsl:value-of disable-output-escaping="yes" select="/shop/price_to"/>
</xsl:attribute>
</xsl:if>
</input>  рублей
<div class="btn-holder">
<input class="btn" name="apply_filter" value="Поиск" type="submit"/>
<div class="r-corner"></div>
</div>
</div>
<!-- Определяем ссылку с параметрами фильтра -->
<xsl:variable name="filter">
<xsl:choose>
<xsl:when test="/shop/apply_filter/node()">?action=apply_filter&producer_id=<xsl:value-of select="/shop/producer_id"/>&saller_id=<xsl:value-of select="/shop/saller_id"/>&price_from=<xsl:value-of select="/shop/price_from"/>&price_to=<xsl:value-of select="/shop/price_to"/>&on_page=<xsl:value-of select="/shop/on_page"/>
<xsl:if test="/shop/property_xml/node()">
<!-- GET для доп. свойств -->
<xsl:value-of select="/shop/property_xml"/>
</xsl:if>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Определяем первый символ вопрос или амперсанд -->
<xsl:variable name="first_symbol">
<xsl:choose>
<xsl:when test="$filter != ''">&</xsl:when>
<xsl:otherwise>?</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="count(/shop/group[@id = /shop/@current_group_id]/propertys/property) > 0">
<div style="margin: 10px 0px;">
<h2>Атрибуты группы товаров</h2>
<xsl:if test="count(property[@dir_id = 0])">
<table border="0">
<xsl:apply-templates select="property[@dir_id = 0]"/>
</table>
</xsl:if>
<xsl:apply-templates select="/shop/properties_groups_dir"/>
</div>
</xsl:if>
<xsl:if test="count_items > 0 and items_on_page > 0">
<xsl:variable name="count_pages" select="ceiling(count_items div items_on_page)"/>
<xsl:variable name="visible_pages" select="5"/>
<xsl:variable name="real_visible_pages"><xsl:choose>
<xsl:when test="$count_pages < $visible_pages"><xsl:value-of select="$count_pages"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$visible_pages"/></xsl:otherwise>
</xsl:choose></xsl:variable>
<!-- Считаем количество выводимых ссылок перед текущим элементом -->
<xsl:variable name="pre_count_page"><xsl:choose>
<xsl:when test="current_page - (floor($real_visible_pages div 2)) < 0">
<xsl:value-of select="current_page"/>
</xsl:when>
<xsl:when test="($count_pages - current_page - 1) < floor($real_visible_pages div 2)">
<xsl:value-of select="$real_visible_pages - ($count_pages - current_page - 1) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="round($real_visible_pages div 2) = $real_visible_pages div 2">
<xsl:value-of select="floor($real_visible_pages div 2) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="floor($real_visible_pages div 2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<!-- Считаем количество выводимых ссылок после текущего элемента -->
<xsl:variable name="post_count_page"><xsl:choose>
<xsl:when test="0 > current_page - (floor($real_visible_pages div 2) - 1)">
<xsl:value-of select="$real_visible_pages - current_page - 1"/>
</xsl:when>
<xsl:when test="($count_pages - current_page - 1) < floor($real_visible_pages div 2)">
<xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:variable name="i"><xsl:choose>
<xsl:when test="current_page + 1 = $count_pages"><xsl:value-of select="current_page - $real_visible_pages + 1"/></xsl:when>
<xsl:when test="current_page - $pre_count_page > 0"><xsl:value-of select="current_page - $pre_count_page"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose></xsl:variable>
</xsl:if>
</form>
</xsl:template>
<!-- Вывод строки со значением свойства -->
<xsl:template match="property">
<tr>
<td style="padding: 5px" bgcolor="#E5DFDA">
<b><xsl:value-of select="name"/></b>
</td>
<td style="padding: 5px" bgcolor="#E5DFDA">
<xsl:choose>
<xsl:when test="type = 1">
<a href="{file_path}">Скачать файл</a>
</xsl:when>
<xsl:when test="type = 7">
<xsl:choose>
<xsl:when test="value = 1">
<input type="checkbox" checked="" disabled="" />
</xsl:when>
<xsl:otherwise>
<input type="checkbox" disabled="" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="value"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<!-- Шаблон для фильтра производителей -->
<xsl:template match="producerslist/producer">
<xsl:param name="id_prod" select="@id"/>
<option value="{@id}">
<xsl:if test="@id = /shop/producer_id">
<xsl:attribute name="selected"> </xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</option>
</xsl:template>
<!-- Шаблон для фильтра продавцов -->
<xsl:template match="sallers/saller">
<option value="{@id}">
<xsl:if test="@id = /shop/saller_id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of select="sallers_name"/>
</option>
</xsl:template>
<!-- Шаблон для фильтра по дополнительным свойствам -->
<xsl:template match="properties_for_group/property">
<xsl:variable name="nodename">property_id_<xsl:value-of select="@id"/></xsl:variable>
<xsl:variable name="nodename_from">property_id_<xsl:value-of select="@id"/>_from</xsl:variable>
<xsl:variable name="nodename_to">property_id_<xsl:value-of select="@id"/>_to</xsl:variable>
<td>
<xsl:value-of disable-output-escaping="yes" select="property_name"/> 
<xsl:if test="property_show_kind = 1">
<!-- Отображаем поле ввода -->
<br/>
<input type="text" name="property_id_{@id}">
<xsl:if test="/shop/*[name()=$nodename] != ''">
<xsl:attribute name="value">
<xsl:value-of select="/shop/*[name()=$nodename]"/>
</xsl:attribute>
</xsl:if>
</input>
</xsl:if>
<xsl:if test="property_show_kind = 2">
<!-- Отображаем список -->
<br/>
<select name="property_id_{@id}">
<option value="0">...</option>-->
<xsl:apply-templates select="list_items/list_item"/>
</select>
</xsl:if>
<xsl:if test="property_show_kind = 3">
<!-- Отображаем переключатели -->
<br/>
<input type="radio" name="property_id_{@id}" value="0" id="id_prop_radio_{@id}_0"></input>
<label for="id_prop_radio_{@id}_0">Любой вариант</label>
<xsl:apply-templates select="list_items/list_item"/>
</xsl:if>
<xsl:if test=" property_show_kind = 4">
<!-- Отображаем флажки -->
<xsl:apply-templates select="list_items/list_item"/>
</xsl:if>
<xsl:if test=" property_show_kind = 5">
<!-- Отображаем флажок -->
<br/>
<input type="checkbox" name="property_id_{@id}" id="property_id_{@id}" style="padding-top:4px">
<xsl:if test="/shop/*[name()=$nodename] != ''">
<xsl:attribute name="checked">
<xsl:value-of select="/shop/*[name()=$nodename]"/>
</xsl:attribute>
</xsl:if>
</input>
<label for="property_id_{@id}">Да</label>
</xsl:if>
<xsl:if test=" property_show_kind = 6">
<!-- Отображение полей "От.. До.." -->
<br/>
от: <input type="text" name="property_id_{@id}_from" size="5" value="{/shop/*[name()=$nodename_from]}"/> до: <input type="text" name="property_id_{@id}_to" size="5" value="{/shop/*[name()=$nodename_to]}"/>
</xsl:if>
<xsl:if test="property_show_kind = 7">
<!-- Отображаем список с множественным выбором-->
<br/>
<select name="property_id_{@id}[]" multiple="">
<xsl:apply-templates select="list_items/list_item"/>
</select>
</xsl:if>
</td>
<xsl:if test="position() mod 6 = 0">
<xsl:text disable-output-escaping="yes">
</tr>
<tr valign="top">
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="list_items/list_item">
<xsl:if test="../../property_show_kind = 2">
<!-- Отображаем список -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<option value="{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</option>
</xsl:if>
<xsl:if test="../../property_show_kind = 3">
<!-- Отображаем переключатели -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<br/>
<input type="radio" name="property_id_{../../@id}" value="{@id}" id="id_property_id_{../../@id}_{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<label for="id_property_id_{../../@id}_{@id}">
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</label>
</input>
</xsl:if>
<xsl:if test="../../property_show_kind = 4">
<!-- Отображаем флажки -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/>_item_id_<xsl:value-of select="@id"/></xsl:variable>
<br/>
<input type="checkbox" name="property_id_{../../@id}_item_id_{@id}" id="id_property_id_{../../@id}_{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<label for="id_property_id_{../../@id}_{@id}">
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</label>
</input>
</xsl:if>
<xsl:if test="../../property_show_kind = 7">
<!-- Отображаем список -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<option value="{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</option>
</xsl:if>
</xsl:template>
<!-- Цикл с шагом 10 для select'a количества элементов на страницу -->
<xsl:template name="for_on_page">
<xsl:param name="i" select="0"/>
<xsl:param name="n"/>
<option value="{$i}">
<xsl:if test="$i = /shop/on_page">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of select="$i"/>
</option>
<xsl:if test="$n > $i">
<!-- Рекурсивный вызов шаблона -->
<xsl:call-template name="for_on_page">
<xsl:with-param name="i" select="$i + 10"/>
<xsl:with-param name="n" select="$n"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
<!DOCTYPE xsl:stylesheet>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output xmlns="http://www.w3.org/TR/xhtml1/strict" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" encoding="utf-8" indent="yes" method="html" omit-xml-declaration="no" version="1.0" media-type="text/xml"/>
<xsl:decimal-format name="my" decimal-separator="," grouping-separator=" "/>
<xsl:template match="/">
<xsl:apply-templates select="/shop"/>
</xsl:template>
<!-- Шаблон для магазина -->
<xsl:template match="/shop">
<!-- Получаем ID родительской группы и записываем в переменную $parent_group_id -->
<xsl:variable name="parent_group_id" select="@current_group_id"/>
<xsl:variable name="count">1</xsl:variable>
<form method="get" action="{/shop/path}{//group[@id=$parent_group_id]/fullpath}">
<div class="search2">
<div>
<!-- Если есть доступные производители -->
Производитель: 
<select name="producer_id">
<option value="0">…</option>
<xsl:apply-templates select="producerslist/producer"/>
</select> 
<!-- Если есть доступные продавцы -->
<xsl:if test="count(sallers/saller) > 0">
Продавец: 
<select name="saller_id">
<option value="0">…</option>
<xsl:apply-templates select="sallers/saller"/>
</select> 
</xsl:if>
</div>
<xsl:if test="count(properties_for_group/property[property_show_kind != 0 and (shop_list_of_properties_type = 0 or shop_list_of_properties_type = 2 or shop_list_of_properties_type = 7)]) > 0">
<xsl:apply-templates select="properties_for_group/property[property_show_kind != 0 and (shop_list_of_properties_type = 0 or shop_list_of_properties_type = 2 or shop_list_of_properties_type = 7)]"/>
</xsl:if>
<span style="white-space: nowrap">Товаров на странице:</span> 
<select name="on_page">
<option value="0">…</option>
<xsl:call-template name="for_on_page">
<xsl:with-param name="i" select="10"/>
<xsl:with-param name="n" select="50"/>
</xsl:call-template>
</select> <br/>
Цена
до: 
<input name="price_to" size="5" type="text">
<xsl:if test="/shop/price_to != 0">
<xsl:attribute name="value">
<xsl:value-of disable-output-escaping="yes" select="/shop/price_to"/>
</xsl:attribute>
</xsl:if>
</input>  рублей
<div class="btn-holder">
<input class="btn" name="apply_filter" value="Поиск" type="submit"/>
<div class="r-corner"></div>
</div>
</div>
<!-- Определяем ссылку с параметрами фильтра -->
<xsl:variable name="filter">
<xsl:choose>
<xsl:when test="/shop/apply_filter/node()">?action=apply_filter&producer_id=<xsl:value-of select="/shop/producer_id"/>&saller_id=<xsl:value-of select="/shop/saller_id"/>&price_from=<xsl:value-of select="/shop/price_from"/>&price_to=<xsl:value-of select="/shop/price_to"/>&on_page=<xsl:value-of select="/shop/on_page"/>
<xsl:if test="/shop/property_xml/node()">
<!-- GET для доп. свойств -->
<xsl:value-of select="/shop/property_xml"/>
</xsl:if>
</xsl:when>
<xsl:otherwise></xsl:otherwise>
</xsl:choose>
</xsl:variable>
<!-- Определяем первый символ вопрос или амперсанд -->
<xsl:variable name="first_symbol">
<xsl:choose>
<xsl:when test="$filter != ''">&</xsl:when>
<xsl:otherwise>?</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:if test="count(/shop/group[@id = /shop/@current_group_id]/propertys/property) > 0">
<div style="margin: 10px 0px;">
<h2>Атрибуты группы товаров</h2>
<xsl:if test="count(property[@dir_id = 0])">
<table border="0">
<xsl:apply-templates select="property[@dir_id = 0]"/>
</table>
</xsl:if>
<xsl:apply-templates select="/shop/properties_groups_dir"/>
</div>
</xsl:if>
<xsl:if test="count_items > 0 and items_on_page > 0">
<xsl:variable name="count_pages" select="ceiling(count_items div items_on_page)"/>
<xsl:variable name="visible_pages" select="5"/>
<xsl:variable name="real_visible_pages"><xsl:choose>
<xsl:when test="$count_pages < $visible_pages"><xsl:value-of select="$count_pages"/></xsl:when>
<xsl:otherwise><xsl:value-of select="$visible_pages"/></xsl:otherwise>
</xsl:choose></xsl:variable>
<!-- Считаем количество выводимых ссылок перед текущим элементом -->
<xsl:variable name="pre_count_page"><xsl:choose>
<xsl:when test="current_page - (floor($real_visible_pages div 2)) < 0">
<xsl:value-of select="current_page"/>
</xsl:when>
<xsl:when test="($count_pages - current_page - 1) < floor($real_visible_pages div 2)">
<xsl:value-of select="$real_visible_pages - ($count_pages - current_page - 1) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="round($real_visible_pages div 2) = $real_visible_pages div 2">
<xsl:value-of select="floor($real_visible_pages div 2) - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="floor($real_visible_pages div 2)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<!-- Считаем количество выводимых ссылок после текущего элемента -->
<xsl:variable name="post_count_page"><xsl:choose>
<xsl:when test="0 > current_page - (floor($real_visible_pages div 2) - 1)">
<xsl:value-of select="$real_visible_pages - current_page - 1"/>
</xsl:when>
<xsl:when test="($count_pages - current_page - 1) < floor($real_visible_pages div 2)">
<xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$real_visible_pages - $pre_count_page - 1"/>
</xsl:otherwise>
</xsl:choose></xsl:variable>
<xsl:variable name="i"><xsl:choose>
<xsl:when test="current_page + 1 = $count_pages"><xsl:value-of select="current_page - $real_visible_pages + 1"/></xsl:when>
<xsl:when test="current_page - $pre_count_page > 0"><xsl:value-of select="current_page - $pre_count_page"/></xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose></xsl:variable>
</xsl:if>
</form>
</xsl:template>
<!-- Вывод строки со значением свойства -->
<xsl:template match="property">
<tr>
<td style="padding: 5px" bgcolor="#E5DFDA">
<b><xsl:value-of select="name"/></b>
</td>
<td style="padding: 5px" bgcolor="#E5DFDA">
<xsl:choose>
<xsl:when test="type = 1">
<a href="{file_path}">Скачать файл</a>
</xsl:when>
<xsl:when test="type = 7">
<xsl:choose>
<xsl:when test="value = 1">
<input type="checkbox" checked="" disabled="" />
</xsl:when>
<xsl:otherwise>
<input type="checkbox" disabled="" />
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="value"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:template>
<!-- Шаблон для фильтра производителей -->
<xsl:template match="producerslist/producer">
<xsl:param name="id_prod" select="@id"/>
<option value="{@id}">
<xsl:if test="@id = /shop/producer_id">
<xsl:attribute name="selected"> </xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="name"/>
</option>
</xsl:template>
<!-- Шаблон для фильтра продавцов -->
<xsl:template match="sallers/saller">
<option value="{@id}">
<xsl:if test="@id = /shop/saller_id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of select="sallers_name"/>
</option>
</xsl:template>
<!-- Шаблон для фильтра по дополнительным свойствам -->
<xsl:template match="properties_for_group/property">
<xsl:variable name="nodename">property_id_<xsl:value-of select="@id"/></xsl:variable>
<xsl:variable name="nodename_from">property_id_<xsl:value-of select="@id"/>_from</xsl:variable>
<xsl:variable name="nodename_to">property_id_<xsl:value-of select="@id"/>_to</xsl:variable>
<td>
<xsl:value-of disable-output-escaping="yes" select="property_name"/> 
<xsl:if test="property_show_kind = 1">
<!-- Отображаем поле ввода -->
<br/>
<input type="text" name="property_id_{@id}">
<xsl:if test="/shop/*[name()=$nodename] != ''">
<xsl:attribute name="value">
<xsl:value-of select="/shop/*[name()=$nodename]"/>
</xsl:attribute>
</xsl:if>
</input>
</xsl:if>
<xsl:if test="property_show_kind = 2">
<!-- Отображаем список -->
<br/>
<select name="property_id_{@id}">
<option value="0">...</option>-->
<xsl:apply-templates select="list_items/list_item"/>
</select>
</xsl:if>
<xsl:if test="property_show_kind = 3">
<!-- Отображаем переключатели -->
<br/>
<input type="radio" name="property_id_{@id}" value="0" id="id_prop_radio_{@id}_0"></input>
<label for="id_prop_radio_{@id}_0">Любой вариант</label>
<xsl:apply-templates select="list_items/list_item"/>
</xsl:if>
<xsl:if test=" property_show_kind = 4">
<!-- Отображаем флажки -->
<xsl:apply-templates select="list_items/list_item"/>
</xsl:if>
<xsl:if test=" property_show_kind = 5">
<!-- Отображаем флажок -->
<br/>
<input type="checkbox" name="property_id_{@id}" id="property_id_{@id}" style="padding-top:4px">
<xsl:if test="/shop/*[name()=$nodename] != ''">
<xsl:attribute name="checked">
<xsl:value-of select="/shop/*[name()=$nodename]"/>
</xsl:attribute>
</xsl:if>
</input>
<label for="property_id_{@id}">Да</label>
</xsl:if>
<xsl:if test=" property_show_kind = 6">
<!-- Отображение полей "От.. До.." -->
<br/>
от: <input type="text" name="property_id_{@id}_from" size="5" value="{/shop/*[name()=$nodename_from]}"/> до: <input type="text" name="property_id_{@id}_to" size="5" value="{/shop/*[name()=$nodename_to]}"/>
</xsl:if>
<xsl:if test="property_show_kind = 7">
<!-- Отображаем список с множественным выбором-->
<br/>
<select name="property_id_{@id}[]" multiple="">
<xsl:apply-templates select="list_items/list_item"/>
</select>
</xsl:if>
</td>
<xsl:if test="position() mod 6 = 0">
<xsl:text disable-output-escaping="yes">
</tr>
<tr valign="top">
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template match="list_items/list_item">
<xsl:if test="../../property_show_kind = 2">
<!-- Отображаем список -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<option value="{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</option>
</xsl:if>
<xsl:if test="../../property_show_kind = 3">
<!-- Отображаем переключатели -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<br/>
<input type="radio" name="property_id_{../../@id}" value="{@id}" id="id_property_id_{../../@id}_{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<label for="id_property_id_{../../@id}_{@id}">
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</label>
</input>
</xsl:if>
<xsl:if test="../../property_show_kind = 4">
<!-- Отображаем флажки -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/>_item_id_<xsl:value-of select="@id"/></xsl:variable>
<br/>
<input type="checkbox" name="property_id_{../../@id}_item_id_{@id}" id="id_property_id_{../../@id}_{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="checked">checked</xsl:attribute>
</xsl:if>
<label for="id_property_id_{../../@id}_{@id}">
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</label>
</input>
</xsl:if>
<xsl:if test="../../property_show_kind = 7">
<!-- Отображаем список -->
<xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>
<option value="{@id}">
<xsl:if test="/shop/*[name()=$nodename] = @id">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
</option>
</xsl:if>
</xsl:template>
<!-- Цикл с шагом 10 для select'a количества элементов на страницу -->
<xsl:template name="for_on_page">
<xsl:param name="i" select="0"/>
<xsl:param name="n"/>
<option value="{$i}">
<xsl:if test="$i = /shop/on_page">
<xsl:attribute name="selected">
</xsl:attribute>
</xsl:if>
<xsl:value-of select="$i"/>
</option>
<xsl:if test="$n > $i">
<!-- Рекурсивный вызов шаблона -->
<xsl:call-template name="for_on_page">
<xsl:with-param name="i" select="$i + 10"/>
<xsl:with-param name="n" select="$n"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
2. Подключаем шаблон в макете в нужном месте, не забываем указывать свой id магазина
<?php
$Shop = & singleton('shop');
$Shop->showshop(1, 'Фильтр');
?>
$Shop = & singleton('shop');
$Shop->showshop(1, 'Фильтр');
?>
3. В ТДС интернет магазина добавляем
$param['current_group_id'] = false
Для того, чтобы вывод происходил из всех групп.4. В Xsl шаблоне вывода каталога товаров (по умолчанию это "МагазинКаталогТоваров" нужно добавить условие, что если выбран фильтр, группы товаров не отображаются. Для этого вносим поправку в код( поправка выделена жирным)
<!-- Отображение подгрупп данной группы, только если подгруппы есть и не идет фильтра по меткам -->
<xsl:if test="count(selected_tags/tag) = 0 and count(//group[@parent=$parent_group_id]) > 0 and apply_filter = 0">
<table width="100%" border="0" cellpadding="50" cellspacing="20">
<tr>
<td valign="top">
<xsl:apply-templates select="//group[@parent=$parent_group_id]"/>
</td>
</tr>
</table><br/>
</xsl:if>
<xsl:if test="count(selected_tags/tag) = 0 and count(//group[@parent=$parent_group_id]) > 0 and apply_filter = 0">
<table width="100%" border="0" cellpadding="50" cellspacing="20">
<tr>
<td valign="top">
<xsl:apply-templates select="//group[@parent=$parent_group_id]"/>
</td>
</tr>
</table><br/>
</xsl:if>
В 5 версии работает!
avtozakup
24 февраля 2013 г.
Гениально почти то что нужно скажите а если данный фильтр нужно организовать в определенных подкатегориях, а не на главной странице сайта ? Это как то можно?
hell0men
3 марта 2013 г.
Что-то не работает
Фильтр такой
Результат, само, собой, тоже пустой
Как раз искал что то подобное с возможностью задать несколько полей для подбора + группу, в которой искать, включая вложенные. Помогите, если что, могу заплатить.
Фильтр такой
Результат, само, собой, тоже пустой
Как раз искал что то подобное с возможностью задать несколько полей для подбора + группу, в которой искать, включая вложенные. Помогите, если что, могу заплатить.
http://www.aiventa.ru
Авторизация