Esempio n. 1
0
def order(request):
        if request.method == 'POST':
            form = OrderForm(request.POST)
            if form.is_valid():
                _customerid  =   form.cleaned_data['customerid']
                _voltage     =   form.cleaned_data['voltage']
                _current     =   form.cleaned_data['current']
                _width       =   form.cleaned_data['width']
                _height      =   form.cleaned_data['height']
                _status      =   form.cleaned_data['status']

                job = Order(customerid=_customerid, voltage=_voltage, current=_current, width=_width, height=_height, status=_status, order_ts=timezone.now())
                job.save()

                return HttpResponse("thank you!")
            
            else:
                form = OrderForm()
                render(request, 'order.html', {
                        'form': form,
                        })

        else: 
            form = OrderForm()
            return render(request, 'order.html', {
               'form': form,
               })
Esempio n. 2
0
File: views.py Progetto: BabyTK/Tk9
def productOrder(request):
    category = Category.objects.all()
    current_user = request.user
    basket = CustomerBasket.objects.filter(user_id = current_user.id)
    total = 0
    for rs in basket:
        total += rs.product.price * rs.quantity
    
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()


            basket = CustomerBasket.objects.filter(user_id=current_user.id)
            for rs in basket:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity

                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()
            
            CustomerBasket.objects.filter(user_id = current_user.id).delete()
            request.session['cart_items']=0
            messages.success(request, "Sipariş tamamlandı!")
            return render(request, 'shop-basket.html',{'ordercode':ordercode,'category':category})
        
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")
    
    form = OrderForm()
    profile = UserProfile.objects.get(user_id = current_user.id)
    context = {
        'basket':basket,
        'total':total,
        'form':form,
        'profile':profile
    }

    return render(request, 'shop-checkout1.html', context)
Esempio n. 3
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    schopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in schopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':  # if there is a post
        form = OrderForm(request.POST)
        # return HttpResponse(request.POST.items())
        if form.is_valid():
            # Send Credit card to bank,  If the bank responds ok, continue, if not, show the error
            # ..............

            data = Order()
            data.first_name = form.cleaned_data['first_name']  # get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()  # random cod
            data.code = ordercode
            data.save()  #

            schopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in schopcart:
                detail = OrderProduct()
                detail.order_id = data.id  # Order Id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()
                # ***Reduce quantity of sold product from Amount of Product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()  # Clear & Delete shopcart
            request.session['cart_items'] = 0
            messages.success(request, "Your Order has been completed. Thank you ")
            return render(request, 'Order_Completed.html', {'ordercode': ordercode, 'category': category})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {'schopcart': schopcart,
               'category': category,
               'total': total,
               'form': form,
               'profile': profile,
               }
    return render(request, 'Order_Form.html', context)
Esempio n. 4
0
def orderproductviews(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.discount_price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)

        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.phone = form.cleaned_data['phone']
            data.region = form.cleaned_data['region']
            data.district = form.cleaned_data['district']
            data.street_address = form.cleaned_data['street_address']
            data.apartment_address = form.cleaned_data['apartment_address']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.color = rs.color
                detail.size = rs.size
                detail.price = rs.product.price
                detail.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request, "Your Oder has been completed. Thank you")
            context = {'category': category,
                       'ordercode': ordercode
                       }
            return render(request, 'order_completed.html', context)
            #return redirect('/order/payment/')
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct/")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {'shopcart': shopcart,
               'category': category,
               'total': total,
               'form': form,
               'profile': profile
               }
    return render(request, 'check-out.html', context)
Esempio n. 5
0
def orderproduct(request):
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    count = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity
        count += rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()

                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.count_sold += 1
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_item'] = 0
            messages.success(request, 'Your order has been completed.')
            return render(request, 'Order_Completed.html',
                          {'ordercode': ordercode})

        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/order/orderproduct')

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart': shopcart,
        'total': total,
        'form': form,
        'profile': profile,
    }
    return render(request, 'order_form.html', context)
Esempio n. 6
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user)
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm()
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.phone = form.cleaned_data['phone']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.country = form.cleaned_data['country']
            data.user_id = current_user.id
            data.ip = request.META('REMOTE_ADDR')
            ordercode = get_random_string(12).upper()
            data.code = ordercode
            data.save()

            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product = rs.product_id
                detail.user_id = rs.user_id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.product.amount
                detail.save()
                product = Product.objects.get(rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_item'] = 0
            messages.success(request, "SIzning buyurtmangiz qabul qilindi!")
            return render(request, 'ordercomplete.html', { 'ordercode': ordercode, 'category': category})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/order/orderproduct')

    form = OrderForm
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    profile = UserProfile.objects.filter(user_id=current_user.id)
    context = {
        'shopcart': shopcart,
        'category': category,
        'total': total,
        'profile': profile,
        'form': form,
    }
    return HttpResponseRedirect(request, 'orderproduct.html', context)
Esempio n. 7
0
def OrderBookFunc(request):
    category = Category.objects.all()
    curent_user = request.user
    shopcart = ShopCart.objects.filter(user_id=curent_user.id)
    total = 0
    for rs in shopcart:
        total += rs.book.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.adress = form.cleaned_data['adress']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = curent_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()  # random cod
            data.code = ordercode
            data.save()

            shopcart = ShopCart.objects.filter(user_id=curent_user.id)
            for rs in shopcart:
                detail = OrderBook()
                detail.order_id = data.id
                detail.book_id = rs.book_id
                detail.user_id = curent_user.id
                detail.quantity = rs.quantity
                detail.price = rs.book.price
                detail.amount = rs.amount
                detail.save()

                book = Book.objects.get(id=rs.book_id)
                book.amount -= rs.quantity
                book.save()

            ShopCart.objects.filter(user_id=curent_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request,"Your order has been completed. Thank you")
            return render(request,'OrderCompleted.html',{'ordercode':ordercode,'category':category})
        else:
            messages.warning(request,form.errors)
            return HttpResponseRedirect("/order/orderbook")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=curent_user.id)
    context = {
        'category': category,
        'shopcart':shopcart,
        'total':total,
        'profile':profile,
        'form':form,
    }
    return render(request,'OrderForm.html',context)
def orderitem(request):
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    schopcart = ShopCart.objects.filter(user_id=current_user.id)

    form = OrderForm(request.POST or None)
    form2 = OrderForm2(request.POST or None)

    total = 0
    for rs in shopcart:
        total += rs.item.fiyat * rs.quantity

    if request.method == 'POST':
        if form.is_valid() and form2.is_valid():
            # Send Credit card to bank,  If the bank responds ok, continue, if not, show the error
            # ..............

            data = Order()
            data.first_name = form.cleaned_data[
                'first_name']  # get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            data.email = form.cleaned_data['email']
            data.address = form2.cleaned_data['address']
            data.city = form2.cleaned_data['city']
            data.phone = form2.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = random.randint(100000000, 999999999)
            # ordercode= get_random_string(9).upper() # random cod
            data.code = ordercode
            data.save()

            for rs in shopcart:
                detail = OrderItem()
                detail.order_id = data.id  # Order Id
                detail.item_id = rs.item_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.beden = rs.beden
                detail.fiyat = rs.item.fiyat
                detail.save()

            return redirect(reverse('payment'))
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    context = {
        'shopcart': shopcart,
        'total': total,
        'form': form,
        'form2': form2,
        'schopcart': schopcart,
    }
    return render(request, 'order/order_form.html', context)
Esempio n. 9
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    schopcart = ShopCart.objects.filter(user_id=current_user)
    total = 0
    for rs in schopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.country=form.cleaned_data['country']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            schopcart = ShopCart.objects.filter(user_id = current_user.id)
            for rs in schopcart:
                detail = OrderProduct()
                detail.order_id =data.id
                detail.product_id =rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                product = Product.objects.get(id = rs.product_id)
                product.amount = rs.quantity
                product.save()

                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()


            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] =0
            messages.success(request,"Siparişiniz verildi, Teşekkürler")
            return render(request,'order_Completed.html',{'ordercode':ordercode,'category':category})
        else:
            messages.error(request,form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id = current_user.id)
    context = {'schopcart':schopcart,
               'category':category,
               'total':total,
               'form':form,
               'profile':profile,}
    return render(request,'Order_Form.html',context)
Esempio n. 10
0
def shop_cart_checkout(request):
    current_user = request.user
    shopcart = ShopCart.objects.all().filter(user_id=current_user.id)
    carttotal = 0
    for rs in shopcart:
        carttotal += rs.quantity * rs.product.price

    form = OrderForm(request.POST or None)
    if request.method == 'POST':
        # check whether it's valid:
        if form.is_valid():

            # Send Credit card information to bank and get result
            # If payment accepted continue else send payment error to checkout page

            data = Order()
            data.name = form.cleaned_data[
                'name']  #get product quantity from form
            data.surname = form.cleaned_data['surname']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.to = form.cleaned_data['name']
            data.user_id = current_user.id
            data.total = carttotal
            data.save()

            # Save Shopcart items to Order detail items
            for rs in shopcart:
                detail = OrderDetail()
                detail.order_id = data.id  # Order Id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.total = rs.amount
                detail.save()
                #  Reduce product Amount  (quantity)

            ShopCart.objects.filter(
                user_id=current_user.id).delete()  # Clear & Delete shopcart
            request.session['cart_items'] = 0
            messages.success(request, "Order has been completed. Thank You ")
            return HttpResponseRedirect("/order")

    context = {
        'page': 'checkout',
        'shopcart': shopcart,
        'carttotal': carttotal,
    }
    return render(request, 'shop_cart_checkout.html', context)
Esempio n. 11
0
def orderproduct(request, id):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    product = Product.objects.get(pk=id)
    current_user = request.user
    total = product.price

    if request.method == 'POST':  # if there is a post
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            orderproduct = OrderProduct()
            orderproduct.order = data
            orderproduct.price = total
            orderproduct.user = current_user
            orderproduct.product = product
            orderproduct.save()

            messages.success(request, "Your Order has been completed. Thank you ")
            return render(request, 'Order_Completed.html', {'ordercode': ordercode, 'category': category, 'setting': setting})

        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct/" + str(id))

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {'category': category,
               'form': form,
               'total': total,
               'profile': profile,
               'product': product,
               'setting': setting,
               }
    return render(request, 'Order_Form.html', context)
Esempio n. 12
0
def order(request):
    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            _customerid = form.cleaned_data['customerid']
            _voltage = form.cleaned_data['voltage']
            _current = form.cleaned_data['current']
            _width = form.cleaned_data['width']
            _height = form.cleaned_data['height']
            _status = form.cleaned_data['status']

            job = Order(customerid=_customerid,
                        voltage=_voltage,
                        current=_current,
                        width=_width,
                        height=_height,
                        status=_status,
                        order_ts=timezone.now())
            job.save()

            return HttpResponse("thank you!")

        else:
            form = OrderForm()
            render(request, 'order.html', {
                'form': form,
            })

    else:
        form = OrderForm()
        return render(request, 'order.html', {
            'form': form,
        })
Esempio n. 13
0
def shop_cart_checkout(request):
    categoryList = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.all().filter(user_id=current_user.id)
    carttotal = 0
    for rs in shopcart:
        carttotal += rs.quantity * rs.product.price

    form = OrderForm(request.POST or None)
    if request.method == 'POST':
        if form.is_valid():
            # Credit Card information section if bank accept payment then order==true
            data = Order()
            data.name = form.cleaned_data['name']
            data.surname = form.cleaned_data['surname']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.to = form.cleaned_data['name']
            data.user_id = current_user.id
            data.total = carttotal
            data.save()
            for rs in shopcart:
                detail = OrderDetail()
                detail.order_id = data.id
                detail.product_id = rs.product.id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.total = rs.amount
                detail.save()
            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request, "Order has been completed ")
            return HttpResponseRedirect("/order")

    context = {
        'page': 'checkout',
        'shopcart': shopcart,
        'carttotal': carttotal,
        'categoryList': categoryList,
    }
    return render(request, 'shop_cart_checkout.html', context)
def shop_cart_checkout(request):
    current_user = request.user
    shopcart = ShopCart.objects.all().filter(user_id=current_user.id)
    carttotal = 0
    for rs in shopcart:
        carttotal += rs.quantity * rs.product.price
    form = OrderForm(request.POST or None)
    if request.method == 'POST':

        if form.is_valid():

            data = Order()
            data.shipname = form.cleaned_data['shipname']
            data.shipaddress = form.cleaned_data['shipaddress']
            data.shipphone = form.cleaned_data['shipphone']
            data.to = form.cleaned_data['shipname']
            data.user_id = current_user.id
            data.total = carttotal
            data.save()

            for rs in shopcart:
                detail = OrderDetail()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.total = rs.amount
                detail.save()
            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request, "Order has been completed. Thank You")
            return HttpResponseRedirect("/order")
    context = {
        'page': 'checkout',
        'shopcart': shopcart,
        'carttotal': carttotal,
    }
    return render(request, 'shop_cart_checkout.html', context)
Esempio n. 15
0
def submission(request):
    tran_id=transaction.savepoint()#记录当前的信息
    post=request.POST
    goods_carts_id=post.get('cart_ids')
    try:
        order_goods=OrderForm()
        now=datetime.now()
        buyer=request.user
        buyerid=buyer.id
        order_goods.order_number='%s%d'%(now.strftime('%Y%m%d%H%M%S'),buyerid)
        order_goods.user_id=buyerid
        order_goods.date=now
        order_goods.total=Decimal(post.get('total4'))
        order_goods.save()
        #创建订单详情
        #goods_carts_id1=[int(item) for item in goods_carts_id.split[',']]
                       # [int(item) for item in cart_ids.split[',']]
        goods_carts_id1 = [int(item) for item in goods_carts_id.split(',')]#此处split()将字符串分割成list
        #cart_ids1 = [int(item) for item in cart_ids]

        for id1 in goods_carts_id1:
            detail=OrderDatail()
            detail.order=order_goods
            carts=Cart.objects.get(id=id1)
            goods=carts.goods
            if goods.stock>=carts.count:
                goods.stock=goods.stock-carts.count
                goods.save()
                detail.goods_id=goods.id
                detail.price=goods.price
                detail.count=carts.count
                detail.save()
                carts.delete()
            else:
                transaction.savepoint_rollback(tran_id)
                return redirect('/cart/')
    except Exception as e:
        print '==============%s'%e
        transaction.savepoint_rollback(tran_id)
    return redirect('/user/order/')

    #return render(request,'users/user_center_order.html')
def orderproduct(request):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    product = Product.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':  # if there is a post
        form = OrderForm(request.POST)
        if form.is_valid():
            #kredi kartı bilgilerini bankaya gönder onay gelirse dewamkee
            #<*><*><*><*>#
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(8).upper()  #random kod üretir
            data.code = ordercode
            data.save()

            #move shopcart items to order products items
            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id  #order id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()
                #***** reduce quantity of sold product from amount of product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()
                #****+++---*****

            ShopCart.objects.filter(
                user_id=current_user.id).delete()  #Clear and Delete ShopCart
            request.session['cart_items'] = 0
            messages.success(
                request, "Üyeliğiniz başarıyla tamamlanmıştır. Sporla kalın! ")
            return render(request, 'Order_Completed.html', {
                'ordercode': ordercode,
                'category': category,
                'setting': setting
            })

        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct/")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'category': category,
        'shopcart': shopcart,
        'form': form,
        'total': total,
        'profile': profile,
        'product': product,
        'setting': setting,
    }
    return render(request, 'Order_Form.html', context)
Esempio n. 17
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user  #Access User Session Information
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid(
        ):  #kredi kartı bilgilerini bankaya gönder onay gelince devam et
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(
                5).upper()  #random kod üretir,5 rakamlı, upper ->büyük harfle
            data.code = ordercode
            data.save()

            # Shopcart öğelerini Ürün  sipariş öğelerine taşıma
            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()

                #**Ürün Miktarından satılan ürün miktarını azaltın **
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(
                user_id=current_user.id).delete()  #sepet temizlenir
            request.session['cart_items'] = 0  #sepet ürün sayısı sıfırlanır
            messages.success(request,
                             "Your Order has been completed. Thank You ..")
            return render(request, 'Order_Completed.html', {
                'ordercode': ordercode,
                'category': category
            })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")
    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart': shopcart,
        'category': category,
        'total': total,
        'form': form,
        'profile': profile,
    }
    return render(request, 'Order_Form.html', context)
Esempio n. 18
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    profilepro = ProfilePro.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        if rs.product.variant == 'None':
            total += rs.quantity * (rs.product.price-(rs.product.price*(rs.product.remise/100)))
        else:
            total += rs.variant.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():

            # Send Credit card information to bank and get result
            # If payment accepted continue else send payment error to checkout page

            data=Order()
            data.note = form.cleaned_data['note']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            # Save Shopcart items to Order detail items
            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id     = data.id # Order Id
                detail.compte = profilepro.compte  # Order Id
                detail.product_id   = rs.product_id
                detail.user_id      = current_user.id
                detail.quantity     = rs.quantity
                if rs.product.variant == 'None':
                    detail.price        = rs.product.price
                else:
                    detail.price = rs.variant.price
                detail.variant_id        = rs.variant_id
                detail.remise = rs.product.remise
                detail.amount = rs.amount
                detail.order_amount = data.total
                detail.note = data.note
                detail.save()
                #  Reduce product Amount  (quantity)

                if rs.product.variant=='None':
                    product = Product.objects.get(id=rs.product_id)
                    product.amount -= rs.quantity
                    product.save()
                else:
                    variant = Variants.objects.get(id=rs.product_id)
                    variant.quantity -= rs.quantity
                    variant.save()


            ShopCart.objects.filter(user_id=current_user.id).delete() # Clear & Delete shopcart
            request.session['cart_items']=0
            messages.success(request, "Your order has been completed. Thank You ")
            return render(request, 'Order_Completed.html',{'ordercode':ordercode, 'category':category})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")
    form = OrderForm()
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {'shopcart': shopcart,
               'category': category,
               'total': total,
               'form': form,
               'profile': profile,
               'profilepro': profilepro,
               }
    return render(request, 'Order_Form.html', context)
