Помогите советом с реализацией данного фильтра.

#
Помогите советом с реализацией данного фильтра.
Пробовал на JavaScript не понравилось оно мне. Да и оттачивать до идеала долго нужно.

Skype:ferdinant1988 ICQ:311960596 E-mail: ferdinant@i.ua
#
Re: Помогите советом с реализацией данного фильтра.
Тут все более-менее просто.

Каждая из строк - это допсвойство типа "список".
При формировании фильтра, в xsl есть специальный темплейт, который вызывается для построения списков (select)
вот его-то и надо модифицировать так, чтобы он вместо набора тегов option выдавал набор тегов a.
Правда будет немного гемора с href - для каждой ссылки вам надо будет учесть все ранее переданные фильтры. Лучше всего, перед каждым вызовом теплейта вычислять переменную href от остальных запросов, а потом дописывать к ней варианты из списка. а для варианта "все" - ничего не дописывать.
Заказов не беру. Консультирую редко.
#
Re: Помогите советом с реализацией данного фильтра.
Kotoff писал(а):
Правда будет немного гемора с href — для каждой ссылки вам надо будет учесть все ранее переданные фильтры. Лучше всего, перед каждым вызовом теплейта вычислять переменную href от остальных запросов, а потом дописывать к ней варианты из списка. а для варианта «все» — ничего не дописывать.


Вот именно в этом мне и нужна помощь.
Skype:ferdinant1988 ICQ:311960596 E-mail: ferdinant@i.ua
#
Re: Помогите советом с реализацией данного фильтра.
Примерно так.

Сначала заменяем тот фрагмент, который формирует саму форму фильтра (это в темплейте /shop)
<div class="shop_block">

               <!-- Если есть доступные производители -->
               <xsl:if test="count(producerslist/producer) &gt; 0">
                  <p>Производитель:&#xA0;

                     <!--вычислим строку с переданными фильтрами и загоним ее в переменную
