def show_checkout(request, template_name = 'checkout/checkout.html'): categories = categoryList if cart.is_empty(request): cart_url = urlresolvers.reverse('show_cart') return HttpResponseRedirect(cart_url) if request.method =='POST': postdata = request.POST.copy() form = CheckoutForm(postdata) if form.is_valid(): response = checkout.process(request) order_number = response.get('order_number', 0) error_message = response.get('message', 0) if order_number: request.session['order_number'] = order_number receipt_url = urlresolvers.reverse('checkout_receipt') return HttpResponseRedirect(receipt_url) else: error_message = 'Correct the errors below.' else: form = CheckoutForm() page_title = 'Checkout' return render_to_response(template_name, locals(), context_instance = RequestContext(request))
def create_order(request, transaction_id): order = Order() checkout_form = CheckoutForm(request.POST, instance = order) order = checkout_form.save(commit = False) order.transaction_id = transaction_id order.ip_address = request.META.get('REMOTE_ADDR') order.user = None order.status = Order.SUBMITTED order.save() if order.pk: cart_items = cart.get_cart_items(request) for ci in cart_items: oi = OrderItem() oi.order = order oi.quantity = ci.quantity oi.price = ci.price oi.product = ci.product oi.save() cart.empty_cart(request) return order