Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Add field to determine whether category should be hidden from the storefront

Marcin Gębala77c71017bf1e
diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.py
index fdbf03dc77..1ba4f98ea7 100644
--- a/saleor/dashboard/category/forms.py
+++ b/saleor/dashboard/category/forms.py
@@ -26,4 +26,5 @@ class CategoryForm(forms.ModelForm):
def save(self, commit=True):
self.instance.slug = slugify(unidecode(self.instance.name))
+ self.instance.set_hidden_descendants(self.cleaned_data['hidden'])
return super(CategoryForm, self).save(commit=commit)
diff --git a/saleor/dashboard/templates/dashboard/category/detail.html b/saleor/dashboard/templates/dashboard/category/detail.html
index 9aea5ef019..cda2ebb041 100644
--- a/saleor/dashboard/templates/dashboard/category/detail.html
+++ b/saleor/dashboard/templates/dashboard/category/detail.html
@@ -5,6 +5,15 @@
{% block title %}{{ title }} - {% trans 'Categories' %} - {{ block.super }}{% endblock %}
+{% block custom_css %}
+<style type="text/css">
+[type=checkbox]:not(:checked), [type=checkbox]:checked {
+ position: static;
+ visibility: visible;
+}
+</style>
+{% endblock %}
+
{% block body_class %}body-categories{% endblock %}
{% block page_title %}{{ title }}{% endblock %}
@@ -29,7 +38,10 @@
<div class="col l8 offset-l2">
<div class="row">
{% csrf_token %}
- {{ form|materializecss }}
+ {{ form.parent|materializecss }}
+ {{ form.name|materializecss }}
+ {{ form.description|materializecss }}
+ {{ form.hidden|materializecss }}
</div>
</div>
</div>
diff --git a/saleor/dashboard/templates/dashboard/category/list.html b/saleor/dashboard/templates/dashboard/category/list.html
index 1c38e09f79..4021f61563 100644
--- a/saleor/dashboard/templates/dashboard/category/list.html
+++ b/saleor/dashboard/templates/dashboard/category/list.html
@@ -40,6 +40,7 @@
{% for node in categories %}
<li class="collection-item category-list-item">
<a href="{% url 'dashboard:category-list' root_pk=node.pk %}">{{ node.name }}</a>
+ {% if node.hidden %}<span class="grey-text"> hidden</span>{% endif %}
<div class="right category-list-item-actions">
<a href="{% url 'dashboard:category-add' root_pk=node.pk %}" title="{% trans "Add child" %}">
<i class="mdi-content-add teal-text"></i>
diff --git a/saleor/product/migrations/0034_auto_20150706_0643.py b/saleor/product/migrations/0034_auto_20150706_0643.py
new file mode 100644
index 0000000000..f34d88115b
--- /dev/null
+++ b/saleor/product/migrations/0034_auto_20150706_0643.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+from django.db import models, migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0033_auto_20150701_1005'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='category',
+ name='hidden',
+ field=models.BooleanField(default=False, verbose_name='hidden'),
+ ),
+ migrations.AlterField(
+ model_name='productattribute',
+ name='name',
+ field=models.SlugField(unique=True, verbose_name='name'),
+ ),
+ ]
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index ed7cb604ad..596587fbc7 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -33,6 +33,8 @@ class Category(MPTTModel):
parent = models.ForeignKey(
'self', null=True, blank=True, related_name='children',
verbose_name=pgettext_lazy('Category field', 'parent'))
+ hidden = models.BooleanField(
+ pgettext_lazy('Category field', 'hidden'), default=False)
objects = Manager()
tree = TreeManager()
@@ -47,6 +49,11 @@ class Category(MPTTModel):
verbose_name_plural = 'categories'
app_label = 'product'
+ def set_hidden_descendants(self, hidden):
+ for category in self.get_descendants():
+ category.hidden = hidden
+ category.save()
+
@python_2_unicode_compatible
class Product(models.Model, ItemRange):
diff --git a/saleor/product/templatetags/category.py b/saleor/product/templatetags/category.py
index aefec0da77..4584c3d7d3 100644
--- a/saleor/product/templatetags/category.py
+++ b/saleor/product/templatetags/category.py
@@ -6,4 +6,4 @@ register = template.Library()
@register.inclusion_tag('category/_list.html')
def categories_list():
- return {'categories': Category.objects.all()}
+ return {'categories': Category.objects.filter(hidden=False)}