Bladeren bron

Updated the checkout to handle different payment methods

master
David Winterbottom 14 jaren geleden
bovenliggende
commit
30724f27a5

+ 1
- 1
examples/datacash/import.py Bestand weergeven

@@ -35,7 +35,7 @@ django_cursor.execute("TRUNCATE TABLE product_itemattributevalue")
35 35
 django_cursor.execute("TRUNCATE TABLE stock_partner")
36 36
 django_cursor.execute("TRUNCATE TABLE stock_stockrecord")
37 37
 
38
-cursor.execute("SELECT * FROM Brd_ProductsCanonical WHERE Partner = 'Prolog' LIMIT 120")
38
+cursor.execute("SELECT * FROM Brd_ProductsCanonical WHERE Partner = 'Prolog' LIMIT 20")
39 39
 for row in cursor.fetchall():
40 40
     print "Creating canonical product %s" % (row['ProductCode'],)
41 41
     pclass,_ = ItemClass.objects.get_or_create(name=row['MediaType'])

+ 5
- 0
examples/datacash/settings.py Bestand weergeven

@@ -81,10 +81,14 @@ INTERNAL_IPS = ('127.0.0.1',)
81 81
 
82 82
 ROOT_URLCONF = 'urls'
83 83
 
84
+import os
85
+PROJECT_DIR = os.path.dirname(__file__)
86
+
84 87
 TEMPLATE_DIRS = (
85 88
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
86 89
     # Always use forward slashes, even on Windows.
87 90
     # Don't forget to use absolute paths, not relative paths.
91
+    os.path.join(PROJECT_DIR, "templates"),
88 92
 )
89 93
 
