def show_details(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id if User_details.objects.filter(user_id=id).exists(): details = User_details.objects.get(user_id=id) cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "details.html", { "username": username, "no": cart_count, "user": id, "details": details, "category": category, }, ) else: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "details.html", { "username": username, "no": cart_count, "user": id, "category": category, }, ) else: return render(request, "index.html")
def confirm(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) email = user.email product = [] cart = Cart.objects.filter(username=username) cart_count = functions.cart_count(username) for item in cart: prod = Product.objects.get(id=item.product_id) product.append(prod) total = 0 for i in product: price = i.price total = total + price prod_id = " " prod_id = str(prod_id) for item in cart: prod = Product.objects.get(id=item.product_id) produ = str(prod.id) prod_id = prod_id + produ prod_id = prod_id + "," user_id = str(user.id) today = date.today() year = str(today.year) month = str(today.month) day = str(today.day) t = time.localtime() current_time = time.strftime("%H%M%S", t) pay_id = day + month + year + current_time + "_" + user_id # for payement table pay = Payement() pay.id = pay_id pay.user_id = user.id pay.products = prod_id pay.amount = total pay.save() payeeee=Payement.objects.get(id=pay_id) print(payeeee) param_dict = { "MID": "", "ORDER_ID": str(pay_id), "TXN_AMOUNT": str(total), "CUST_ID": email, "INDUSTRY_TYPE_ID": "Retail", "WEBSITE": "WEBSTAGING", "CHANNEL_ID": "WEB", "CALLBACK_URL": "http://127.0.0.1:8000/handlerequest/", } param_dict["CHECKSUMHASH"] = Checksum.generate_checksum( param_dict, MERCHANT_KEY ) return render(request, "paytm.html", {"param_dict": param_dict}) return render(request, "shop/checkout.html")
def addc(request, id): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) cart = Cart() cart.username = username cart.product_id = id cart.save() messages.success(request, "Added to cart successfuly") return redirect("cart") else: messages.error(request, "Please login with your account") return redirect("home")
def aj_addc(request): username = functions.get_username(request) id = request.GET['id'] user = User.objects.get(username=username) cart = Cart() cart.username = username cart.product_id = id try: cart.save() cart_count = functions.cart_count(username) return HttpResponse(cart_count) except: return HttpResponse('false')
def home(request): obj = Product.objects.all() exclusive_products = [] featured_products = [] j = 0 # loop to add exclusive products in the list while j < 4: obj1 = random.choice(obj) temp = 1 for i in range(0, j): ob = exclusive_products[i] if obj1.id == ob.id: temp = 0 break if temp == 1: if obj1.is_exclusive: exclusive_products.append(obj1) j += 1 # loop to add random four products in the list j = 0 while j < 4: obj1 = random.choice(obj) temp = 1 for i in range(0, j): ob = featured_products[i] if obj1.id == ob.id: temp = 0 break if temp == 1: featured_products.append(obj1) j += 1 username = functions.get_username(request) if username is not None: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "index.html", { "obj": exclusive_products, "obj0": featured_products, "username": username, "no": cart_count, "category": category, }, ) else: return render(request, "index.html", {"obj": obje, "obj0": objec})
def cod(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) product = [] cart = Cart.objects.filter(username=username) for item in cart: orde = Orders() prod = Product.objects.get(id=item.product_id) orde.user_id = user.id orde.product_id = prod.id orde.price = prod.price orde.save() messages.success(request, "your order has been placed") Cart.objects.filter(username=username).delete() return redirect("home")
def checkout(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id if user.status == "active": product = [] if Cart.objects.filter(username=username).exists(): cart = Cart.objects.filter(username=username) cart_count = functions.cart_count(username) for item in cart: prod = Product.objects.get(id=item.product_id) product.append(prod) total = 0 for i in product: price = i.price total = total + price total_in_words=functions.no_to_words(str(total)) details = User_details.objects.get(user_id=id) category = functions.get_category(username) return render( request, "checkout.html", { "cart": product, "username": username, "no": cart_count, "total": total, "total_in_words":total_in_words, "details": details, "user": user, "category":category, }, ) else: messages.error(request, "add some products to the cart for checkout") return redirect("home") else: messages.error(request, "please fill you details first and then checkout") return redirect("show_details") else: messages.error(request, "login with your account") return redirect("account")
def details(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "details.html", { "username": username, "no": cart_count, "user": id, "category": category }, ) else: return render(request, "index.html")
def contact(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "contact.html", { "username": username, "no": cart_count, "user": user, "category": category, }, ) else: return render(request, "contact.html")
def mobile(request): mobiles = Product.objects.filter(category="mobile") username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, "category.html", { "obj": mobiles, "username": username, "no": cart_count, "category": category, }, ) else: return render(request, "category.html", {"obj": mobiles})
def cart(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) product = [] cart = Cart.objects.filter(username=username) cart_count = functions.cart_count(username) category = functions.get_category(username) if cart: for item in cart: prod = Product.objects.get(id=item.product_id) product.append(prod) total = 0 for i in product: price = i.price total = total + price return render( request, "cart.html", { "cart": product, "username": username, "no": cart_count, "total": total, "category": category, }, ) else: return render( request, "cart.html", { "username": username, "no": cart_count, "category": category }, ) else: return render(request, "cart.html")
def addcom(request, id): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) prod = Product.objects.get(id=id) if Compare.objects.filter(username=username).exists(): category = functions.get_category(username) if category == prod.category: if Compare.objects.filter(username=username, product_id=id).exists(): messages.error(request, "product already exist in compare section") return redirect("home") else: compare = Compare() compare.username = username compare.product_id = id compare.save() messages.success(request, "Added for compare") return redirect("home") else: Compare.objects.filter(username=username).delete() compare = Compare() compare.username = username compare.product_id = id compare.save() messages.success(request, "Added for compare") return redirect("home") else: compare = Compare() compare.username = username compare.product_id = id compare.save() messages.success(request, "Added for compare") return redirect("home") else: messages.error(request, "Please login with your account") return redirect("home")
def myorders(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id cart_count = functions.cart_count(username) orders = Orders.objects.filter(user_id=id) ordered_products = [] category = functions.get_category(username) for item in orders: prod1 = Product.objects.get(id=item.product_id) ordered_products.append(prod1) return render( request, "myorders.html", { "username": username, "no": cart_count, "product": ordered_products, "orders": orders, "category": category, }, )
def search(request): if request.method == 'POST': username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) id = user.id if User_details.objects.filter(user_id=id).exists(): details = User_details.objects.get(user_id=id) cart_count = functions.cart_count(username) category = functions.get_category(username) cat = request.POST['type'] brand = request.POST['brand'] start = request.POST['from'] to = request.POST['to'] if cat == 'Null': products = Product.objects.filter(brand=brand) elif brand == 'Null': products = Product.objects.filter(category=cat) else: products = Product.objects.filter(brand=brand, category=cat) product = [] for item in products: if item.price >= int(start) and item.price <= int(to): product.append(item) if product: return render( request, 'search.html', { 'obj': product, 'username': username, 'no': cart_count, 'user': id, 'details': details, 'category': category }) else: messages.error(request, 'No products available') return redirect('home') else: cat = request.POST['type'] brand = request.POST['brand'] start = request.POST['from'] to = request.POST['to'] if cat == 'Null': products = Product.objects.filter(brand=brand) elif brand == 'Null': products = Product.objects.filter(category=cat) else: products = Product.objects.filter(brand=brand, category=cat) product = [] for item in products: if item.price >= int(start) and item.price <= int(to): product.append(item) if product: return render(request, 'search.html', {'obj': product}) else: messages.error(request, 'No products available') return redirect('home')
def clear(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) Compare.objects.filter(username=username).delete() return redirect("home")
def product(request, id): print(id) obj2 = Product.objects.get(id=id) rev = functions.review(id) #reviews of the products rel = functions.related(id) # related products if obj2.category == 'mobile': obj3 = Mobile.objects.get(product_id=id) username = functions.get_username(request) if username is not None: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, 'product.html', { 'obj': obj2, 'mobile': obj3, 'username': username, 'no': cart_count, 'category': category, 'review': rev, 'related': rel }) else: return render(request, 'product.html', { 'obj': obj2, 'mobile': obj3, 'review': rev, 'related': rel }) elif obj2.category == 'laptop': obj3 = Laptop.objects.get(product_id=id) username = functions.get_username(request) if username is not None: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, 'product.html', { 'obj': obj2, 'laptop': obj3, 'username': username, 'no': cart_count, 'category': category, 'review': rev, 'related': rel }) else: return render(request, 'product.html', { 'obj': obj2, 'laptop': obj3, 'review': rev, 'related': rel }) elif obj2.category == 'tv': obj3 = Tv.objects.get(product_id=id) username = functions.get_username(request) if username is not None: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, 'product.html', { 'obj': obj2, 'tv': obj3, 'username': username, 'no': cart_count, 'category': category, 'review': rev, 'related': rel }) else: return render(request, 'product.html', { 'obj': obj2, 'tv': obj3, 'review': rev, 'related': rel }) elif obj2.category == 'watch': obj3 = Watch.objects.get(product_id=id) username = functions.get_username(request) if username is not None: cart_count = functions.cart_count(username) category = functions.get_category(username) return render( request, 'product.html', { 'obj': obj2, 'watch': obj3, 'username': username, 'no': cart_count, 'category': category, 'review': rev, 'related': rel }) else: return render(request, 'product.html', { 'obj': obj2, 'watch': obj3, 'review': rev, 'related': rel })
def compare(request): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) if Compare.objects.filter(username=username).exists(): product = [] cart_count = functions.cart_count(username) com = Compare.objects.filter(username=username) for j in com: prod = Product.objects.get(id=j.product_id) print(prod) product.append(prod) category = prod.category det = [] if category == "mobile": for n in product: details = Mobile.objects.get(product_id=n.id) det.append(details) return render( request, "compare.html", { "username": username, "no": cart_count, "category": category, "mobile": det, }, ) elif category == "laptop": for n in product: details = Laptop.objects.get(product_id=n.id) det.append(details) return render( request, "compare.html", { "username": username, "no": cart_count, "category": category, "laptop": det, }, ) elif category == "tv": for n in product: details = Tv.objects.get(product_id=n.id) det.append(details) return render( request, "compare.html", { "username": username, "no": cart_count, "category": category, "tv": det, }, ) elif category == "watch": for n in product: details = Watch.objects.get(product_id=n.id) det.append(details) return render( request, "compare.html", { "username": username, "no": cart_count, "category": category, "watch": det, }, ) else: messages.error(request, "Add some products to Compare") return redirect("home") else: messages.error(request, "Please login with your account") return redirect("home")
def remove(request, id): username = functions.get_username(request) if username is not None: user = User.objects.get(username=username) Cart.objects.filter(product_id=id, username=username).delete() return redirect("cart")