Skip to content

Instantly share code, notes, and snippets.

@brianweiner
Last active December 11, 2015 11:38
Show Gist options
  • Save brianweiner/4595339 to your computer and use it in GitHub Desktop.
Save brianweiner/4595339 to your computer and use it in GitHub Desktop.
subsection of search-filter-partial for category behavior
<!-- FIND CATEGORY -->
{% if selected_categories is defined %}
{% set current_category = method('Extensions320ny_Shop_Category', 'create').find_by_id(selected_categories[0]) %}
{% else %}
{% set current_category = category ? category : product.list_categories[0] %}
{% endif %}
<form id="search-filter" method="get" action="/search">
<input type="hidden" name="query" value="{{ query ? query: '' }}">
<!-- CATEGORIES -->
{% set categories = method('Shop_Category', 'create').list_root_children('front_end_sort_order') %}
{% set selected_categories = selected_categories ? selected_categories : [] %}
{% if categories.count %}
{{ category ? "" : "<h4>Departments</h4>"}}
<select id="category-select" style="display:none;" {{category ? '':"multiple" }} name="categories[]">
{% for category in categories %}
<option
{{ category.id in selected_categories ? 'selected="selected"' : null }}
{{ category.id == current_category.id ? 'selected="selected"' : null }}
value="{{ category.id }}">{{ category.name }}</option>
{% endfor %}
</select>
{% if category == null %}
{% for category in categories %}
<span data-select="category-select" data-value="{{category.id}}" data-type="category"
{{ category.id in selected_categories ? 'class="category-filter filter-option search-filter-selection"' : 'class="category-filter filter-option"' }}
>{{category.name}}</span>
{% endfor %}
<br><br>
{% endif %}
{% endif %}
{% set my_cat = method('Extensions320ny_Shop_Category', 'create').find_by_id(current_category.id) %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment