Esempio n. 1
0
def show_checkout(request,id):
	"""checkout form to collect order information and send email notification"""
	item = Item.objects.get(pk=id)
	total = order.order_subtotal(request) + item.owner.service_fee
	if total < item.owner.minimum_order_amount:
		cart_url = urlresolvers.reverse('order_index',kwargs={'id':item.id})
		# redirect if total is less than minimum order amount
		return HttpResponseRedirect(cart_url)
	if request.method == 'POST':
		postdata = request.POST.copy()
		form = formz.CheckoutForm(request.POST,postdata)
		#validate check out form
		if form.is_valid():
			#current order
			order_created = create_order(request,item)
			#current order id
			order_number = order_created.id
			# if order in cart
			if order_number:
				#session for this order
				request.session['order_number'] = order_number
			if postdata['submit'] == 'complete order':
				#send email notification of incoming order
				recipients = ['*****@*****.**']
				order_resto = item.owner.restaurant_name
				title = 'Order Recieved, for %s' % order_resto
				name = form.cleaned_data['name']
				send_mail(title,name,order_resto,recipients)
				reciept_url = urlresolvers.reverse('checkout_reciept')
				# redirect at this point to reciept page.
				return HttpResponseRedirect(reciept_url)
		else:
			order_created = None
	else:
		form = formz.CheckoutForm
	order_subtotal = order.order_subtotal(request)
	total = order_subtotal + item.owner.service_fee # Access the order total
	context = {
		'total':total,
		'form':form,

	}
	return render(request,'checkout/checkout.html',context)
Esempio n. 2
0
def show_order(request,id):
	item = Item.objects.get(pk=id)
#	option = OptionalItem.objects.get(pk=id)
	if request.method == 'POST':
		postdata = request.POST.copy()
		if postdata['submit'] == 'Remove order':
			order.remove_from_order(request)
		if postdata['submit'] == 'Update quantity':
			order.update_order(request)
		if postdata['submit'] == 'Checkout':
#			checkout_url = show_checkout(request)
			return HttpResponseRedirect(urlresolvers.reverse('checkout',kwargs={'id':item.id}))
	order_items = order.get_order_items(request)
	order_subtotal = order.order_subtotal(request)
	total = order_subtotal + item.owner.service_fee

	context = {
		'order_items':order_items,
		'order_subtotal':order_subtotal,
		'item': item,
		'total': total,
	}
	return render_to_response('public/order.html',context,context_instance=RequestContext(request))