Esempio n. 19
0
def order(request_):
    category = Category.objects.all()
    current_user = request_.user
    print(current_user)
    cart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in cart:
        total += rs.product.price * rs.quantity
    print(total)
    grand_total = total + (total * 0.18)
    if request_.method == 'POST':
        print('post recived')
        form = OrderForm(request_.POST)
        print(form)
        if form.is_valid():
            print('valid')
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.state = form.cleaned_data['state']
            data.country = form.cleaned_data['country']
            data.zip = form.cleaned_data['zip_code']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request_.META.get('REMOTE_ADDR')
            ordercode = get_random_string(7).upper()
            data.code = ordercode
            print(ordercode)
            data.save()

            shop_cart = ShopCart.objects.filter(user_id=current_user.id)
            total_cart = 0
            for rs in shop_cart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                total_cart += rs.amount
                print(detail.amount)
                detail.save()

                # reduce quantity of sold product from amount of product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request_.session['cart_items'] = 0
            messages.success(
                request_,
                "Your Order Has Been Completed Successfully, Thank You!")

            send_mail(
                'Your Order Has Been Received!',
                'Thanks For Shopping With Us, Your order will be delivered in 5-6 working days! Your Order No. :'
                + ordercode,
                '*****@*****.**',
                ['*****@*****.**'],
                fail_silently=False)
            print('mail sent')

            return render(request_, 'shop/order_completed.html', {
                'ordercode': ordercode,
                'category': category
            })
    return None
Esempio n. 20
0
def checkout(request):
    category = Category.objects.all()

    current_user = request.user
    print(current_user)
    cart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in cart:
        total += rs.product.price * rs.quantity
    print(total)
    grand_total = total + (total * 0.18)
    form = OrderForm()
    context = {
        'category': category,
        'shopcart': cart,
        'total': total,
        'grand_total': grand_total,
        'form': form
    }
    if request.method == 'POST':
        print('post recived')
        form = OrderForm(request.POST)
        print(form)
        if form.is_valid():
            print('valid')
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.state = form.cleaned_data['state']
            data.country = form.cleaned_data['country']
            data.zip = form.cleaned_data['zip_code']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(7).upper()
            data.code = ordercode
            print(ordercode)
            data.save()

            shop_cart = ShopCart.objects.filter(user_id=current_user.id)
            total_cart = 0
            for rs in shop_cart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                total_cart += rs.amount
                print(detail.amount)
                detail.save()

                # reduce quantity of sold product from amount of product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(
                request,
                "Your Order Has Been Completed Successfully, Thank You!")

            send_mail_task.delay(ordercode)
            sleepy.delay(30)

            print('mail sent')

            return render(request, 'shop/order_completed.html', {
                'ordercode': ordercode,
                'category': category
            })

    return render(request, 'shop/checkout.html', context)
