1. Chris Moffitt
  2. satchmo

Commits

Chris Moffitt  committed 8eb14c0

Modify when cart gets emptied with paypal. Should reduce user confusion with IPN lags. Closes #773

  • Participants
  • Parent commits 4c66ca9
  • Branches default

Comments (0)

Files changed (2)

File satchmo/apps/payment/modules/paypal/urls.py

View file
 urlpatterns = patterns('',
      (r'^$', 'payment.modules.paypal.views.pay_ship_info', {'SSL': ssl}, 'PAYPAL_satchmo_checkout-step2'),
      (r'^confirm/$', 'payment.modules.paypal.views.confirm_info', {'SSL': ssl}, 'PAYPAL_satchmo_checkout-step3'),
-     (r'^success/$', 'payment.views.checkout.success', {'SSL': ssl}, 'PAYPAL_satchmo_checkout-success'),
+     (r'^success/$', 'payment.modules.paypal.views.success', {'SSL': ssl}, 'PAYPAL_satchmo_checkout-success'),
      (r'^ipn/$', 'payment.modules.paypal.views.ipn', {'SSL': ssl}, 'PAYPAL_satchmo_checkout-ipn'),
      (r'^confirmorder/$', 'payment.views.confirm.confirm_free_order',
          {'SSL' : ssl, 'key' : 'PAYPAL'}, 'PAYPAL_satchmo_checkout_free-confirm')

File satchmo/apps/payment/modules/paypal/views.py

View file
 from satchmo_store.shop.models import Order, OrderPayment
 from satchmo_store.contact.models import Contact
 from satchmo_utils.dynamic import lookup_url, lookup_template
+from satchmo_utils.views import bad_or_missing
 from sys import exc_info
 from traceback import format_exception
 import logging
                 for item in order.orderitem_set.filter(product__subscriptionproduct__recurring=True, completed=False):
                     item.completed = True
                     item.save()
-
-            for cart in Cart.objects.filter(customer=order.contact):
-                cart.empty()
+            # We no longer empty the cart here. We do it on checkout success.
 
     except:
         log.exception(''.join(format_exception(*exc_info())))
         return False
 
     return True
+
+
+def success(request):
+    """
+    The order has been succesfully processed.
+    We clear out the cart but let the payment processing get called by IPN
+    """
+    try:
+        order = Order.objects.from_request(request)
+    except Order.DoesNotExist:
+        return bad_or_missing(request, _('Your order has already been processed.'))
+
+    # Added to track total sold for each product
+    for item in order.orderitem_set.all():
+        product = item.product
+        product.total_sold += item.quantity
+        product.items_in_stock -= item.quantity
+        product.save()
+
+    # Clean up cart now, the rest of the order will be cleaned on paypal IPN
+    for cart in Cart.objects.filter(customer=order.contact):
+        cart.empty()
+
+    del request.session['orderID']
+    context = RequestContext(request, {'order': order})
+    return render_to_response('shop/checkout/success.html', context)
+
+success = never_cache(success)