Browse Source

Updated checkout to have order placement with payment details

master
David Winterbottom 15 years ago
parent
commit
809fa2fdf6

+ 7
- 17
examples/datacash/shop/checkout/views.py View File

@@ -4,7 +4,6 @@ from oscar.checkout.views import (ShippingMethodView as CoreShippingMethodView,
4 4
                                   PaymentMethodView as CorePaymentMethodView, 
5 5
                                   PaymentDetailsView as CorePaymentDetailsView,
6 6
                                   OrderPreviewView as CoreOrderPreviewView,
7
-                                  SubmitView as CoreSubmitView,
8 7
                                   prev_steps_must_be_complete)
9 8
 from oscar.payment.forms import BankcardForm, BillingAddressForm
10 9
 from oscar.services import import_module
@@ -46,25 +45,16 @@ class PaymentDetailsView(CorePaymentMethodView):
46 45
     template_file = 'checkout/payment_details.html'
47 46
     
48 47
     def handle_GET(self):
49
-        
50
-        # Need a billing address form and a bankcard form
51 48
         self.context['bankcard_form'] = BankcardForm()
52 49
         self.context['billing_address_form'] = BillingAddressForm()
53
-        
54 50
         return render(self.request, self.template_file, self.context)
55 51
     
56 52
     def handle_POST(self):
57
-        assert False
58
-        
59
-
60
-class SubmitView(CoreSubmitView):
61
-    
62
-    def _handle_payment(self, basket):
63
-        u"""Handle any payment processing"""
53
+        bankcard_form = BankcardForm(self.request.POST)
54
+        billing_addr_form = BillingAddressForm(self.request.POST)
55
+        if bankcard_form.is_valid() and billing_addr_form.is_valid():
56
+            return self._submit()
57
+        self.context['bankcard_form'] = bankcard_form
58
+        self.context['billing_address_form'] = billing_addr_form
59
+        return render(self.request, self.template_file, self.context)
64 60
         
65
-        bankcard_form = BankcardForm(request.POST)
66
-        if not bankcard_form.is_valid():
67
-            # Put form into the session and redirect back 
68
-            self.request.session['bankcard_form'] = bankcard_form
69
-            
70
-        assert False

+ 1
- 2
oscar/checkout/urls.py View File

@@ -3,7 +3,7 @@ from django.conf.urls.defaults import *
3 3
 from oscar.views import class_based_view
4 4
 from oscar.services import import_module
5 5
 
6
-checkout_views = import_module('checkout.views', ['IndexView', 'ShippingAddressView', 'SubmitView',
6
+checkout_views = import_module('checkout.views', ['IndexView', 'ShippingAddressView',
7 7
                                                   'ShippingMethodView', 'PaymentMethodView', 'OrderPreviewView',
8 8
                                                   'PaymentDetailsView', 'ThankYouView'])
9 9
 
@@ -14,7 +14,6 @@ urlpatterns = patterns('oscar.checkout.views',
14 14
     url(r'payment-method/$', class_based_view(checkout_views.PaymentMethodView), name='oscar-checkout-payment-method'),
15 15
     url(r'preview/$', class_based_view(checkout_views.OrderPreviewView), name='oscar-checkout-preview'),
16 16
     url(r'payment-details/$', class_based_view(checkout_views.PaymentDetailsView), name='oscar-checkout-payment-details'),
17
-    url(r'submit/$', class_based_view(checkout_views.SubmitView), name='oscar-checkout-submit'),
18 17
     url(r'thank-you/$', class_based_view(checkout_views.ThankYouView), name='oscar-checkout-thank-you'),
19 18
 )
20 19
 

+ 1
- 2
oscar/checkout/utils.py View File

@@ -16,8 +16,7 @@ class ProgressChecker(object):
16 16
                       'oscar-checkout-shipping-method',
17 17
                       'oscar-checkout-payment-method',
18 18
                       'oscar-checkout-preview',
19
-                      'oscar-checkout-payment-details',
20
-                      'oscar-checkout-submit',]
19
+                      'oscar-checkout-payment-details']
21 20
     
22 21
     def are_previous_steps_complete(self, request):
23 22
         u"""

+ 8
- 17
oscar/checkout/views.py View File

@@ -246,32 +246,23 @@ class OrderPreviewView(CheckoutView):
246 246
 
247 247
 class PaymentDetailsView(CheckoutView):
248 248
     u"""
249
-    For taking the details of payment.
250
-    
251
-    This has to be the final step before submit as we don't want to store
252
-    payment details in the session.
253
-    """
254
-    pass
255
-
256
-
257
-class SubmitView(CheckoutView):
258
-    u"""
259
-    Class for submitting an order.
249
+    For taking the details of payment and creating the order
260 250
     
261 251
     The class is deliberately split into fine-grained method, responsible for only one
262 252
     thing.  This is to make it easier to subclass and override just one component of
263 253
     functionality.
264
-    
265
-    Note that the order models support shipping to multiple addresses but the default
266
-    implementation assumes only one.  To change this, override the _get_shipping_address_for_line
267
-    method.
268 254
     """
269
-    
270 255
     def handle_GET(self):
271 256
         return self.handle_POST()
272 257
     
273 258
     def handle_POST(self):
274
-        
259
+        """
260
+        This method is designed to be overridden by subclasses which will
261
+        validate the forms from the payment details page.  If the forms are valid
262
+        then the method can call _submit()."""
263
+        return self._submit()
264
+    
265
+    def _submit(self):
275 266
         checkout_signals.pre_payment.send_robust(sender=self, view=self)
276 267
         self._handle_payment(self.basket)
277 268
         checkout_signals.post_payment.send_robust(sender=self, view=self)

+ 4
- 1
oscar/templates/checkout/preview.html View File

@@ -3,6 +3,9 @@
3 3
 {% block place_order %}
4 4
 <hr/>
5 5
 <h3>Place your order</h3>
6
-<a href="{% url oscar-checkout-payment-details %}">Place order</a>
6
+<form method="post" action="{% url oscar-checkout-payment-details %}">
7
+{% csrf_token %}
8
+<input type="submit" value="Place order" />
9
+</form>
7 10
 {% endblock place_order %}
8 11
 

Loading…
Cancel
Save