Esempio n. 21
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    userAddress = UserAddress.objects.filter(user_id=current_user.id)
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    ordercode = get_random_string(10).upper()

    couponInfo = []
    from offer.views import checkValidCoupon
    couponInfo = checkValidCoupon(request)

    from offer.views import applyWallet
    applyWalletInfo = applyWallet(request)

    total = 0
    discountlessTotal = 0
    discountOff = 0
    for rs in shopcart:
        if rs.product.variant == 'None':
            try:
                disP = ProductDiscount.objects.get(product_id=rs.product.id,
                                                   variant_id=rs.variant_id)
                actualPrice = rs.product.price
                nowPrice = actualPrice - actualPrice * disP.discountPercent / 100
                print(disP, nowPrice)
            except:
                actualPrice = rs.product.price
                nowPrice = actualPrice

            total += nowPrice * rs.quantity
            discountlessTotal += actualPrice * rs.quantity
        else:
            try:
                disP = ProductDiscount.objects.get(product_id=rs.product.id,
                                                   variant_id=rs.variant_id)
                actualPrice = rs.variant.price
                nowPrice = actualPrice - actualPrice * disP.discountPercent / 100
                print(disP, nowPrice)
            except:
                actualPrice = rs.variant.price
                nowPrice = actualPrice

            total += nowPrice * rs.quantity
            discountlessTotal += rs.variant.price * rs.quantity

    #check user has subscribed to any plan or not. priceOff is the amount subtract from original price.
    try:
        activePlan = Subscriber.objects.filter(user_id=request.user.id,
                                               status='Active')[0]
        s_id = activePlan.subcription_id
        plan_info = Subscription_Duration.objects.get(id=s_id)
        limit_amount = plan_info.limit_amount
        percentage = plan_info.percentage

        if total * percentage / 100 > limit_amount:
            totalprice = total - limit_amount
            priceOff = limit_amount
        else:
            totalprice = total - total * percentage / 100
            priceOff = total * percentage / 100

    except:
        totalprice = total
        priceOff = 0

    if request.method == 'POST':  # if there is a post

        form = OrderForm(request.POST)
        # return HttpResponse(request.POST.items())
        if form.is_valid():
            # Send Credit card to bank,  If the bank responds ok, continue, if not, show the error
            # ..............

            data = Order()
            data.first_name = form.cleaned_data[
                'first_name']  # get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            #data.address = form.cleaned_data['address']
            #data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.locationAddress = form.cleaned_data['locationAddress']
            data.houseNo = form.cleaned_data['houseNo']
            data.latitude = form.cleaned_data['latitude']
            data.longitude = form.cleaned_data['longitude']

            print(form.cleaned_data['useWallet'])
            data.useWallet = form.cleaned_data['useWallet']
            data.user_id = current_user.id

            data.total = total
            data.priceOffPlan = total - totalprice
            data.discountOff = discountlessTotal - total

            walletMoneyDeducted = 0

            if form.cleaned_data['useWallet']:
                walletMoneyDeducted = applyWalletInfo.cashBackTotal
                if (totalprice <= walletMoneyDeducted):
                    walletMoneyDeducted = totalprice
                else:
                    walletMoneyDeducted = applyWalletInfo.cashBackTotal

            paybleAmount = float(totalprice) - float(walletMoneyDeducted)
            paybleAmount = round(paybleAmount, 2)
            data.walletDeduction = walletMoneyDeducted

            try:
                print(couponInfo.code)
                cashBackAdded = total * couponInfo.cashBackPercent / 100
                if cashBackAdded >= couponInfo.cashBackLimit:
                    cashBackAdded = couponInfo.cashBackLimit
                data.cashBackIssued = cashBackAdded
                data.cashBackCoupon = couponInfo.code

            except:
                pass

            data.ip = request.META.get('REMOTE_ADDR')
            # random code
            data.code = ordercode
            data.save()  #

            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id  # Order Id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                if rs.product.variant == 'None':
                    detail.price = rs.product.price
                    productDiscountOff = 0
                    try:
                        disP = ProductDiscount.objects.get(
                            product_id=rs.product.id, variant_id=rs.variant_id)
                        actualPrice = rs.product.price

                        detail.productDiscountOff = actualPrice * disP.discountPercent / 100
                    except:
                        #actualPrice = rs.product.price
                        detail.productDiscountOff = 0
                else:
                    detail.price = rs.variant.price
                    try:
                        disP = ProductDiscount.objects.get(
                            product_id=rs.product.id, variant_id=rs.variant_id)
                        actualPrice = rs.variant.price

                        detail.productDiscountOff = actualPrice * disP.discountPercent / 100
                    except:
                        # actualPrice = rs.product.price
                        detail.productDiscountOff = 0
                detail.variant_id = rs.variant_id
                detail.amount = detail.quantity * detail.price
                detail.save()
                # ***Reduce quantity of sold product from Amount of Product
                if rs.product.variant == 'None':
                    product = Product.objects.get(id=rs.product_id)
                    product.amount -= rs.quantity
                    product.save()
                else:
                    variant = Variants.objects.get(id=rs.variant_id)
                    variant.quantity -= rs.quantity
                    variant.save()
                #************ <> *****************
            name = request.user.get_username()
            print('username is: ', name)

            #name='tuhin'
            param_dict = {
                'MID':
                MID,
                'ORDER_ID':
                str(ordercode),
                'TXN_AMOUNT':
                str(paybleAmount),
                'CUST_ID':
                str(
                    UserProfile.objects.get(
                        user_id=current_user.id).user.email),
                'INDUSTRY_TYPE_ID':
                'Retail',
                'WEBSITE':
                'WEBSTAGING',
                'CHANNEL_ID':
                'WEB',
                'CALLBACK_URL':
                'http://127.0.0.1:8000/order/handleRequest/' + name,
            }

            if (paybleAmount == 0 and totalprice > 0):
                print('Order Successful')
                # uid = Order.objects.filter(code = str(response_dict['ORDERID']))
                # print (uid.get(pk=1))

                order_update = Order.objects.get(code=ordercode,
                                                 user_id=current_user.id)
                order_update.status = 'Accepted'
                order_update.paid = True

                order_update.clientOTP = random.randint(1111, 9999)

                # order_update.useWallet = True
                # order_update.refresh_from_db(fields=['status'])
                Order.save(self=order_update)

                from offer.views import walletDeduction
                walletDeduction(request, ordercode)
                # print(order_update.status)

                entryDeliveryManagemant = DeliveryManagement()
                entryDeliveryManagemant.confirmedOrder_id = order_update.id
                entryDeliveryManagemant.save()

                current_user = request.user  # Access User Session information
                ShopCart.objects.filter(user_id=current_user.id).delete()
                request.session['cart_items'] = 0
                # Order.objects.filter(user_id=current_user.id, code= ).delete()
                messages.success(request,
                                 "Your Order has been completed. Thank you ")

                return HttpResponseRedirect(
                    'http://127.0.0.1:8000/order/handleRequest/' + name)

            else:
                param_dict['CHECKSUMHASH'] = checksum.generate_checksum(
                    param_dict, MERCHANT_KEY)

                form = OrderForm()
                profile = UserProfile.objects.get(user_id=current_user.id)
                context = {
                    'shopcart': shopcart,
                    'total': total,
                    'totalprice': totalprice,
                    'discountlessTotal': discountlessTotal,
                    'form': form,
                    'profile': profile,
                    'param_dict': param_dict,
                    'priceOff': priceOff,
                    'couponInfo': couponInfo,
                    'applyWalletInfo': applyWalletInfo,
                    'userAddress': userAddress,
                }
                return render(request, 'paytm.html', context)

    context2 = {
        'shopcart': shopcart,
        'total': total,
        'totalprice': totalprice,
        'discountlessTotal': discountlessTotal,
        'profile': UserProfile.objects.get(user_id=current_user.id),
        'priceOff': priceOff,
        'couponInfo': couponInfo,
        'applyWalletInfo': applyWalletInfo,
        'userAddress': userAddress,
    }

    return render(request, 'Order_Form.html', context2)
