Beispiel #1
0
def make_order_view(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)
    form = OrdForm(request.POST or None)
    categories = Category.objects.all()
    if form.is_valid():
        name = form.cleaned_data['name']
        last_name = form.cleaned_data['last_name']
        phone = form.cleaned_data['phone']
        buying_type = form.cleaned_data['buying_type']
        address = form.cleaned_data['address']
        comments = form.cleaned_data['comments']
        new_order = Ord.objects.create(user=request.user,
                                       items=cart,
                                       total=cart.cart_total,
                                       first_name=name,
                                       last_name=last_name,
                                       phone=phone,
                                       address=address,
                                       buying_type=buying_type,
                                       comments=comments)
        request.session['total'] = cart.items.count()
        del request.session['cart_id']
        del request.session['total']
        return render(request, 'thank_you.html', {'categories': categories})
    return render(request, 'ord.html', {'categories': categories})
Beispiel #2
0
def checkout_view(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)
    categories = Category.objects.all()
    context = {'cart': cart, 'categories': categories}
    return render(request, 'checkout.html', context)
Beispiel #3
0
def order_create_view(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)
    categories = Category.objects.all()
    form = OrdForm(request.POST or None)
    context = {'form': form, 'cart': cart, 'categories': categories}
    return render(request, 'ord.html', context)
Beispiel #4
0
def order_view(request, order_slug):
    # cart = Cart.objects.first()
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)

    order = Order.objects.get(slug=order_slug)
    categories = Category.objects.all()
    context = {
        'order': order,
        'categories': categories,
        'cart': cart,
    }
    return render(request, 'order.html', context)
Beispiel #5
0
def change_item_qty(request):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)
    #qty = request.GET.get('qty')
    item_id = request.GET.get('item_id')
    cart_item = CartItem.objects.get(id=int(item_id))
    cart.change_qty(item_id)
    #cart.change_qty(qty, item_id)
    return JsonResponse({
        'cart_total': cart.items.count(),
        'item_total': cart_item.order.price,
        'cart_total_price': cart.cart_total
    })
Beispiel #6
0
def add_to_cart_view(request):  #, order_slug):
    try:
        cart_id = request.session['cart_id']
        cart = Cart.objects.get(id=cart_id)
        request.session['total'] = cart.items.count()
    except:
        cart = Cart()
        cart.save()
        cart_id = cart.id
        request.session['cart_id'] = cart_id
        cart = Cart.objects.get(id=cart_id)

    order_slug = request.GET.get('order_slug')
    order = Order.objects.get(slug=order_slug)
    cart.add_to_cart(order.slug)
    new_cart_total = 0.00
    for item in cart.items.all():
        new_cart_total += float(item.order.price)
    cart.cart_total = new_cart_total
    cart.save()
    return JsonResponse({
        'cart_total': cart.items.count(),
        'cart_total_price': cart.cart_total
    })