Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Product details in dashboard
Mira Szewczykbabe404135b1
diff --git a/saleor/dashboard/product/views.py b/saleor/dashboard/product/views.pyindex 4838eacd3d..4c5c9de0e9 100644--- a/saleor/dashboard/product/views.py+++ b/saleor/dashboard/product/views.py@@ -13,7 +13,8 @@ from ...core.utils import get_paginator_itemsfrom ...product.models import (Product, ProductAttribute, ProductClass,ProductImage, ProductVariant, Stock,StockLocation)-from ...product.utils import get_product_attributes_data+from ...product.utils import (get_product_attributes_data, get_availability,+ price_range_as_dict)from ..views import staff_member_required@@ -138,7 +139,11 @@ def product_detail(request, pk):'product_class__product_attributes__values', 'categories').all()product = get_object_or_404(products, pk=pk)attributes = get_product_attributes_data(product)- ctx = {'product': product, 'attributes': attributes}+ availability = get_availability(product)+ sale_price = availability.price_range+ gross_price_range = product.get_gross_price_range()+ ctx = {'product': product, 'attributes': attributes,+ 'sale_price': sale_price, 'gross_price_range': gross_price_range}return TemplateResponse(request, 'dashboard/product/product_detail.html', ctx)diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 0868d9a172..6781bf557b 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -200,6 +200,11 @@ class Product(models.Model, ItemRange, index.Indexed):return super(Product, self).get_price_range(discounts=discounts, **kwargs)+ def get_gross_price_range(self, **kwargs):+ grosses = [self.get_price_per_item(item, **kwargs) for item in self]+ grosses = sorted(grosses, key=lambda x: x.tax)+ return PriceRange(min(grosses), max(grosses))+@python_2_unicode_compatibleclass ProductVariant(models.Model, Item):diff --git a/templates/dashboard/product/product_detail.html b/templates/dashboard/product/product_detail.htmlindex 85846b7609..f20ca37237 100644--- a/templates/dashboard/product/product_detail.html+++ b/templates/dashboard/product/product_detail.html@@ -57,90 +57,52 @@{% endblock %}{% block content %}- <div class="row">- <div class="col s12">- <ul class="tabs">- <li class="tab col s3" role="presentation">- <a href="#details" class="active" role="tab">- <span>- {% trans "Details" context "Product form tab" %}- </span>- </a>- </li>- {% if product.product_class.has_variants %}- <li class="tab col s3" role="presentation">- <a href="#variants" role="tab">- <span>- {% trans "Variants" context "Product form tab" %}- </span>- </a>- </li>- {% endif %}- <li class="tab col s3" role="presentation">- <a href="#stock" role="tab">- <span>- {% trans "Stock" context "Product form tab" %}- </span>- </a>- </li>- <li class="tab col s3" role="presentation">- <a href="#images" role="tab">- <span>- {% trans "Images" context "Product form tab" %}- </span>- </a>- </li>- </ul>- </div>- </div>-<div class="tab-content" id="details"><div class="row"><div class="col m12 l12"><div class="card"><div class="card-content">- <span class="card-title">{{ product.product_class }}</span>+ <span class="card-title">{{ product }}</span><div class="row">- <div class="col s12 l9">- <h5>{% trans "Name" context "Product field" %}</h5>- <p>{{ product.name }}</p>+ <div class="col s12 l3">+ <h5>{% trans "Sale price" context "Product field" %}</h5>+ {% with sale_price.min_price as min_price %}+ {% with sale_price.max_price as max_price %}+ <p>{% gross min_price %} - {% gross max_price %}</p>+ {% endwith %}+ {% endwith %}</div><div class="col s12 l3">- <h5>{% trans "Price" context "Product field" %}</h5>- <p>{% gross product.price %}</p>+ <h5>{% trans "Purchase cost" context "Product field" %}</h5>+ {% with sale_price.min_price as min_price %}+ {% with sale_price.max_price as max_price %}+ <p>{% net min_price %} - {% net max_price %}</p>+ {% endwith %}+ {% endwith %}</div>- {% for attribute, value in attributes.items %}- <div class="col s12 l9">- <h5>{{ attribute }}</h5>- <p>{{ value }}</p>- </div>- {% endfor %}- {% if product.description %}- <div class="col s12 l9">- <h5>{% trans "Description" context "Product field" %}</h5>- <p>{{ product.description }}</p>- </div>- {% endif %}- {% if product.categories.all %}- <div class="col s12 l9">- <h5>{% trans "Categories" context "Product field" %}</h5>- <p>- {% for category in product.categories.all %}- {{ category }},- {% endfor %}- </p>- </div>- {% endif %}- {% if product.available_on %}- <div class="col s12 l9">- <h5>{% trans "Available on" context "Product field" %}</h5>- <p>{{ product.available_on }}</p>+ <div class="col s12 l3">+ <h5>{% trans "Gross margin" context "Product field" %}</h5>+ {% with gross_price_range.min_price as min_price %}+ {% with gross_price_range.max_price as max_price %}+ <p>{% tax min_price %} - {% tax max_price %}</p>+ {% endwith %}+ {% endwith %}</div>- {% endif %}</div></div></div></div></div></div>+ <div class="tab-content" id="details">+ <div class="row">+ <div class="col m12 l12">+ <div class="card">+ <div class="card-content">+ <span class="card-title">{% trans "Variant" %}</span>+ </div>+ </div>+ </div>+ </div>+ </div>{% endblock %}