Обратите внимание на комментарий внутри переменной!
с помощью него я отключаю тот параметр, который будет меняться в списке,
в данном случае это производитель-->
                     <xsl:variable name="filter_string">
                        <!--<xsl:if test="/shop/producer_id/node()">&amp;producer_id=<xsl:value-of select="/shop/producer_id"/></xsl:if>-->
                        <xsl:if test="/shop/saller_id/node()">&amp;saller_id=<xsl:value-of select="/shop/saller_id"/></xsl:if>
                        <xsl:if test="/shop/on_page/node()">&amp;on_page=<xsl:value-of select="/shop/on_page"/></xsl:if>
                        <xsl:if test="/shop/price_from/node()">&amp;price_from=<xsl:value-of select="/shop/price_from"/></xsl:if>
                        <xsl:if test="/shop/price_to/node()">&amp;price_to=<xsl:value-of select="/shop/price_to"/></xsl:if>
                        <xsl:if test="/shop/sort_by_field/node()">&amp;sort_by_field=<xsl:value-of select="/shop/sort_by_field"/></xsl:if>
                        <xsl:if test="/shop/order_direction/node()">
                           <xsl:text>&amp;order_direction=</xsl:text>
                           <xsl:if test="/shop/order_direction = 'ASC'">1</xsl:if>
                           <xsl:if test="/shop/order_direction = 'DESC'">2</xsl:if>
                        </xsl:if>
                        <xsl:if test="/shop/property_xml/node()">
                           <xsl:value-of select="/shop/property_xml"/>
                        </xsl:if>
                     </xsl:variable>

                     <a href="./?apply_filter=1{$filter_string}">все</a>,&#xA0;
                     <xsl:apply-templates select="producerslist/producer">
                        <xsl:with-param name="add_filter" select="$filter_string"/>
                     </xsl:apply-templates>
                  </p>
               </xsl:if>

               <!-- Если есть доступные продавцы -->
               <xsl:if test="count(sallers/saller) &gt; 0">
                  <p>Продавец:&#xA0;
                     <xsl:variable name="filter_string">
                        <xsl:if test="/shop/producer_id/node()">&amp;producer_id=<xsl:value-of select="/shop/producer_id"/></xsl:if>
                        <!--<xsl:if test="/shop/saller_id/node()">&amp;saller_id=<xsl:value-of select="/shop/saller_id"/></xsl:if>-->
                        <xsl:if test="/shop/on_page/node()">&amp;on_page=<xsl:value-of select="/shop/on_page"/></xsl:if>
                        <xsl:if test="/shop/price_from/node()">&amp;price_from=<xsl:value-of select="/shop/price_from"/></xsl:if>
                        <xsl:if test="/shop/price_to/node()">&amp;price_to=<xsl:value-of select="/shop/price_to"/></xsl:if>
                        <xsl:if test="/shop/sort_by_field/node()">&amp;sort_by_field=<xsl:value-of select="/shop/sort_by_field"/></xsl:if>
                        <xsl:if test="/shop/order_direction/node()">
                           <xsl:text>&amp;order_direction=</xsl:text>
                           <xsl:if test="/shop/order_direction = 'ASC'">1</xsl:if>
                           <xsl:if test="/shop/order_direction = 'DESC'">2</xsl:if>
                        </xsl:if>
                        <xsl:if test="/shop/property_xml/node()">
                           <xsl:value-of select="/shop/property_xml"/>
                        </xsl:if>
                     </xsl:variable>

                     <a href="./?apply_filter=1{$filter_string}">все</a>,&#xA0;
                     <xsl:apply-templates select="sallers/saller">
                        <xsl:with-param name="add_filter" select="$filter_string"/>
                     </xsl:apply-templates>
                  </p>
               </xsl:if>Цена от:&#xA0;
               <input name="price_from" size="5" type="text">
                  <xsl:if test="/shop/price_from != 0">
                     <xsl:attribute name="value">
                        <xsl:value-of disable-output-escaping="yes" select="/shop/price_from"/>
                     </xsl:attribute>
                  </xsl:if>
               </input>&#xA0;
                  
                  до:&#xA0;
               <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>&#xA0;

               <p>
                  <span style="white-space: nowrap">Товаров на странице:</span>&#xA0;
                  <xsl:variable name="filter_string">
                     <xsl:if test="/shop/producer_id/node()">&amp;producer_id=<xsl:value-of select="/shop/producer_id"/></xsl:if>
                     <xsl:if test="/shop/saller_id/node()">&amp;saller_id=<xsl:value-of select="/shop/saller_id"/></xsl:if>
                     <!--<xsl:if test="/shop/on_page/node()">&amp;on_page=<xsl:value-of select="/shop/on_page"/></xsl:if>-->
                     <xsl:if test="/shop/price_from/node()">&amp;price_from=<xsl:value-of select="/shop/price_from"/></xsl:if>
                     <xsl:if test="/shop/price_to/node()">&amp;price_to=<xsl:value-of select="/shop/price_to"/></xsl:if>
                     <xsl:if test="/shop/sort_by_field/node()">&amp;sort_by_field=<xsl:value-of select="/shop/sort_by_field"/></xsl:if>
                     <xsl:if test="/shop/order_direction/node()">
                        <xsl:text>&amp;order_direction=</xsl:text>
                        <xsl:if test="/shop/order_direction = 'ASC'">1</xsl:if>
                        <xsl:if test="/shop/order_direction = 'DESC'">2</xsl:if>
                     </xsl:if>
                     <xsl:if test="/shop/property_xml/node()">
                        <xsl:value-of select="/shop/property_xml"/>
                     </xsl:if>
                  </xsl:variable>

                  <xsl:call-template name="for_on_page">
                     <xsl:with-param name="i" select="10"/>
                     <xsl:with-param name="n" select="50"/>
                     <xsl:with-param name="add_filter" select="$filter_string"/>
                  </xsl:call-template>
               </p>&#xA0;
               <input name="apply_filter" value="Применить" type="submit"/>


               <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)]) &gt; 0">
                  <p>
                     <b>Фильтр по дополнительным свойствам товара:</b>
                  </p>
                  <table cellpadding="10px" cellspacing="0">
                     <tr valign="top">
                        <xsl:variable name="filter_string">
                           <xsl:if test="/shop/producer_id/node()">&amp;producer_id=<xsl:value-of select="/shop/producer_id"/></xsl:if>
                           <xsl:if test="/shop/saller_id/node()">&amp;saller_id=<xsl:value-of select="/shop/saller_id"/></xsl:if>
                           <xsl:if test="/shop/on_page/node()">&amp;on_page=<xsl:value-of select="/shop/on_page"/></xsl:if>
                           <xsl:if test="/shop/price_from/node()">&amp;price_from=<xsl:value-of select="/shop/price_from"/></xsl:if>
                           <xsl:if test="/shop/price_to/node()">&amp;price_to=<xsl:value-of select="/shop/price_to"/></xsl:if>
                           <xsl:if test="/shop/sort_by_field/node()">&amp;sort_by_field=<xsl:value-of select="/shop/sort_by_field"/></xsl:if>
                           <xsl:if test="/shop/order_direction/node()">
                              <xsl:text>&amp;order_direction=</xsl:text>
                              <xsl:if test="/shop/order_direction = 'ASC'">1</xsl:if>
                              <xsl:if test="/shop/order_direction = 'DESC'">2</xsl:if>
                           </xsl:if>
                           <!--<xsl:if test="/shop/property_xml/node()">
                              <xsl:value-of select="/shop/property_xml"/>
                           </xsl:if>-->
                        </xsl:variable>
                        <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:with-param name="std_filter" select="$filter_string"/>
                        </xsl:apply-templates>
                     </tr>
                  </table>
               </xsl:if>
            </div>


