Sfoglia il codice sorgente

Added estimated shipping charge to basket summary page.

Looks up all shipping methods for a basket and picks the first one to
form the estimate.
master
David Winterbottom 13 anni fa
parent
commit
e029e1ab24

+ 28
- 6
oscar/apps/basket/tests.py Vedi File

@@ -1,4 +1,5 @@
1 1
 from decimal import Decimal as D
2
+import httplib
2 3
 
3 4
 from django.conf import settings
4 5
 from django.core.urlresolvers import reverse
@@ -35,12 +36,6 @@ class BasketModelTest(TestCase):
35 36
 
36 37
 class BasketViewsTest(TestCase):
37 38
 
38
-    def test_empty_basket_view(self):
39
-        url = reverse('basket:summary')
40
-        response = self.client.get(url)
41
-        self.assertEquals(200, response.status_code)
42
-        self.assertEquals(0, response.context['basket'].num_lines)
43
-
44 39
     def test_anonymous_add_to_basket_creates_cookie(self):
45 40
         dummy_product = create_product(price=D('10.00'))
46 41
         url = reverse('basket:add')
@@ -51,6 +46,33 @@ class BasketViewsTest(TestCase):
51 46
         self.assertTrue('oscar_open_basket' in response.cookies)
52 47
 
53 48
 
49
+class BasketSummaryViewTests(TestCase):
50
+
51
+    def setUp(self):
52
+        url = reverse('basket:summary')
53
+        self.response = self.client.get(url)
54
+
55
+    def test_shipping_method_in_context(self):
56
+        self.assertTrue('shipping_method' in self.response.context)
57
+
58
+    def test_shipping_charge_in_context(self):
59
+        self.assertTrue('shipping_charge_incl_tax' in self.response.context)
60
+
61
+    def test_order_total_in_context(self):
62
+        self.assertTrue('order_total_incl_tax' in self.response.context)
63
+
64
+    def test_view_does_not_error(self):
65
+        self.assertEquals(httplib.OK, self.response.status_code)
66
+
67
+    def test_basket_in_context(self):
68
+        self.assertTrue('basket' in self.response.context)
69
+
70
+    def test_basket_is_empty(self):
71
+        basket = self.response.context['basket']
72
+        self.assertEquals(0, basket.num_lines)
73
+
74
+
75
+
54 76
 class BasketThresholdTest(TestCase):
55 77
 
56 78
     def setUp(self):

+ 8
- 0
oscar/apps/basket/views.py Vedi File

@@ -16,6 +16,7 @@ BasketLineForm, AddToBasketForm, BasketVoucherForm, \
16 16
             'basket.forms', ('BasketLineForm', 'AddToBasketForm',
17 17
                              'BasketVoucherForm', 'SavedLineForm',
18 18
                              'ProductSelectionForm'))
19
+Repository = get_class('shipping.repository', ('Repository'))
19 20
 
20 21
 
21 22
 class BasketView(ModelFormSetView):
@@ -29,9 +30,16 @@ class BasketView(ModelFormSetView):
29 30
     def get_queryset(self):
30 31
         return self.request.basket.lines.all()
31 32
 
33
+    def get_default_shipping_method(self, basket):
34
+        return Repository().get_default_shipping_method(self.request.user, self.request.basket)
35
+
32 36
     def get_context_data(self, **kwargs):
33 37
         context = super(BasketView, self).get_context_data(**kwargs)
34 38
         context['voucher_form'] = BasketVoucherForm()
39
+        method = self.get_default_shipping_method(self.request.basket)
40
+        context['shipping_method'] = method
41
+        context['shipping_charge_incl_tax'] = method.basket_charge_incl_tax()
42
+        context['order_total_incl_tax'] = self.request.basket.total_incl_tax + method.basket_charge_incl_tax()
35 43
 
36 44
         if self.request.user.is_authenticated():
37 45
             try:

+ 3
- 0
oscar/apps/shipping/repository.py Vedi File

