示例#1
0
def order(request):
    cart = Cart(request)

    if request.method == 'POST' and request.is_ajax():
        name = request.POST['name']
        phone = request.POST['phone']
        order = Order(name=name,
                      phone_number=phone,
                      total=Decimal(cart.total_price))
        order.save()
        for item in cart.items_list:
            item_id = item['product_id']
            item_quantity = item['quantity']
            item = Products.objects.get(id=item_id)
            order_item = OrderItem(product=item,
                                   quantity=item_quantity,
                                   order=order)
            order_item.save()

        cart.clean_cart()

        return HttpResponse('')
    else:
        return Http404
示例#2
0
def clean_cart(request):
    cart = Cart(request)
    cart.clean_cart()
    return HttpResponse('')