Теперь заменим следующие темплейты:
<!-- Шаблон для фильтра производителей -->
   <xsl:template match="producerslist/producer">
      <xsl:param name="add_filter" select="''"/>
      <a href="./?producer_id={@id}{$add_filter}&amp;apply_filter=1">
         <xsl:if test="@id = /shop/producer_id">
            <xsl:attribute name="class">current</xsl:attribute>
         </xsl:if>
         <xsl:value-of disable-output-escaping="yes" select="name"/>
      </a>
      <xsl:if test="position() != last()">,<xsl:text> </xsl:text></xsl:if>
   </xsl:template>


<!-- Шаблон для фильтра продавцов -->
   <xsl:template match="sallers/saller">
      <xsl:param name="add_filter" select="''"/>
      <a href="./?saller_id={@id}{$add_filter}&amp;apply_filter=1">
         <xsl:if test="@id = /shop/saller_id">
            <xsl:attribute name="class">current</xsl:attribute>
         </xsl:if>
         <xsl:value-of disable-output-escaping="yes" select="name"/>
      </a>
      <xsl:if test="position() != last()">,<xsl:text> </xsl:text></xsl:if>
   </xsl:template>


<!-- Цикл с шагом 10 для select'a количества элементов на страницу -->
   <xsl:template name="for_on_page">
      <xsl:param name="i" select="0"/>
      <xsl:param name="n"/>
      <xsl:param name="add_filter" select="''"/>

      <a href="./?on_page={$i}{$add_filter}&amp;apply_filter=1">
         <xsl:if test="$i = /shop/on_page">
            <xsl:attribute name="class">current</xsl:attribute>
         </xsl:if>
         <xsl:value-of select="$i"/>
      </a>
      <xsl:if test="$n &gt; $i">
         <xsl:text>, </xsl:text>
         <!-- Рекурсивный вызов шаблона -->
         <xsl:call-template name="for_on_page">
            <xsl:with-param name="i" select="$i + 10"/>
            <xsl:with-param name="n" select="$n"/>
            <xsl:with-param name="add_filter" select="$add_filter"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>


