def buyProduct(request, product_id): amount = request.POST.get('amount', 1) try: product = Product.objects.get(id=product_id) order = Order() order.client = request.META["REMOTE_ADDR"] order.details = "is buying the product " + product.name + " in MINITRADE" order.total = product.price * int(amount) order.status = "created" order.save() orderProduct = OrderProduct() orderProduct.product = product orderProduct.order = order orderProduct.amount = amount orderProduct.total = product.price * int(amount) orderProduct.save() callback_url = "https://{0}/finish_buy/{1}/".format(request.get_host(), order.id) response = createPayRequest(order, callback_url) order.token = response['token'] order.status = response['status'] order.save() return HttpResponse(json.dumps({ "url": response['url'] }), status=200) except Exception as e: # import traceback # traceback.print_exc() return HttpResponse(json.dumps({ "error": str(e), "message": "The transaction could not be created!" }), status=500)
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)
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)
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)
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)
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)
def post(self, request, *args, **kwargs): current_user = request.user shopcart = ShopCart.objects.filter(user_id=self.request.user.id) total = 0 count = 0 for rs in shopcart: total += rs.product.price * rs.quantity count += rs.quantity form = OrderPaymentForm(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.payment_option = form.cleaned_data['payment_option'] 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.count_sold += 1 product.amount -= rs.quantity product.save() if data.payment_option == "S": return redirect('payment', payment_option="stripe") if data.payment_option == "P": return redirect('payment', payment_option="paypal") messages.info(self.request, "Invalid payment option") return redirect('checkout') else: return redirect('checkout')
def siparis(request, id): setting = Setting.objects.get(pk=1) category = Category.objects.all() current_user = request.user # #Access User Session information, şu anki userin bilgilerini aliyor schopcart = ShopCart.objects.get(pk=id) total = schopcart.ay * schopcart.urun.price if id: #shopcartdan id gelmisse data = Order() # order modeline baglaniyor data.user_id = current_user.id #bilgileri Order veritabanina aktariyor data.status = 'New' data.total = total data.ip = request.META.get('REMOTE_ADDR') data.save() #aktarilan verileri kaydediyor schopcart = ShopCart.objects.get( pk=id) #Shopcartdan gelen idli veriyi OrderProducta ekliyor #orderproducta ekleme detail = OrderProduct() #orderproductta baglaniiyor detail.order_id = data.id detail.urun_id = schopcart.urun_id detail.user_id = current_user.id detail.ay = schopcart.ay detail.price = schopcart.urun.price detail.amount = schopcart.amount detail.status = 'New' detail.save() ShopCart.objects.get( pk=id).delete() #shopcartdan alinan veriyi siliyor prodata = Property.objects.get( pk=schopcart.urun_id) #shopcartdan siparis verilen urunu aliyor prodata.status = "False" #statusunu false yapiyor prodata.save() messages.success( request, 'Siparisiniz Basariyla Alinmistir') #basarili islem mesaji context = { 'setting': setting, 'category': category, 'shopcart': schopcart, 'total': total, } return HttpResponseRedirect('/user/orders') #user orderse gonderiyor else: messages.warning(request, "Siparis Alinamadi") #basarisiz islem return HttpResponseRedirect('/user/shopcart') #shopcartda kaliyor
def checkout(request): current_user = request.user shopcart = ShopCart.objects.filter(user_id = current_user.id) total = 0 q = 0 for s in shopcart: total += s.product.price * s.quantity q += s.quantity setting = Setting.objects.all() catagories = ProductCategories.objects.all() data = Order() if request.method == "POST": data.full_name = request.POST.get("name") data.address = request.POST.get("address") data.city = request.POST.get("city") data.country = request.POST.get("country") data.phone = request.POST.get("tel") data.user_id = current_user.id data.ip = request.META.get('REMOTE_ADDR') data.total = total 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 = total detail.save() ShopCart.objects.filter(user_id=current_user.id).delete()#clear and delete shopcart messages.success(request,"Your order has been completed. Thank you.") return render(request, 'order_Completed.html',{'orderCode':orderCode,'category':catagories}) context = { "catagories":catagories, "setting":setting, 'total':total, 'q':q, } return render(request, 'checkout.html',context=context)
def order(request, id): if request.method == "POST": current_user = request.user whole_total = 0 shopcart = ShopCart.objects.filter(user_id=current_user.id) for each in shopcart: whole_total += each.price * each.quantity # add the total price of cart items #for order model order = Order() order.user = current_user order.code = "oppps" order.first_name = request.POST.get('first_name') order.last_name = request.POST.get('last_name') order.phone = request.POST.get('phone') order.email = request.POST.get('email') order.address = request.POST.get('address') order.address_desc = request.POST.get('address_desc') order.city = request.POST.get('city') order.total = whole_total order.status = request.POST.get('status') order.save() # for order product model for items in shopcart: orderproduct = OrderProduct() orderproduct.user = current_user # orderproduct.user = items.user orderproduct.order = Order.objects.get(id=order.id) # cart_items = ShopCart.objects.filter(user_id= current_user.id) # orderproduct.product = Product.objects.get(id = items.product.id) orderproduct.product = items.product orderproduct.quantity = items.quantity orderproduct.amount = 5 orderproduct.price = 1200 orderproduct.save() url = request.META.get('HTTP_REFERER') return HttpResponseRedirect(url)
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)
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
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)
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)
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)
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)
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)
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)
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)
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)