Esempio n. 1
0
def ajax_delivery(request):

    cart_id = cart.set_cart_id(request)
    cart_items = CartItem.objects.filter(cart_id=cart_id)
    region = cart.set_region(request)
    weight = 0
    cart_info = CartInfoHelper()
    cart_info.cart_id = cart_id
    for item in cart_items:
        weight = weight + item.parametr.weight * item.count

    cart_info.delivery_price = delivery.calculate_delivery(weight, region)
    cart_info.get_total_price()

    try:
        delivery_item = Delivery.objects.get(cart_id=cart_id)
        delivery_item.city = region
        delivery_item.price = cart_info.delivery_price
        delivery_item.save()
    except:
        delivery_item = Delivery()
        delivery_item.city = region
        delivery_item.price = cart_info.delivery_price
        delivery_item.cart_id = cart_id
        delivery_item.save()

    data = json.dumps({
        "region": region,
        "delivery_price": cart_info.delivery_price,
        "item_price": cart_info.item_price,
        "total_price": cart_info.total_price,
        })
    return HttpResponse(data, content_type="application/json")
Esempio n. 2
0
def ajax_delivery(request):

    cart_id = cart.set_cart_id(request)
    cart_items = CartItem.objects.filter(cart_id=cart_id)
    region = cart.set_region(request)
    weight = 0
    cart_info = CartInfoHelper()
    cart_info.cart_id = cart_id
    for item in cart_items:
        weight = weight + item.parametr.weight * item.count

    cart_info.delivery_price = delivery.calculate_delivery(weight, region)
    cart_info.get_total_price()

    try:
        delivery_item = Delivery.objects.get(cart_id=cart_id)
        delivery_item.city = region
        delivery_item.price = cart_info.delivery_price
        delivery_item.save()
    except:
        delivery_item = Delivery()
        delivery_item.city = region
        delivery_item.price = cart_info.delivery_price
        delivery_item.cart_id = cart_id
        delivery_item.save()

    data = json.dumps({
        "region": region,
        "delivery_price": cart_info.delivery_price,
        "item_price": cart_info.item_price,
        "total_price": cart_info.total_price,
    })
    return HttpResponse(data, content_type="application/json")
Esempio n. 3
0
def top_menu(context, request):

    cart_info = CartInfoHelper()
    cart_info.cart_id = cart.set_cart_id(request)
    cart_info.cart_total_price_helper()

    # cart_ifo = cart_info

    return {'user': request.user, 'request': request, 'cart_info': cart_info}
Esempio n. 4
0
def top_menu(context, request):

    cart_info = CartInfoHelper()
    cart_info.cart_id = cart.set_cart_id(request)
    cart_info.cart_total_price_helper()

    # cart_ifo = cart_info

    return {
        'user': request.user,
        'request': request,
        'cart_info': cart_info
    }
Esempio n. 5
0
def add_to_cart(request):
    id = request.POST['id']
    product = Product.objects.get(id=id)
    cart_id = cart.set_cart_id(request)

    try:
        tmp_item = CartItem.objects.get(cart_id=cart_id, product=product)
        tmp_item.count += int(request.POST['count'])
        tmp_item.save()
    except:
        cartItem = CartItem()
        cartItem.product = product
        cartItem.count = request.POST['count']
        cartItem.cart_id = cart_id
        cartItem.save()
Esempio n. 6
0
def add_to_cart(request):
    id = request.POST['id']
    product = Product.objects.get(id=id)
    cart_id = cart.set_cart_id(request)
    parametr_price = request.POST['parametr_price']
    parametr = ProductParametr.objects.get(product=product, price=parametr_price)

    try:
        tmp_item = CartItem.objects.get(cart_id=cart_id, product=product, parametr=parametr)
        tmp_item.count += int(request.POST['count'])
        tmp_item.save()
    except:
        cartItem = CartItem()
        cartItem.parametr = parametr
        cartItem.product = product
        cartItem.count = request.POST['count']
        cartItem.cart_id = cart_id
        cartItem.save()