<!-- Шаблон для фильтра по дополнительным свойствам -->
   <xsl:template match="properties_for_group/property">
      <xsl:param name="std_filter" select="''"/>

      <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"/>&#xA0;
         <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">
            <!-- Отображаем список -->
            <xsl:variable name="current_property_id" select="@id"/>

            <xsl:variable name="other_property_filter">
               <xsl:apply-templates select="/shop/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)][@id != $current_property_id]"
                                    mode="property_filter"/>
            </xsl:variable>

            <xsl:variable name="result_filter">
               <xsl:value-of select="$std_filter"/>
               <xsl:value-of select="$other_property_filter"/>
            </xsl:variable>

            <p>
               <a href="./?apply_filter=1{$result_filter}">все</a>,&#xA0;
               <xsl:apply-templates select="list_items/list_item">
                  <xsl:with-param name="add_filter" select="$result_filter"/>
               </xsl:apply-templates>
            </p>
         </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">
            &lt;/tr&gt;
            &lt;tr valign="top"&gt;
         </xsl:text>
      </xsl:if>
   </xsl:template>


<xsl:template match="list_items/list_item">
      <xsl:param name="add_filter" select="''"/>

      <xsl:if test="../../property_show_kind = 2">
         <!-- Отображаем список ссылками -->
         <xsl:variable name="nodename">property_id_<xsl:value-of select="../../@id"/></xsl:variable>

         <a href="./?{$nodename}={@id}{$add_filter}&amp;apply_filter=1">
            <xsl:if test="/shop/*[name()=$nodename] = @id">
               <xsl:attribute name="class">current</xsl:attribute>
            </xsl:if>
            <xsl:value-of disable-output-escaping="yes" select="list_item_value"/>
         </a>
         <xsl:if test="position() != last()">,<xsl:text> </xsl:text></xsl:if>
      </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>


и добавим еще один новый

<!-- Шаблон для подстроки фильтра по дополнительным свойствам -->
   <xsl:template match="properties_for_group/property" mode="property_filter">
      <xsl:param name="std_filter" select="''"/>
      <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>

      <xsl:if test="/shop/*[name()=$nodename] != ''">
         <xsl:text>&amp;</xsl:text>
         <xsl:value-of select="$nodename"/>
         <xsl:text>=</xsl:text>
         <xsl:value-of select="/shop/*[name()=$nodename]"/>
      </xsl:if>

      <xsl:if test="/shop/*[name()=$nodename_from] != ''">
         <xsl:text>&amp;</xsl:text>
         <xsl:value-of select="$nodename_from"/>
         <xsl:text>=</xsl:text>
         <xsl:value-of select="/shop/*[name()=$nodename_from]"/>
      </xsl:if>

      <xsl:if test="/shop/*[name()=$nodename_to] != ''">
         <xsl:text>&amp;</xsl:text>
         <xsl:value-of select="$nodename_to"/>
         <xsl:text>=</xsl:text>
         <xsl:value-of select="/shop/*[name()=$nodename_to]"/>
      </xsl:if>
   </xsl:template>


Должно работать )

На ссылки будут заменяться те доп.свойства, у которых в в настройках выбрано отображение "Список-списком".
Заказов не беру. Консультирую редко.
#
Re: Помогите советом с реализацией данного фильтра.
Kotoff писал(а):
Должно работать)


Все действительно работает! Вы Гений! Единственный нюанс а как то выделить выбранный параметр можно?  
Skype:ferdinant1988 ICQ:311960596 E-mail: ferdinant@i.ua
#
Re: Помогите советом с реализацией данного фильтра.
ferdinant, как-то можно
Я сейчас в отпуске, поэтому пример написать не могу )
Но обратите внимание, как в исходном шаблоне сделано свойство selected для тега option, и сделайте по аналогии
Заказов не беру. Консультирую редко.
#
Re: Помогите советом с реализацией данного фильтра.
Kotoff писал(а):
Kotoff
Главное отдохните робота подождет!
С э этим я разобрался там класс current. Я с другой проблемой столкнулся! это цена от до и кнопкой применить. При нажатии применить обнуляется все параметры выбранные в фильтре! Как-то я хочу придумать что цену впихнуть в этот фильтр. и убрать кнопку применить. И вторая проблема при начатии фильтра с не первой страницы например page-3 то выбранные товары не показываются и пагинация пропадает!
Skype:ferdinant1988 ICQ:311960596 E-mail: ferdinant@i.ua
Авторизация