90 94
 INSTALLED_APPS = (
@@ -115,6 +119,7 @@ INSTALLED_APPS = (
115 119
 
116 120
 LOGIN_REDIRECT_URL = '/shop/accounts/profile/'
117 121
 APPEND_SLASH = True
122
+DEFAULT_CURRENCY = 'GBP'
118 123
 
119 124
 # Local overrides
120 125
 try:

+ 24
- 17
examples/datacash/shop/checkout/views.py Bestand weergeven

@@ -1,7 +1,9 @@
1 1
 from django.shortcuts import render
2 2
 
3 3
 from oscar.checkout.views import (ShippingMethodView as CoreShippingMethodView, 
4
-                                  PaymentView as CorePaymentView, prev_steps_must_be_complete)
4
+                                  PaymentMethodView as CorePaymentMethodView, 
5
+                                  PaymentDetailsView as CorePaymentDetailsView,
6
+                                  prev_steps_must_be_complete)
5 7
 from oscar.payment.forms import BankcardForm
6 8
 from oscar.services import import_module
7 9
 
@@ -10,30 +12,35 @@ shipping_models = import_module('shipping.models', ['Method'])
10 12
     
11 13
 class ShippingMethodView(CoreShippingMethodView):
12 14
     
13
-    def get_shipping_methods_for_basket(self, basket):
15
+    def get_available_shipping_methods(self):
14 16
         codes = ['royal-mail-first-class']
15 17
         # Only allow parcel force if dropship products are include
16
-        for line in basket.lines.all():
18
+        for line in self.basket.lines.all():
17 19
             if line.product.stockrecord.partner_id == 2:
18 20
                 codes.append('parcel-force')
19 21
         return shipping_models.Method.objects.filter(code__in=codes)
20 22
 
21 23
     
22
-class PaymentView(CorePaymentView):
24
+class PaymentMethodView(CorePaymentMethodView):
25
+    template_file = 'checkout/payment_method.html'
26
+    
27
+    def handle_GET(self):
28
+        return render(self.request, self.template_file, self.context)
29
+    
30
+    def handle_POST(self):
31
+        method = self.request.POST['method_code']
32
+        self.co_data.pay_by(method)
33
+        return self.get_success_response()
23 34
     
24
-    @prev_steps_must_be_complete
25
-    def __call__(self, request):
26
-        
27
-        assert False
28
-        
29
-        # Display credit card form
30
-        form = BankcardForm()
31
-        
32
-        return render(request, 'checkout/payment.html', locals())
33 35
         
34
-    def success(self):
36
+class PaymentDetailsView(CorePaymentMethodView):
37
+    template_file = 'checkout/datacash.html'
38
+    
39
+    def handle_GET(self):
40
+        # Need a billing address form and a bankcard form
35 41
         
36
-        mark_step_as_complete(request)
37
-        return HttpResponseRedirect(reverse(get_next_step(request)))
38 42
         
39
-
43
+        return render(self.request, self.template_file, self.context)
44
+    
45
+    def handle_POST(self):
46
+        assert False

+ 111
- 0
examples/datacash/templates/checkout/datacash.html Bestand weergeven

@@ -0,0 +1,111 @@
1
+{% extends "layout.html" %}
2
+
3
+{% load currency_filters %}
4
+
5
+{% block header %}
6
+<h2>Checkout / Payment details</h2>
7
+{% endblock header %}
8
+
9
+
10
+{% block content %}
11
+
12
+<h3>Shipping address</h3>
13
+<hr />
14
+<table>
15
+    <tr>
16
+        <th>Address</th>
17
+        <td>
18
+            {% for field in shipping_addr.active_address_fields %}
19
+            {{ field }}<br/>
20
+            {% endfor %}
21
+        </td>
22
+    </tr>
23
+    {% if shipping_addr.phone_number %}
24
+    <tr>
25
+        <th>Contact number</th>
26
+        <td>shipping_addr.phone_number</td>
27
+    </tr>
28
+    {% endif %}
29
+    {% if shipping_addr.notes %}
30
+    <tr>
31
+        <th>Shipping notes</th>
32
+        <td>shipping_addr.notes</td>
33
+    </tr>
34
+    {% endif %} 
35
+</table>
36
+<a href="{% url oscar-checkout-shipping-address %}">Change shipping address</a>
37
+
38
+<h3>Shipping method</h3>
39
+<hr />
40
+<table>
41
+    <thead>
42
+        <tr>
43
+            <th>Method</th>
44
+            <th>Cost</th>
45
+            <th>Description</th>
46
+            <th></th>
47
+        </tr>
48
+    <thead>
49
+    <tbody>
50
+        <tr>
51
+            <td>{{ method.name }}</td>
52
+            <td>{{ method.basket_charge_incl_tax|currency }}</td>
53
+            <td>{{ method.description }}</td>
54
+            <td></td>
55
+        </tr>
56
+    </tbody>
57
+</table>
58
+
59
+<h3>Payment</h3>
60
+<hr />
61
+{% if payment_method %}
62
+<p>{{ payment_method }}</p>
63
+{% endif %}
64
+
65
+<h3>Your order</h3>
66
+<hr />
67
+
68
+<table>
69
+    <tr>
70
+        <th>Product</th>
71
+        <th>Availability</th>
72
+        <th>Quantity</th>
73
+        <th>Unit price excl tax</th>
74
+        <th>Unit price tax</th>
75
+        <th>Line price excl tax</th>
76
+        <th>Line price incl tax</th>
77
+    </tr>
78
+    {% for line in basket.lines.all %}
79
+    <tr>
80
+        <td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
81
+        <td>{{ line.product.stockrecord.availability }}</td>
82
+        <td>{{ line.quantity }}</td>
83
+        <td>{{ line.unit_price_excl_tax|currency }}</td>
84
+        <td>{{ line.unit_tax|currency }}</td>
85
+        <td>{{ line.line_price_excl_tax|currency }}</td>
86
+        <td>{{ line.line_price_incl_tax|currency }}</td>
87
+    </tr>
88
+    {% endfor %}
89
+    <tr>
90
+        <td colspan="5">Total</td>
91
+        <td>{{ basket.total_excl_tax|currency }}</td>
92
+        <td>{{ basket.total_incl_tax|currency }}</td>
93
+    </tr>
94
+    <tr>
95
+        <td colspan="5">Shipping charge</td>
96
+        <td></td>
97
+        <td></td>
98
+    </tr>
99
+    <tr>
100
+        <td colspan="6">Order total</td>
101
+        <td>{{ order_total|currency }}</td>
102
+    </tr>
103
+</table>
104
+
105
+<h3>Payment details</h3>
106
+
107
+asdfjaklsdjfkl;
108
+
109
+
110
+{% endblock content %}
111
+

+ 133
- 0
examples/datacash/templates/checkout/payment_method.html Bestand weergeven

@@ -0,0 +1,133 @@
1
+{% extends "layout.html" %}
2
+
3
+{% load currency_filters %}
4
+
5
+{% block header %}
6
+<h2>Checkout / Payment Methods</h2>
7
+{% endblock header %}
8
+
9
+
10
+{% block content %}
11
+
12
+<h3>Shipping address</h3>
13
+<hr />
14
+<table>
15
+    <tr>
16
+        <th>Address</th>
17
+        <td>
18
+            {% for field in shipping_addr.active_address_fields %}
19
+            {{ field }}<br/>
20
+            {% endfor %}
21
+        </td>
22
+    </tr>
23
+    {% if shipping_addr.phone_number %}
24
+    <tr>
25
+        <th>Contact number</th>
26
+        <td>shipping_addr.phone_number</td>
27
+    </tr>
28
+    {% endif %}
29
+    {% if shipping_addr.notes %}
30
+    <tr>
31
+        <th>Shipping notes</th>
32
+        <td>shipping_addr.notes</td>
33
+    </tr>
34
+    {% endif %} 
35
+</table>
36
+<a href="{% url oscar-checkout-shipping-address %}">Change shipping address</a>
37
+
38
+<h3>Shipping method</h3>
39
+<hr />
40
+<table>
41
+    <thead>
42
+        <tr>
43
+            <th>Method</th>
44
+            <th>Cost</th>
45
+            <th>Description</th>
46
+            <th></th>
47
+        </tr>
48
+    <thead>
49
+    <tbody>
50
+        <tr>
51
+            <td>{{ method.name }}</td>
52
+            <td>{{ method.basket_charge_incl_tax|currency }}</td>
53
+            <td>{{ method.description }}</td>
54
+            <td></td>
55
+        </tr>
56
+    </tbody>
57
+</table>
58
+
59
+<h3>Payment</h3>
60
+<hr />
61
+<table>
62
+    <thead>
63
+        <tr>
64
+            <th>Method</th>
65
+            <th></th>
66
+        </tr>
67
+    <thead>
68
+    <tbody>
69
+        <tr>
70
+            <td>Cheque</td>
71
+            <td>
72
+                <form method="post" action="{% url oscar-checkout-payment-method %}">
73
+                    {% csrf_token %}
74
+                    <input type="hidden" name="method_code" value="cheque" />
75
+                    <input type="submit" value="Pay by cheque" />
76
+                </form>
77
+            </td>
78
+        </tr>
79
+        <tr>
80
+            <td>Bankcard</td>
81
+            <td>
82
+                <form method="post" action="{% url oscar-checkout-payment-method %}">
83
+                    {% csrf_token %}
84
+                    <input type="hidden" name="method_code" value="bankcard" />
85
+                    <input type="submit" value="Pay by bankcard" />
86
+                </form>
87
+            </td>
88
+        </tr>
89
+    </tbody>
90
+</table>
91
+
92
+<h3>Your order</h3>
93
+<hr />
94
+
95
+<table>
96
+    <tr>
97
+        <th>Product</th>
98
+        <th>Availability</th>
99
+        <th>Quantity</th>
100
+        <th>Unit price excl tax</th>
101
+        <th>Unit price tax</th>
102
+        <th>Line price excl tax</th>
103
+        <th>Line price incl tax</th>
104
+    </tr>
105
+    {% for line in basket.lines.all %}
106
+    <tr>
107
+        <td><a href="{{ line.product.get_absolute_url }}">{{ line.description }}</a></td>
108
+        <td>{{ line.product.stockrecord.availability }}</td>
109
+        <td>{{ line.quantity }}</td>
110
+        <td>{{ line.unit_price_excl_tax|currency }}</td>
111
+        <td>{{ line.unit_tax|currency }}</td>
112
+        <td>{{ line.line_price_excl_tax|currency }}</td>
113
+        <td>{{ line.line_price_incl_tax|currency }}</td>
114
+    </tr>
115
+    {% endfor %}
116
+    <tr>
117
+        <td colspan="5">Total</td>
118
+        <td>{{ basket.total_excl_tax|currency }}</td>
119
+        <td>{{ basket.total_incl_tax|currency }}</td>
120
+    </tr>
121
+    <tr>
122
+        <td colspan="5">Shipping charge</td>
123
+        <td></td>
124
+        <td></td>
125
+    </tr>
126
+    <tr>
127
+        <td colspan="6">Order total</td>
128
+        <td>{{ order_total|currency }}</td>
129
+    </tr>
130
+</table>
131
+
132
+{% endblock content %}
133
+

+ 9
- 0
oscar/checkout/utils.py Bestand weergeven

@@ -143,3 +143,12 @@ class CheckoutSessionData(object):
143 143
             return None
144 144
         repo = shipping_methods.Repository()
145 145
         return repo.find_by_code(code)
146
+    
147
+    # Payment methods
148
+    
149
+    def pay_by(self, method):
150
+        self._set('payment', 'method', method)
151
+        
152
+    def payment_method(self):
153
+        return self._get('payment', 'method')
154
+        

+ 9
- 3
oscar/checkout/views.py Bestand weergeven

@@ -81,10 +81,13 @@ class CheckoutView(object):
81 81
         self.request = request
82 82
         self.co_data = checkout_utils.CheckoutSessionData(request)
83 83
         self.basket = basket_factory.BasketFactory().get_open_basket(self.request)
84
+        
85
+        # Set up template context that is available to every view
84 86
         self.context = {'basket': self.basket,
85 87
                         'order_total': self.get_order_total(),
86 88
                         'shipping_addr': self.get_shipping_address()}
87 89
         self.set_shipping_context()
90
+        self.set_payment_context()
88 91
         
89 92
         if request.method == 'POST':
90 93
             response = self.handle_POST()
@@ -101,6 +104,11 @@ class CheckoutView(object):
101 104
             self.context['method'] = method
102 105
             self.context['shipping_total_excl_tax'] = method.basket_charge_excl_tax()
103 106
             self.context['shipping_total_incl_tax'] = method.basket_charge_incl_tax()
107
+            
108
+    def set_payment_context(self):
109
+        method = self.co_data.payment_method()
110
+        if method:
111
+            self.context['payment_method'] = method
104 112
     
105 113
     def handle_GET(self):
106 114
         u"""
@@ -212,8 +220,7 @@ class ShippingMethodView(CheckoutView):
212 220
     def handle_POST(self):
213 221
         method_code = self.request.POST['method_code']
214 222
         self.co_data.use_shipping_method(method_code)
215
-        mark_step_as_complete(self.request)
216
-        return HttpResponseRedirect(reverse(get_next_step(self.request)))
223
+        return self.get_success_response()
217 224
         
218 225
 
219 226
 class PaymentMethodView(CheckoutView):
@@ -232,7 +239,6 @@ class OrderPreviewView(CheckoutView):
232 239
     template_file = 'checkout/preview.html'
233 240
     
234 241
     def handle_GET(self):
235
-        
236 242
         mark_step_as_complete(self.request)
237 243
         return render(self.request, self.template_file, self.context)
238 244
 

+ 3
- 0
oscar/templates/checkout/preview.html Bestand weergeven

@@ -57,6 +57,9 @@
57 57
 
58 58
 <h3>Payment</h3>
59 59
 <hr />
60
+{% if payment_method %}
61
+<p>{{ payment_method }}</p>
62
+{% endif %}
60 63
 
61 64
 <h3>Your order</h3>
62 65
 <hr />

+ 1
- 0
oscar/templates/checkout/shipping_methods.html Bestand weergeven

@@ -59,6 +59,7 @@
59 59
                     <input type="submit" value="Use this shipping method" />
60 60
                 </form>
61 61
             </td>
62
+        </tr>
62 63
         {% endfor %}
63 64
     </tbody>
64 65
 </table>

Laden…
Annuleren
Opslaan