Esempio n. 7
0
def add_to_cart(request):
    id = request.POST['id']
    product = Product.objects.get(id=id)
    cart_id = cart.set_cart_id(request)
    parametr_price = request.POST['parametr_price']
    parametr = ProductParametr.objects.get(product=product,
                                           price=parametr_price)

    try:
        tmp_item = CartItem.objects.get(cart_id=cart_id,
                                        product=product,
                                        parametr=parametr)
        tmp_item.count += int(request.POST['count'])
        tmp_item.save()
    except:
        cartItem = CartItem()
        cartItem.parametr = parametr
        cartItem.product = product
        cartItem.count = request.POST['count']
        cartItem.cart_id = cart_id
        cartItem.save()
Esempio n. 8
0
def cart_menu(context, request):
    cart_info = CartInfoHelper()
    cart_info.cart_id = cart.set_cart_id(request)
    cart_info.cart_total_price_helper()

    return {'cart_info': cart_info}
Esempio n. 9
0
def cart_menu(context, request):
    cart_info = CartInfoHelper()
    cart_info.cart_id = cart.set_cart_id(request)
    cart_info.cart_total_price_helper()

    return {'cart_info': cart_info}
Esempio n. 10
0
def cart_view(request, template_name="cart/cart.html"):

    cart_id = cart.set_cart_id(request)
    region = cart.get_region(request)

    user = request.user
    form = AccountForm()
    delivery_form = DeliveryForm()

    if user.is_authenticated():
        if region == 'МОСКВА':
            initial_region = user.city
        else:
            initial_region = region
        data = {
            'first_name': user.first_name,
            'last_name': user.last_name,
            'zip': user.zip,
            'city': initial_region,
            'address': user.address,
            'phone': user.phone
        }
        pureForm = PureAccountForm(initial=data)

    cart_items = CartItem.objects.filter(cart_id=cart_id)

    cart_info = CartInfoHelper()
    cart_info.cart_id = cart_id

    if request.method == 'POST' and "checkout" in request.POST:
        if user.is_authenticated():
            postdata = request.POST.copy()
            pureForm = PureAccountForm(postdata)

            if pureForm.is_valid():
                user.first_name = request.POST['first_name']
                user.last_name = request.POST['last_name']
                user.zip = request.POST['zip']
                user.city = request.POST['city']
                user.address = request.POST['address']
                user.phone = request.POST['phone']
                user.save()

        else:
            postdata = request.POST.copy()
            form = AccountForm(postdata)

            if form.is_valid():
                email = request.POST['email']
                password = request.POST['password']
                username = request.POST['username']
                user = Account.objects.create_user(email, password=password, username=username)
                login(request, user)
                user.first_name = request.POST['first_name']
                user.last_name = request.POST['last_name']
                user.zip = request.POST['zip']
                user.city = request.POST['city']
                user.address = request.POST['address']
                user.phone = request.POST['phone']
                user.save()

        order = Order()
        order.user = get_user(request)
        order.cart_id = cart_id
        order.save()

        url = '/confirmation?cart_id=%s' % request.session['cart_id']
        cart.del_session_cart_id(request)

        return HttpResponseRedirect(url)

    elif request.method == "POST" and "delete" in request.POST:
        tmp_id = request.POST['id']
        tmp_item = CartItem.objects.get(id=tmp_id)
        tmp_item.delete()

    elif request.method == "POST" and "change_count" in request.POST:
        id = int(request.POST['id'])
        tmp_count = request.POST['count']
        tmp_item = CartItem.objects.get(id=id)
        tmp_item.count = tmp_count
        tmp_item.save()

    # elif request.method == "POST" and "post_city" in request.POST:
    #     region = request.POST["region"]
    #     weight = 0
    #     for item in cart_items:
    #         weight = weight + item.parametr.weight * item.count
    #
    #     cart_info.delivery_price = delivery.calculate_delivery(weight, region)
    #     cart_info.get_total_price()
    #
    #     try:
    #         delivery_item = Delivery.objects.get(cart_id=cart_id)
    #         delivery_item.city = region
    #         delivery_item.price = cart_info.delivery_price
    #         delivery_item.save()
    #     except:
    #         delivery_item = Delivery()
    #         delivery_item.city = region
    #         delivery_item.price = cart_info.delivery_price
    #         delivery_item.cart_id = cart_id
    #         delivery_item.save()






        # user = request.user
        # cart_id = cart.set_cart_id(request)
        #
        # try:
        #     tmp_item = CartItem.objects.get(user=user, product=product)
        #     tmp_item.count += int(request.POST['count'])
        #     tmp_item.save()
        # except:
        #     cartItem = CartItem()
        #     cartItem.product = product
        #     # cartItem.user = user
        #     cartItem.count = request.POST['count']
        #     cartItem.cart_id = cart_id
        #     cartItem.save()

    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
