Пример #1
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))
Пример #2
0
def create_order(request,obj):
	"""create new order containing each orderitem instance,save order and empty the order."""
	anon_user = User.objects.get(id=settings.ANONYMOUS_USER_ID)
	resto = Item.objects.get(pk=obj.id)
	orders = Order()

	checkout_form = formz.CheckoutForm(request.POST,instance=orders)
	checkout = checkout_form.save(commit=False)

	checkout.created_by = anon_user
	checkout.modified_by = anon_user
	checkout.restaurant = resto.owner
#	orders.restaurant = Restaurant.objects.get(pk=id)
	checkout.status = Order.SUBMITTED
	checkout.save()

	if checkout.pk:
		"""if the order save suceeded"""
		cart_items = order.get_order_items(request)
		for ci in cart_items:
			"""create online_order for each order_item"""
			oi = RecievedOrder()
			oi.order = checkout
			oi.quantity = ci.quantity
			oi.created_by = anon_user
			oi.modified_by = anon_user
			oi.item = ci.item
			oi.price = ci.price
			oi.option = ci.option
			toppings = ci.toppings_and_extras
			oi.save()
			for topping in toppings.all():
				oi.toppings_and_extras.add(topping)
			#oi.toppings_and_extras.create()
		#empty order cart
		order.empty_cart(request)
	return orders