Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
ColorVariants connected to product forms, PriceRange errors fixed in template
Artur Smęt7ca7d38415e8
diff --git a/saleor/product/forms.py b/saleor/product/forms.pyindex 099268962c..3516a6eb86 100644--- a/saleor/product/forms.py+++ b/saleor/product/forms.py@@ -1,22 +1,17 @@from django import formsfrom ..cart.forms import AddToCartForm-from .models import Bag, BagVariant, Shirt, ShirtVariant+from .models import Bag, BagVariant, Shirt, ShirtVariant, Colorclass BagForm(AddToCartForm):- color = forms.ChoiceField(choices=BagVariant.COLOR_CHOICES)+ color = forms.ModelChoiceField(queryset=None)def __init__(self, *args, **kwargs):super(BagForm, self).__init__(*args, **kwargs)color_field = self.fields['color']- color_values = list(- self.product.variants.values_list('color', flat=True))- color_choices = color_field.choices- new_choices = [- choice for choice in color_choices if choice[0] in color_values]- color_field.choices = new_choices+ color_field.queryset = self.product.get_available_colors()def get_variant(self, clean_data):color = clean_data.get('color')@@ -25,13 +20,18 @@ class BagForm(AddToCartForm):class ShirtForm(AddToCartForm):- color = forms.ChoiceField(choices=ShirtVariant.COLOR_CHOICES)+ color = forms.ModelChoiceField(queryset=None)size = forms.ChoiceField(choices=ShirtVariant.SIZE_CHOICES)def get_variant(self, clean_data):color = clean_data.get('color')size = clean_data.get('size')- return ShirtVariant.objects.get(color=color, size=size)+ return ShirtVariant.objects.get(size=size, color=color)++ def __init__(self, *args, **kwargs):+ super(ShirtForm, self).__init__(*args, **kwargs)+ color_field = self.fields['color']+ color_field.queryset = self.product.get_available_colors()def get_form_class_for_product(product):diff --git a/saleor/product/templates/product/details.html b/saleor/product/templates/product/details.htmlindex f069147c9a..4207bee561 100644--- a/saleor/product/templates/product/details.html+++ b/saleor/product/templates/product/details.html@@ -1,7 +1,7 @@{% extends "base.html" %}{% load as_vertical_form from bootstrap %}-{% load undiscounted_price price_difference from discount %}+{% load undiscounted_price undiscounted_price_range price_difference from discount %}{% load i18n %}{% load at_size from images %}{% load gross from prices %}@@ -15,8 +15,10 @@{% endblock breadcrumb %}{% block outercontent %}-{% with price=product.get_price undiscounted=product|undiscounted_price %}-{% with discount=undiscounted|price_difference:price %}++{% with price=product.get_price_range.min_price undiscounted=product|undiscounted_price_range %}+{% with discount=undiscounted.min_price|price_difference:price %}+<div itemscope itemtype="http://schema.org/Product"><h1 itemprop="name">{{ product }}@@ -30,9 +32,9 @@<div class="col-sm-4"><p itemprop="offers" itemscope itemtype="http://schema.org/Offer"><span class="price" itemprop="price">{% gross price %}</span>- {% if undiscounted != price %}+ {% if undiscounted.min_price != price %}<br>- <span class="price undiscounted">{% gross undiscounted %}</span>+ <span class="price undiscounted">{% gross undiscounted.min_price %}</span><br><small class="label label-success">{% trans "You save" %} {% gross discount %}</small>{% endif %}@@ -45,9 +47,15 @@{% endif %}</p><hr>+ <h3>{% trans "Available Colors" %}</h3>+ {% for color in product.get_available_colors %}+ <span class="label" style="background-color: #{{ color.color }}">{{ color.name }}</span>+ {% endfor %}+ <hr>+ <h3>{% trans "Order" %}</h3><form role="form" class="form-vertical" method="post" action=".">{% csrf_token %}- {{ form.quantity|as_vertical_form }}+ {{ form|as_vertical_form }}<div class="form-group"><button class="btn btn-default">diff --git a/saleor/product/templatetags/discount.py b/saleor/product/templatetags/discount.pyindex 13f5ffd76c..fa338dd661 100644--- a/saleor/product/templatetags/discount.py+++ b/saleor/product/templatetags/discount.py@@ -7,6 +7,9 @@ register = template.Library()def undiscounted_price(item):return item.get_price(discounted=False)+def undiscounted_price_range(item):+ return item.get_price_range(discounted=False)@register.filterdef price_difference(price1, price2):