Esempio n. 22
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            # check bank or credit card information and if everything ok or return error message before save order
            #......code
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(6).upper()
            data.code = ordercode
            data.save()

            # move shopcart items to order product items

            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id  # order id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()

                # reduce quantity of sold product from amount of product

                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

                #********<>**********

            ShopCart.objects.filter(
                user_id=current_user.id).delete()  # clear and delete shopcart
            request.session['total_item'] = 0
            messages.success(request,
                             'your order has been completed.thank you')
            return render(request, 'order_completed.html', {
                'ordercode': ordercode,
                'category': category
            })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect('/orderproduct')
    form = OrderForm()
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart': shopcart,
        'category': category,
        'total': total,
        'form': form,
        'profile': profile,
    }

    return render(request, 'checkout.html', context)
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        if rs.product.variant == 'None':
            total += rs.product.price * rs.quantity
        else:
            total += rs.variant.price * rs.quantity

    transport = 0
    for rs in shopcart:
        transport += rs.product.transportation * rs.quantity

    final_total = total + transport

    amount = 0
    for rs in shopcart:
        amount += rs.quantity

    if request.method == 'POST':  # if there is a post
        form = OrderForm(request.POST)
        # return HttpResponse(request.POST.items())
        if form.is_valid():
            # Send Credit card to bank,  If the bank responds ok, continue, if not, show the error

            req_data = {
                "merchant_id": MERCHANT,
                "amount": amount,
                "callback_url": CallbackURL,
                "description": description,
                "metadata": {"mobile": mobile, "email": email}
            }
            req_header = {"accept": "application/json",
                          "content-type": "application/json'"}
            req = requests.post(url=ZP_API_REQUEST, data=json.dumps(
                req_data), headers=req_header)
            authority = req.json()['data']['authority']
            if len(req.json()['errors']) == 0:
                return redirect(ZP_API_STARTPAY.format(authority=authority))
            else:
                e_code = req.json()['errors']['code']
                e_message = req.json()['errors']['message']
                return HttpResponse(f"Error code: {e_code}, Error Message: {e_message}")

            # ..............

            data = Order()
            data.first_name = form.cleaned_data['first_name']  # get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()  # random cod
            data.code = ordercode
            data.save()  #

            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                if rs.product.variant == 'None':
                    detail.price = rs.product.price
                else:
                    detail.price = rs.variant.price
                detail.variant_id = rs.variant_id
                detail.amount = rs.amount
                detail.save()

                # ***Reduce quantity of sold product from Amount of Product
                if rs.product.variant == 'None':
                    product = Product.objects.get(id=rs.product_id)
                    product.amount -= rs.quantity
                    product.save()
                else:
                    variant = Variants.objects.get(id=rs.product_id)
                    variant.quantity -= rs.quantity
                    variant.save()
                # ************ <> *****************
            setting = Setting.objects.get(pk=1)
            ShopCart.objects.filter(user_id=current_user.id).delete()  # Clear & Delete shopcart
            request.session['cart_items'] = 0
            messages.success(request, "خرید شما با موفقیت انجام شد")
            return render(request, 'Order_Completed.html',
                          {'ordercode': ordercode, 'category': category, 'setting': setting, 'amount':amount})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    context = {'shopcart': shopcart,
               'category': category,
               'total': total,
               'form': form,
               'profile': profile,
               'transport': transport,
               'final_total': final_total,
               'setting': setting,
               'amount':amount
               }
    return render(request, 'Order_Form.html', context)
Esempio n. 24
0
def orderproduct(request):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        if rs.product.variant == 'None':
            total += rs.product.price * rs.quantity
        else:
            total += rs.variant.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():

            # apply credit card infromation from the bank like api process
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.email = form.cleaned_data['email']
            data.country = form.cleaned_data['country']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                if rs.product.variant == 'None':
                    detail.price = rs.product.price
                else:
                    detail.price = rs.variant.price
                detail.variant_id = rs.variant_id
                detail.amount = rs.amount
                detail.save()

                if rs.product.variant == 'None':
                    product = Product.objects.get(id=rs.product_id)
                    product.amount -= rs.quantity
                    product.save()
            else:
                check = Variants.objects.filter(id=rs.product_id)
                if len(check) > 0:
                    variant = Variants.objects.get(id=rs.product_id)
                    variant.quantity -= rs.quantity
                    variant.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request,
                             "Your Order has been completed. Thank you")
            template = render_to_string(
                'order_confirmation.html', {
                    'ordercode': ordercode,
                    'detail': detail,
                    'detail.quantity': detail.quantity,
                    'detail.price': detail.price,
                    'detail.amount': detail.amount,
                    'category': category
                })
            send_mail('Order Confirmation',
                      'Your order has been recieved!',
                      settings.EMAIL_HOST_USER,
                      ['*****@*****.**', data.email],
                      fail_silently=False,
                      html_message=template)
            return render(
                request, 'order_completed.html', {
                    'ordercode': ordercode,
                    'detail': detail,
                    'detail.quantity': detail.quantity,
                    'detail.price': detail.price,
                    'detail.amount': detail.amount,
                    'category': category
                })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    # profile = UserProfile.objects.get(user_id=current_user.id)
    setting = Setting.objects.get(pk=1)
    context = {
        'shopcart': shopcart,
        'setting': setting,
        'total': total,
        'form': form,
        #        'profile': profile,
        'category': category,
    }
    return render(request, 'order_form.html', context)