Esempio n. 11
0
def cart_view(request, template_name="cart/cart.html"):

    cart_id = cart.set_cart_id(request)
    region = cart.get_region(request)

    user = request.user
    form = AccountForm()
    delivery_form = DeliveryForm()

    if user.is_authenticated():
        if region == 'МОСКВА':
            initial_region = user.city
        else:
            initial_region = region
        data = {
            'first_name': user.first_name,
            'last_name': user.last_name,
            'zip': user.zip,
            'city': initial_region,
            'address': user.address,
            'phone': user.phone
        }
        pureForm = PureAccountForm(initial=data)

    cart_items = CartItem.objects.filter(cart_id=cart_id)

    cart_info = CartInfoHelper()
    cart_info.cart_id = cart_id

    if request.method == 'POST' and "checkout" in request.POST:
        if user.is_authenticated():
            postdata = request.POST.copy()
            pureForm = PureAccountForm(postdata)

            if pureForm.is_valid():
                user.first_name = request.POST['first_name']
                user.last_name = request.POST['last_name']
                user.zip = request.POST['zip']
                user.city = request.POST['city']
                user.address = request.POST['address']
                user.phone = request.POST['phone']
                user.save()

        else:
            postdata = request.POST.copy()
            form = AccountForm(postdata)

            if form.is_valid():
                email = request.POST['email']
                password = request.POST['password']
                username = request.POST['username']
                user = Account.objects.create_user(email,
                                                   password=password,
                                                   username=username)
                login(request, user)
                user.first_name = request.POST['first_name']
                user.last_name = request.POST['last_name']
                user.zip = request.POST['zip']
                user.city = request.POST['city']
                user.address = request.POST['address']
                user.phone = request.POST['phone']
                user.save()

        order = Order()
        order.user = get_user(request)
        order.cart_id = cart_id
        order.save()

        url = '/confirmation?cart_id=%s' % request.session['cart_id']
        cart.del_session_cart_id(request)

        return HttpResponseRedirect(url)

    elif request.method == "POST" and "delete" in request.POST:
        tmp_id = request.POST['id']
        tmp_item = CartItem.objects.get(id=tmp_id)
        tmp_item.delete()

    elif request.method == "POST" and "change_count" in request.POST:
        id = int(request.POST['id'])
        tmp_count = request.POST['count']
        tmp_item = CartItem.objects.get(id=id)
        tmp_item.count = tmp_count
        tmp_item.save()

    # elif request.method == "POST" and "post_city" in request.POST:
    #     region = request.POST["region"]
    #     weight = 0
    #     for item in cart_items:
    #         weight = weight + item.parametr.weight * item.count
    #
    #     cart_info.delivery_price = delivery.calculate_delivery(weight, region)
    #     cart_info.get_total_price()
    #
    #     try:
    #         delivery_item = Delivery.objects.get(cart_id=cart_id)
    #         delivery_item.city = region
    #         delivery_item.price = cart_info.delivery_price
    #         delivery_item.save()
    #     except:
    #         delivery_item = Delivery()
    #         delivery_item.city = region
    #         delivery_item.price = cart_info.delivery_price
    #         delivery_item.cart_id = cart_id
    #         delivery_item.save()

    # user = request.user
    # cart_id = cart.set_cart_id(request)
    #
    # try:
    #     tmp_item = CartItem.objects.get(user=user, product=product)
    #     tmp_item.count += int(request.POST['count'])
    #     tmp_item.save()
    # except:
    #     cartItem = CartItem()
    #     cartItem.product = product
    #     # cartItem.user = user
    #     cartItem.count = request.POST['count']
    #     cartItem.cart_id = cart_id
    #     cartItem.save()

    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))