Skip to content

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

Pass discounts when calculating cart prices

Anna Siwik03606778f7a1
diff --git a/saleor/cart/models.py b/saleor/cart/models.py
index 4fecdc68ad..53925e7735 100644
--- a/saleor/cart/models.py
+++ b/saleor/cart/models.py
@@ -147,9 +147,9 @@ class Cart(models.Model):
def __len__(self):
return self.lines.count()
- def get_total(self):
+ def get_total(self, discounts=None):
"""Return the total cost of the cart prior to shipping."""
- subtotals = [line.get_total() for line in self.lines.all()]
+ subtotals = [line.get_total(discounts) for line in self.lines.all()]
if not subtotals:
raise AttributeError('Calling get_total() on an empty cart')
zero = Price(0, currency=settings.DEFAULT_CURRENCY)
@@ -267,9 +267,9 @@ class CartLine(models.Model):
def __setstate__(self, data):
self.variant, self.quantity, self.data = data
- def get_total(self):
+ def get_total(self, discounts=None):
"""Return the total price of this line."""
- amount = self.get_price_per_item() * self.quantity
+ amount = self.get_price_per_item(discounts) * self.quantity
return amount.quantize(CENTS)
# pylint: disable=W0221
diff --git a/templates/order/_ordered_items_table.html b/templates/order/_ordered_items_table.html
index 571d6030cb..0eb841ed3e 100644
--- a/templates/order/_ordered_items_table.html
+++ b/templates/order/_ordered_items_table.html
@@ -47,26 +47,26 @@
</div>
</div>
-{% for item in order %}
- {% for item_line in item %}
+{% for group in order %}
+ {% for line in group %}
<div class="table__row order-details__product{% if forloop.last %} order-details__last-row{% endif %}">
<div class="row">
<div class="col-md-6 col-9">
- <a class="link--clean" href="{% if item_line.product %}{{ item_line.product.get_absolute_url }}{% endif %}">
- <img data-src="{% product_first_image item_line.product size="60x60" method="crop" %}"
- data-srcset="{% product_first_image item_line.product size="60x60" method="crop" %} 1x, {% product_first_image item_line.product size="120x120" method="crop" %} 2x"
+ <a class="link--clean" href="{% if line.product %}{{ line.product.get_absolute_url }}{% endif %}">
+ <img data-src="{% product_first_image line.product size="60x60" method="crop" %}"
+ data-srcset="{% product_first_image line.product size="60x60" method="crop" %} 1x, {% product_first_image line.product size="120x120" method="crop" %} 2x"
class="float-left lazyload lazypreload"
src="{% placeholder size=60 %}">
- <span class="order-details__product__description">{{ item_line.product_name }}</span>
+ <span class="order-details__product__description">{{ line.product_name }}</span>
</a>
</div>
<div class="col-md-6 col-3">
<div class="row">
<div class="col-md-6 col-12">
- <p class="float-right">x {{ item_line.quantity }}</p>
+ <p class="float-right">x {{ line.quantity }}</p>
</div>
<div class="col-md-6 col-12">
- <p class="float-right">{% gross item_line.get_total html=True %}</p>
+ <p class="float-right">{% gross line.get_total html=True %}</p>
</div>
</div>
</div>
@@ -78,13 +78,13 @@
<div class="row">
<div class="col-12 order-details__table-footer">
<p>
- {% blocktrans trimmed with shipping_method_name=item.shipping_method_name context "Order details shipment row text" %}
+ {% blocktrans trimmed with shipping_method_name=group.shipping_method_name context "Order details shipment row text" %}
Shipping ({{ shipping_method_name }})
{% endblocktrans %}
</p>
- {% if item.tracking_number %}
+ {% if group.tracking_number %}
<p>
- {% blocktrans trimmed with tracking_number=item.tracking_number context "Order details shipment row text" %}
+ {% blocktrans trimmed with tracking_number=group.tracking_number context "Order details shipment row text" %}
Tracking number: {{ tracking_number }}
{% endblocktrans %}
</p>