Esempio n. 25
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    # profile = UserProfile.objects.get(user_id=current_user.id)
    total_quantity = 0
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity
        total_quantity += rs.quantity
    # return HttpResponse(str(total))

    if request.method == 'POST':  # if there is a post
        form = OrderForm(request.POST)
        if form.is_valid():

            data = Order()
            data.first_name = form.cleaned_data['first_name']  # get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.total_quantity = total_quantity
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(10).upper()  # random code
            data.code = ordercode
            data.save()

            # Move Shopcart items to Order Product items
            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id  # Order id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()
                # Reduce quantity of sold product from Amount of Product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request, "Your Order Has Been Completed! Thank you!")
            return render(request, 'ordercomplete.html', {'ordercode': ordercode, 'category': category})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart': shopcart,
        'category': category,
        'total': total,
        'total_quantity': total_quantity,
        'profile': profile,
        'form': form,
    }

    return render(request, 'orderproduct.html', context)
Esempio n. 26
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.fiyat * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)

        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            #move shopcrt items for order products items
            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:  #schopcart
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.fiyat = rs.product.fiyat
                detail.stok_durum = rs.stok_durum
                detail.save()

                # ***************< Reduce >***************#
                product = Kitap.objects.get(id=rs.product_id)
                product.stok_durum -= rs.quantity
                product.save()
                #***************<^^^^^^^^^^>***************#

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request,
                             "Your order has been completed , thank you!")
            return render(request, "Order_Complated.html", {
                'ordercode': ordercode,
                'category': category
            })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart': shopcart,  # hoca Schopcart yazmis
        'category': category,
        'total': total,
        'profile': profile,
        'form': form,
    }

    return render(request, 'Order_Form.html', context)
def orderfood(request):
    category = Category.objects.all()
    current_user = request.user
    schopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in schopcart:
        total += rs.Food.price * rs.quantity #toplamı hesapla

    if request.method == 'POST': #form post edildiyse food_detail dan
        form = OrderForm(request.POST)
        if form.is_valid(): #geçerli mi csrf kontrolü
            #kredi kartı bilgilerini bankaya gönder onay gelirse devam et
            #....if kontrolü....
            data = Order() #order tablosu ile ilişki kur
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper() # random kod üretir
            data.code = ordercode
            data.save()

            #sepetteki ürünleri order'a kaydetmek için aşağıdaki kodlar
            schopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in schopcart:
                detail = OrderFood()
                detail.order_id = data.user_id
                detail.Food_id = rs.Food_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity

                Food = food.objects.get(id=rs.Food_id)
                Food.amount -= rs.quantity #ürün stoktan düşme
                Food.save()

                detail.price = rs.Food.price
                detail.amount = rs.amount
                detail.save()

            ShopCart.objects.filter(user_id=current_user.id).delete() #sepet temizlendi
            request.session['cart_items']=0
            messages.success(request, "Your order has been completed. Thank you")
            return render(request,'Order_Completed.html',{'ordercode':ordercode,'category':category})
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderfood")

    #post yoksa
    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {'schopcart': schopcart,
                'category': category,
                'total': total,
                'form': form,
                'profile': profile,
                }
    return render(request,'Order_Form.html',context)
Esempio n. 28
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user

    schopcart = Shopcart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in schopcart:
        total += rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.country = form.cleaned_data['country']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            tarih = datetime.now() + timedelta(days=15)
            data.teslim_tarih = tarih
            data.code = ordercode
            data.save()

            # Move Shopcart items to order Product items
            schopcart = Shopcart.objects.filter(user_id=current_user.id)
            for rs in schopcart:
                detail = OrderProduct()
                detail.order_id = data.id  #order id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity

                #reduce quantity of sold product
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()
                #************* <> *********
                detail.save()

            Shopcart.objects.filter(
                user_id=current_user.id).delete()  #clear and delete shop cart
            request.session['cart_items'] = 0
            messages.success(request, "Kitabı Ödünç Aldınız, Teşekkür Ederiz")
            return render(request, 'Order_Completed.html', {
                'ordercode': ordercode,
                'category': category,
                'tarih': tarih
            })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderproduct")
    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'schopcart': schopcart,
        'category': category,
        'total': total,
        'form': form,
        'profile': profile
    }
    return render(request, 'Order_Form.html', context)
Esempio n. 29
0
def orderproduct(request):
    #form = OrderForm()
    category = Category.objects.all()
    setting = Setting.objects.all()
    current_user = request.user
    profile = UserProfile.objects.get(User_id=current_user.id)
    shopcart = ShopCart.objects.filter(User_id=current_user.id)
    orderqty = ShopCart.objects.filter(User_id=current_user.id).aggregate(
        Sum('Quantity'))
    orderqty = orderqty['Quantity__sum']
    #print(orderqty)

    total = 0
    for sctotal in shopcart:
        total += sctotal.Quantity * sctotal.Product.Price
        #print(total)

    if request.method == 'POST':
        form = OrderForm(request.POST)
        #print(form)
        #print(request.POST['First_name'])
        if form.is_valid():
            data = Order()
            data.First_name = form.cleaned_data['First_name']
            data.Last_name = form.cleaned_data['Last_name']
            data.City = form.cleaned_data['City']
            data.Country = form.cleaned_data['Country']
            data.Phone = form.cleaned_data['Phone']
            data.Address = form.cleaned_data['Address']
            data.User_id = current_user.id
            data.Total = total
            data.Ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.Code = ordercode
            #print(ordercode)
            data.save()

            shopcart = ShopCart.objects.filter(User_id=current_user.id)
            for sc in shopcart:
                orderdetails = OrderProduct()
                orderdetails.Order_id = data.id
                orderdetails.User_id = current_user.id
                orderdetails.Product_id = sc.Product_id
                #print(orderdetails.Product_id)
                orderdetails.Quantity = sc.Quantity
                orderdetails.Price = sc.Product.Price
                #orderdetails.Price = sc.price
                orderdetails.Amount = sc.amount
                #orderdetails.Amount = sc.Product.Price * sc.Quantity
                orderdetails.save()

                #Quantity Deduction From Stock
                product = Product.objects.get(id=sc.Product_id)
                product.Amount -= sc.Quantity
                product.save()

            shopcart = ShopCart.objects.filter(
                User_id=current_user.id).delete()
            request.session['cart_items'] = 0
            messages.success(request, 'Your order is completed successfully')
            context = {
                'ordercode': ordercode,
                'category': category,
                'setting': setting,
            }
            return render(request, 'order_complete.html', context)

        else:
            #Need to code another system here. This only for test basis
            print('Form is not valid')
    else:
        #Need to code another system here. This only for test basis
        print('Form is not posted')

    context = {
        'category': category,
        'setting': setting,
        'shopcart': shopcart,
        'orderqty': orderqty,
        'total': total,
        'profile': profile,
    }
    return render(request, 'order_form.html', context)
