Kaynağa Gözat

Added basket warnings.

When an item's price has changed, a warning is now displayed.
master
David Winterbottom 13 yıl önce
ebeveyn
işleme
bb84bab418

+ 24
- 1
oscar/apps/basket/abstract_models.py Dosyayı Görüntüle

@@ -7,6 +7,7 @@ from django.utils.translation import ugettext as _
7 7
 from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
8 8
 
9 9
 from oscar.apps.basket.managers import OpenBasketManager, SavedBasketManager
10
+from oscar.templatetags.currency_filters import currency
10 11
 
11 12
 # Basket statuses
12 13
 # - Frozen is for when a basket is in the process of being submitted
@@ -84,7 +85,7 @@ class AbstractBasket(models.Model):
84 85
         if not self.id:
85 86
             self.save()
86 87
 
87
-        # Line refernene is used to distinguish between variations of the same 
88
+        # Line reference is used to distinguish between variations of the same 
88 89
         # product (eg T-shirts with different personalisations)
89 90
         line_ref = self._create_line_reference(product, options)
90 91
 
@@ -513,6 +514,28 @@ class AbstractLine(models.Model):
513 514
             d = "%s (%s)" % (d.decode('utf-8'), ", ".join(ops))
514 515
         return d
515 516
 
517
+    def get_warning(self):
518
+        """
519
+        Return a warning message about this basket line if one is applicable
520
+
521
+        This could be things like the price has changed
522
+        """
523
+        if not self.price_incl_tax:
524
+            return
525
+        current_price_incl_tax = self.product.stockrecord.price_incl_tax
526
+        if current_price_incl_tax > self.price_incl_tax:
527
+            msg = u"The price of '%(product)s' has increased from %(old_price)s " \
528
+                  u"to %(new_price)s since you added it to your basket"
529
+            return _(msg % {'product': self.product.get_title(),
530
+                            'old_price': currency(self.price_incl_tax),
531
+                            'new_price': currency(current_price_incl_tax)})
532
+        if current_price_incl_tax < self.price_incl_tax:
533
+            msg = u"The price of '%(product)s' has decreased from %(old_price)s " \
534
+                  u"to %(new_price)s since you added it to your basket"
535
+            return _(msg % {'product': self.product.get_title(),
536
+                            'old_price': currency(self.price_incl_tax),
537
+                            'new_price': currency(current_price_incl_tax)})
538
+
516 539
 
517 540
 class AbstractLineAttribute(models.Model):
518 541
     """An attribute of a basket line"""

+ 1
- 1
oscar/apps/basket/forms.py Dosyayı Görüntüle

@@ -40,7 +40,7 @@ class BasketLineForm(forms.ModelForm):
40 40
 
41 41
     class Meta:
42 42
         model = Line
43
-        exclude = ('basket', 'product', 'line_reference', )
43
+        exclude = ('basket', 'product', 'line_reference', 'price_incl_tax')
44 44
 
45 45
 
46 46
 class SavedLineForm(forms.ModelForm):

+ 13
- 0
oscar/apps/basket/views.py Dosyayı Görüntüle

@@ -33,6 +33,17 @@ class BasketView(ModelFormSetView):
33 33
     def get_default_shipping_method(self, basket):
34 34
         return Repository().get_default_shipping_method(self.request.user, self.request.basket)
35 35
 
36
+    def get_basket_warnings(self, basket):
37
+        """
38
+        Return a list of warnings that apply to this basket
39
+        """
40
+        warnings = []
41
+        for line in basket.lines.all():
42
+            warning = line.get_warning()
43
+            if warning:
44
+                warnings.append(warning)
45
+        return warnings
46
+
36 47
     def get_context_data(self, **kwargs):
37 48
         context = super(BasketView, self).get_context_data(**kwargs)
38 49
         context['voucher_form'] = BasketVoucherForm()
@@ -40,6 +51,7 @@ class BasketView(ModelFormSetView):
40 51
         context['shipping_method'] = method
41 52
         context['shipping_charge_incl_tax'] = method.basket_charge_incl_tax()
42 53
         context['order_total_incl_tax'] = self.request.basket.total_incl_tax + method.basket_charge_incl_tax()
54
+        context['basket_warnings'] = self.get_basket_warnings(self.request.basket)
43 55
 
44 56
         if self.request.user.is_authenticated():
45 57
             try:
@@ -78,6 +90,7 @@ class BasketView(ModelFormSetView):
78 90
 
79 91
     def formset_invalid(self, formset):
80 92
         messages.info(self.request, _("There was a problem updating your basket, please check that all quantities are numbers"))
93
+        assert False
81 94
         return super(BasketView, self).formset_invalid(formset)
82 95
 
83 96
 

+ 0
- 7
oscar/static/oscar/css/styles.css Dosyayı Görüntüle

@@ -1651,13 +1651,6 @@ button.btn.small, input[type="submit"].btn.small {
1651 1651
   -webkit-border-radius: 4px;
1652 1652
   -moz-border-radius: 4px;
1653 1653
   border-radius: 4px;
1654
-  /*  Position alerts at the bottom of the browser window*/
1655
-
1656
-  position: fixed;
1657
-  bottom: 0;
1658
-  right: 2em;
1659
-  width: 200px;
1660
-  z-index: 9;
1661 1654
 }
1662 1655
 .alert, .alert-heading {
1663 1656
   color: #c09853;

+ 9
- 1
oscar/templates/basket/basket.html Dosyayı Görüntüle

@@ -34,9 +34,17 @@ Basket | {{ block.super }}
34 34
 </div>
35 35
 {% endblock header %}
36 36
 
37
+
37 38
 {% block content %}
38 39
 
39
-{% if request.basket.lines.count %}
40
+{% if basket_warnings %}
41
+	<h5>Important messages about items in your basket</h5>
42
+	{% for warning in basket_warnings %}
43
+	<div class="alert">{{ warning }}</div>
44
+	{% endfor %}
45
+{% endif %}
46
+
47
+{% if not basket.is_empty %}
40 48
 
41 49
 <form action="." method="post" class="basket_summary" id="basket_formset">
42 50
     {% csrf_token %}

+ 3
- 2
oscar/templatetags/currency_filters.py Dosyayı Görüntüle

@@ -20,9 +20,10 @@ def currency(value):
20 20
     symbol = getattr(settings, 'CURRENCY_SYMBOL', None)
21 21
     try:
22 22
         if symbol:
23
-            return "%s%s" % (symbol, locale.format("%.2f", value, grouping=True))
23
+            return u"%s%s" % (symbol, locale.format("%.2f", value, grouping=True))
24 24
         else:
25
-            return locale.currency(value, symbol=True, grouping=True)
25
+            c = locale.currency(value, symbol=True, grouping=True)
26
+            return unicode(c, 'utf8')
26 27
     except TypeError:
27 28
         return '' 
28 29
         

Loading…
İptal
Kaydet