@@ -19,6 +19,9 @@ class Repository(object):
19 19
         methods = [Free()]
20 20
         return self.add_basket_to_methods(basket, methods)
21 21
 
22
+    def get_default_shipping_method(self, user, basket, shipping_addr=None, **kwargs):
23
+        return self.get_shipping_methods(user, basket, shipping_addr, **kwargs)[0]
24
+
22 25
     def add_basket_to_methods(self, basket, methods):
23 26
         for method in methods:
24 27
             method.set_basket(basket)

+ 12
- 4
oscar/templates/basket/basket.html Vedi File

@@ -49,7 +49,7 @@ Basket | {{ block.super }}
49 49
             <th>Availability</th>
50 50
             <th>Quantity</th>
51 51
             <th>Unit price</th>
52
-            <th>Line price</th>
52
+            <th>Subtotal</th>
53 53
 			{% if request.user.is_authenticated %}
54 54
             <th>Save for later&hellip;</th>
55 55
 			{% endif %}
@@ -82,10 +82,18 @@ Basket | {{ block.super }}
82 82
         </tr>
83 83
         {% endfor %}
84 84
         <tr>
85
-            <th colspan="4">Subtotal</th>
86
-            <td>{{ request.basket.total_excl_tax|currency }}</td>
85
+            <th colspan="5">Basket total</th>
87 86
             <td>{{ basket.total_incl_tax|currency }}</td>
88 87
 			<td></td>
88
+        </tr>
89
+        <tr>
90
+			<th colspan="5">Estimated shipping ({{ shipping_method.name }})</th>
91
+            <td>{{ shipping_charge_incl_tax|currency }}</td>
92
+			<td></td>
93
+        </tr>
94
+        <tr>
95
+            <th colspan="5">Order total</th>
96
+            <td>{{ order_total_incl_tax|currency }}</td>
89 97
 			<td></td>
90 98
         </tr>
91 99
         </tbody>
@@ -155,7 +163,7 @@ Basket | {{ block.super }}
155 163
 
156 164
     <div class="form-actions">
157 165
         Made changes? <input type="submit" value="Update basket" class="btn"/>
158
-        <a href="{% url checkout:index %}" class="pull-right btn btn-primary">Proceed to Checkout</a>
166
+        <a href="{% url checkout:index %}" class="pull-right btn btn-large btn-primary">Proceed to checkout</a>
159 167
     </div>
160 168
 
161 169
 </form>

+ 6
- 4
run_tests.py Vedi File

@@ -12,8 +12,8 @@ from django.test.simple import DjangoTestSuiteRunner
12 12
 logging.disable(logging.CRITICAL)
13 13
 
14 14
 
15
-def run_tests(*test_args):
16
-    test_runner = DjangoTestSuiteRunner(verbosity=1)
15
+def run_tests(verbosity, *test_args):
16
+    test_runner = DjangoTestSuiteRunner(verbosity=verbosity)
17 17
     if not test_args:
18 18
         test_args = ['oscar']
19 19
     num_failures = test_runner.run_tests(test_args)
@@ -24,16 +24,18 @@ if __name__ == '__main__':
24 24
     parser = OptionParser()
25 25
     parser.add_option('-c', '--coverage', dest='use_coverage', default=False,
26 26
                       action='store_true', help="Generate coverage report")
27
+    parser.add_option('-v', '--verbosity', dest='verbosity', default=1,
28
+                      type='int', help="Verbosity of output")
27 29
     (options, args) = parser.parse_args()
28 30
 
29 31
     if options.use_coverage:
30 32
         print 'Running tests with coverage'
31 33
         c = coverage(source=['oscar'])
32 34
         c.start()
33
-        run_tests(*args)
35
+        run_tests(options.verbosity, *args)
34 36
         c.stop()
35 37
         print 'Generate HTML reports'
36 38
         c.html_report()
37 39
     else:
38 40
         print 'Running tests'
39
-        run_tests(*args)
41
+        run_tests(options.verbosity, *args)

Loading…
Annulla
Salva