Esempio n. 30
0
def orderproduct(request):
    category = Category.objects.all()
    current_user = request.user
    shopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in shopcart:
        total += rs.product.price * rs.quantity

    if request.method == 'POST':
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data['first_name']
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.country = form.cleaned_data['country']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode= get_random_string(5).upper()
            data.code = ordercode
            data.save()

            shopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in shopcart:
                detail = OrderProduct()
                detail.order_id = data.id
                detail.product_id = rs.product_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                product = Product.objects.get(id=rs.product_id)
                product.amount -= rs.quantity
                product.save()
                detail.price = rs.product.price
                detail.amount = rs.amount
                detail.save()

            ShopCart.objects.filter(user_id=current_user.id).delete()
            request.session['cart_items']=0
            messages.success(request,"Siparisiniz tamamlandi")
            return render (request, 'order_completed.html',{'ordercode':ordercode,'category':category})
        else:
            messages.warning(request,form.errors)
            return HttpResponseRedirect("/order/orderproduct")


    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'shopcart':shopcart,
        'category':category,
        'total':total,
        'form':form,
        'profile':profile,
    }
    return render(request, 'Order_Form.html',context)

    # if request.method == 'POST':  # form post edildiyse
    #    form= OrderForm(request.POST)
    ##      data = Order()
    #         data=ShopCart.objects.get(product_id=id)
    #        data.quantity+=form.cleaned_data['quantity']
    #       data.save()
    #  else:
    #     data=ShopCart()
    #   data.product_id=id
    # data.quantity=form.cleaned_data['quantity']
    #  data.save()
    #  request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count()
    # messages.success(request, "Ürün başarı ile sepete eklenmiştir. Teşekkür ederiz")
    # return HttpResponseRedirect(url)

    # if request.method == 'POST':  # form post edildiyse
    #    form= OrderForm(request.POST)
    ##      data = Order()
    #         data=ShopCart.objects.get(product_id=id)
    #        data.quantity+=form.cleaned_data['quantity']
    #       data.save()
    #  else:
    #     data=ShopCart()
    #   data.product_id=id
    # data.quantity=form.cleaned_data['quantity']
    #  data.save()
    #  request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count()
    # messages.success(request, "Ürün başarı ile sepete eklenmiştir. Teşekkür ederiz")
    # return HttpResponseRedirect(url)

    #else:
    #   if control == 1:
    #      data = ShopCart.objects.get(product_id=id)
    #     data.quantity += 1
    #    data.save()
    #else:
    #   data = ShopCart()
    #  data.user_id = current_user.id
    # data.product_id = id
    #data.quantity = 1
    #data.save()
    #request.session['cart_items']= ShopCart.objects.filter(user_id=current_user.id).count()
    #messages.success(request, "Ürün başarı ile sepete eklenmiştir. Teşekkür ederiz")
    #return HttpResponseRedirect(url)

    messages.warning(request, "Ürün sepete eklemede hata oluştu.! Lütfen kontrol ediniz...")
    return  HttpResponseRedirect(url)
Esempio n. 31
0
def orderbook(request):
    setting = Setting.objects.get(pk=1)
    category = Category.objects.all()
    current_user = request.user
    schopcart = ShopCart.objects.filter(user_id=current_user.id)
    total = 0
    for rs in schopcart:
        total += rs.book.price * rs.quantity

    if request.method == 'POST':  #if there is a post
        form = OrderForm(request.POST)
        if form.is_valid():
            data = Order()
            data.first_name = form.cleaned_data[
                'first_name']  #get product quantity from form
            data.last_name = form.cleaned_data['last_name']
            data.address = form.cleaned_data['address']
            data.city = form.cleaned_data['city']
            data.country = form.cleaned_data['country']
            data.phone = form.cleaned_data['phone']
            data.user_id = current_user.id
            data.total = total
            data.ip = request.META.get('REMOTE_ADDR')
            ordercode = get_random_string(5).upper()
            data.code = ordercode
            data.save()

            #move shopcart items to order book items
            schopcart = ShopCart.objects.filter(user_id=current_user.id)
            for rs in schopcart:
                detail = OrderBook()
                detail.order_id = data.id  #Order ID
                detail.book_id = rs.book_id
                detail.user_id = current_user.id
                detail.quantity = rs.quantity
                detail.price = rs.book.price
                detail.amount = rs.amount
                detail.save()
                #Reduce quantity of sold  book from Amount Of Book
                book = Book.objects.get(id=rs.book_id)
                book.amount -= rs.quantity
                book.save()
                #*************************************

            ShopCart.objects.filter(
                user_id=current_user.id).delete()  #Clear & Delete  shopcart
            request.session['cart_items'] = 0
            messages.success(request, "Siparişiniz alındı. Teşekkürler")
            return render(
                request, 'Order_Compeleted.html', {
                    'ordercode': ordercode,
                    'category': category,
                    'setting': setting,
                    'page': 'order_completed'
                })
        else:
            messages.warning(request, form.errors)
            return HttpResponseRedirect("/order/orderbook/")

    form = OrderForm()
    profile = UserProfile.objects.get(user_id=current_user.id)
    context = {
        'schopcart': schopcart,
        'category': category,
        'total': total,
        'form': form,
        'profile': profile,
        'setting': setting,
        'page': 'order_form'
    }

    return render(request, 'Order_Form.html', context)