def shop_cart_add(request, proid): url = request.META.get('HTTP_REFERER') form = ShopCartForm(request.POST or None) if request.method == 'POST': if form.is_valid(): current_user = request.user quantity = form.cleaned_data['quantity'] try: q1 = ShopCart.objects.get(user_id=current_user.id, product_id=proid) except ShopCart.DoesNotExist: q1 = None if q1 != None: q1.quantity = q1.quantity + quantity q1.save() else: data = ShopCart(user_id=current_user.id, product_id=proid, quantity=quantity) data.save() request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() messages.success(request, "product added to cart") return HttpResponseRedirect(url) return HttpResponseRedirect('product', args=[proid])
def shop_cart_add(request,proid): # if this is a POST request we need to process the form data url = request.META.get('HTTP_REFERER') # Bir önceki adresi alır # return HttpResponse(url) form = ShopCartForm(request.POST or None) if request.method == 'POST': # check whether it's valid: if form.is_valid(): current_user = request.user # Get User id quantity = form.cleaned_data['quantity'] #get product quantity from form # Checking product in ShopCart try: q1 = ShopCart.objects.get(user_id=current_user.id, product_id=proid) except ShopCart.DoesNotExist: q1 = None if q1 != None: # Update quantity to exist product quantity q1.quantity = q1.quantity + quantity q1.save() else: # Add new item to shop cart data = ShopCart(user_id=current_user.id, product_id=proid, quantity=quantity) data.save() request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() #Count item in shop cart messages.success(request, "Product added to cart.. ") return HttpResponseRedirect(url) return HttpResponseRedirect(reverse('product', args=[proid]))
def shop_cart_add(request, proid): url = request.META.get('HTTP_REFERER') if request.method == 'POST': current_user = request.user quantity = request.POST['quantity'] try: q1 = ShopCart.objects.get(user_id=current_user.id, product_id=proid) except ShopCart.DoesNotExist: q1 = None if q1 != None: q1.quantity = q1.quantity + int(quantity) q1.save() else: data = ShopCart(user_id=current_user.id, product_id=proid, quantity=quantity) data.save() request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() messages.success(request, "Ürün sepete eklendi...") return HttpResponseRedirect(url) return HttpResponseRedirect(reverse('product', args=[proid]))
def addtocart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 1 else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = form.cleaned_data['quantity'] data.save() 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)
def addurun(request, id): url = request.META.get("HTTP_REFERER") # get last url if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): current_user = request.user #Access User Session information if (ShopCart.objects.filter(urun_id=id)): data = ShopCart.objects.get(urun_id=id) data.ay += form.cleaned_data[ 'ay'] #tekrar ev eklenmişse ay larını birleştiriyo data.save() else: data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id #current yani mevcut user data.urun_id = id data.ay = form.cleaned_data['ay'] #hocanin ki quantity data.save() # veritabanına kaydet request.session['cart_item'] = ShopCart.objects.filter( user_id=current_user.id).count() messages.success(request, "Ev başarıyla eklendi.") return HttpResponseRedirect(url) #return HttpResponse("Kaydedildi") else: messages.warning(request, "Ev gönderilemedi. Lütfen tekrar deneyiniz.") return HttpResponseRedirect(url)
def addtocart(request, id): current_user = request.user qty = 0 checkproduct = ShopCart.objects.filter(user_id=current_user.id, product_id=id) if checkproduct: # if product exist in cart if request.method == 'POST': # if there is a post qty = request.POST.get('qty') shopcart = ShopCart.objects.get(user_id=current_user.id, product_id=id) shopcart.quantity += int(qty) shopcart.save() else: # if doesnot exist if request.method == 'POST': # if there is a post qty = request.POST.get('qty') shopcart = ShopCart() shopcart.user = current_user shopcart.product = Product.objects.get(id=id) shopcart.quantity = qty shopcart.save() url = request.META.get('HTTP_REFERER') return HttpResponseRedirect(url)
def addtocart(request,id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 1 #sepette aynı üründen var else: control = 0 #sepette aynı üründen yok if request.method == 'POST': # if there is a post form = ShopCartForm(request.POST) if form.is_valid(): if control==1: data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = form.cleaned_data['quantity'] data.save() messages.success(request, "The product was successfully added to the basket.") return HttpResponseRedirect(url) messages.warning(request,"Error") return HttpResponseRedirect(url)
def shop_cart_add(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user product = Item.objects.get(pk=id) check_item = ShopCart.objects.filter(item__id=id, user_id=current_user.id) if check_item: control = 1 # Ürün Sepette Varsa else: control = 0 # Ürün Sepette Yoksa if request.method == 'POST': form = ShopCartForm(request.POST or None) if form.is_valid(): if control == 1: # Ürün Sepette Varsa Güncelle data = ShopCart.objects.get(item_id=id, user_id=current_user.id) data.quantity += form.cleaned_data['quantity'] data.beden = request.POST.get('beden') data.save() messages.success( request, "Ürün Sepete Eklenerek Sayısı Güncellenmiştir. Sepetinizi Kontrol Ediniz." ) else: # Ürün Sepette Yoksa Ekle data = ShopCart() data.user_id = current_user.id data.item_id = id data.quantity = form.cleaned_data['quantity'] data.beden = request.POST.get('beden') data.save() messages.success( request, "Ürün Başarı İle Sepete Eklenmiştir. Sepetinizi Kontrol Ediniz." ) else: messages.warning(request, "Lütfen Beden Seçiniz.") request.session['cart_items'] = ShopCart.objects.filter( user__id=current_user.id).count() return HttpResponseRedirect(url) else: messages.warning(request, "Lütfen Beden Seçiniz.") messages.warning( request, "Ürün Sepete Eklemede Bir Hata Oluştu. Lütfen Sepetinizi Kontrol Ediniz. " ) return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') # get last url if request.method == 'POST': # form post edildiyse form = ShopCartForm(request.POST) if form.is_valid(): current_user = request.user data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id 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 sepetinize eklenmiştir.Teşekkür Ederiz.") return HttpResponseRedirect(url) messages.warning(request, "Ürün sepete eklenemedi.") return HttpResponseRedirect(url)
def addtoshopcart(request,id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user # Access User Session information product= Product.objects.get(pk=id) if product.variant != 'None': variantid = request.POST.get('variantid') # from variant add to cart checkinvariant = ShopCart.objects.filter(variant_id=variantid, user_id=current_user.id) # Check product in shopcart if checkinvariant: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart""" else: checkinproduct = ShopCart.objects.filter(product_id=id, user_id=current_user.id) # Check product in shopcart if checkinproduct: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart""" if request.method == 'POST': # if there is a post form = ShopCartForm(request.POST) if form.is_valid(): if control==1: # Update shopcart variantid = request.POST.get('variantid') # from variant add to cart if product.variant == 'None': data = ShopCart.objects.get(product_id=id, user_id=current_user.id) else: data = ShopCart.objects.get(product_id=id, variant_id=variantid, user_id=current_user.id) #data.quantity += form.cleaned_data['quantity'] #qte sera ajouter à la qte déja existait data.quantity = form.cleaned_data['quantity'] # qte sera remplacer la qte precedente data.save() # save data else : # Insert to Shopcart data = ShopCart() data.user_id = current_user.id data.product_id =id # data.variant_id = variantid data.quantity = form.cleaned_data['quantity'] data.save() messages.success(request, "Product added to Shopcart via F ") return HttpResponseRedirect(url) else: # if there is no post if control == 1: # Update shopcart data = ShopCart.objects.get(product_id=id, user_id=current_user.id) #data.quantity += 1 #qte 1 sera ajoutée data.quantity = 1 #qte 1 sera remplacée la qté precedente data.save() # else: # Inser to Shopcart data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id data.product_id = id data.quantity = 1 data.variant_id =None data.save() # messages.success(request, "Product added to Shopcart") return HttpResponseRedirect(url)
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') #get last url current_user = request.user product= Product.objects.get(pk=id) checkinproduct = ShopCart.objects.filter(product_id=id, user_id=current_user.id) # Check product in shopcart if checkinproduct: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart""" if request.method == "POST": if control == 1: data = ShopCart.objects.get(product_id=id,user_id=current_user.id) data.quantity += int(request.POST.get("quantity")) data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = request.POST.get("quantity") data.save() messages.success(request, "Product added to shopcart ") return HttpResponseRedirect(url) else: if control == 1: data = ShopCart.objects.get(product_id=id,user_id=current_user.id) data.quantity += 1 data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = 1 data.save() messages.success(request, "Product added to shopcart") return HttpResponseRedirect(url) return render(request, 'index.html')
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user # Access User Session information product = Product.objects.get(pk=id) if product.amount == 0: messages.success(request, "Product Out of Stock! Sorry!") return HttpResponseRedirect(url) variantid = None if product.variant != "None": variantid = request.POST.get('variantid') # from variant add to cart checkinvariant = ShopCart.objects.filter( variant_id=variantid, user_id=current_user.id) # Check product in shopcart if checkinvariant: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart""" else: checkinproduct = ShopCart.objects.filter( product_id=id, user_id=current_user.id) # Check product in shopcart if checkinproduct: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart""" if request.method == 'POST': # if there is a post form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: # Update shopcart if product.variant == 'None': data = ShopCart.objects.get(product_id=id, user_id=current_user.id) else: data = ShopCart.objects.get(product_id=id, variant_id=variantid, user_id=current_user.id) data.quantity += form.cleaned_data['quantity'] data.save() # save data else: # Inser to Shopcart data = ShopCart() data.user_id = current_user.id data.product_id = id if variantid is not None: data.variant.id = variantid data.quantity = form.cleaned_data['quantity'] data.save() messages.success(request, "Product added to Shopcart ") return HttpResponseRedirect(url) else: # if there is no post> if control == 1: # Update shopcart data = ShopCart.objects.get(product_id=id, user_id=current_user.id) data.quantity += 1 data.save() else: # Inser to Shopcart data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id data.product_id = id data.quantity = 1 data.variant_id = None data.save() # messages.success(request, "Product added to Shopcart") return HttpResponseRedirect(url)
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user variantid = request.POST.get('variantid') checkinproduct = ShopCart.objects.filter(product_id=id) checkinvariant = ShopCart.objects.filter(variant_id=variantid) if checkinproduct and checkinvariant: control = 1 # the product is in cart else: control = 0 # the product is not in cart if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.variant_id = variantid data.quantity = form.cleaned_data['quantity'] data.save() messages.success(request, " Product Added to Shopping Cart ") return HttpResponseRedirect(url) else: # if there is no post if control == 1: # Update shopcart 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.variant_id = None data.save() messages.success(request, " Product Added To ShopCart") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user #access user session information #****** ÜRÜN SEPETTE Mİ KONTROLÜ ******* checkproduct = ShopCart.objects.filter(product_id=id) #ürün sepette mi? if checkproduct: control = 1 #ürün sepette else: control = 0 #ürün sepette değil if request.method == 'POST': #ÜRÜN DETAY SAYFASINDAN EKLE BUTONUNA BASINCA form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: #ürün varsa güncelle data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() #db kaydı else: #ürün yoksa ekle data = ShopCart() #model ile bağlantı data.user_id = current_user.id data.product_id = id data.quantity = form.cleaned_data['quantity'] data.save() #db kaydı request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() #listedekileri sayar messages.success(request, "Ürün eklenmiştir. Sporla Kalın!") return HttpResponseRedirect(url) else: #ANASAYFADAN EKLE BUTONUNA BASINCA if control == 1: # ürün varsa güncelle data = ShopCart.objects.get(product_id=id) data.quantity += 1 data.save() # db kaydı else: # ürün yoksa ekle data = ShopCart() # model ile bağlantı data.user_id = current_user.id data.product_id = id data.quantity = 1 data.save() # db kaydı request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() # listedekileri sayar messages.success(request, "Ürün eklenmiştir. Sporla Kalın!") return HttpResponseRedirect(url) messages.warning(request, "Ürün kaydı yapılamamıştır.") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user checkbook = ShopCart.objects.filter(book_id=id) if checkbook: control = 1 #ürün sepette var else: control = 0 #ürün sepette yok if request.method == 'POST': # Form post edildiyse, ürün detay sayfasından geldiyse form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: # ürün varsa güncelle data = ShopCart.objects.get( book_id=id) # get 1 eleman çağırır,filtre liste cağırır data.quantity += form.cleaned_data['quantity'] data.save() # ver,tabanına kaydet else: # ürün yoksa ekle data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id data.book_id = id data.quantity = form.cleaned_data['quantity'] data.save() # veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() messages.success( request, "Ürün basari ile sepete eklenmiştir.Teşekkür Ederiz") return HttpResponseRedirect(url) else: #ürün direk sepette ekle butonuna basıldıysa if control == 1: # ürün varsa güncelle data = ShopCart.objects.get(book_id=id) data.quantity += 1 data.save() else: # ürün yoksa ekle data = ShopCart() data.user_id = current_user.id data.book_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 basari ile sepete eklenmiştir.Teşekkür Ederiz") return HttpResponseRedirect(url) messages.warning(request, form.errors) return HttpResponseRedirect(url)
def addtocart(request,id): url = request.META.get('HTTP_REFERER') current_user = request.user checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 1 else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): #detailden tıklandıysa if control==1: #ürün varsa data = ShopCart.objects.get(product_id=id) data.user_id = current_user.id data.quantity += form.cleaned_data['quantity'] data.save() else: #ürün yoksa data= ShopCart() data.user_id = current_user.id 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, "Araç Başarılı Bir Şekilde Sepetinize Eklenmiştir..") return HttpResponseRedirect(url) else: #contentten tıklandıysa if control == 1: # ürün varsa data = ShopCart.objects.get(product_id=id) data.user_id = current_user.id data.quantity += 1 data.save() else: # ürün yoksa 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, "Araç Başarılı Bir Şekilde Sepetinize Eklenmiştir..") return HttpResponseRedirect(url) messages.warning(request, "Sepete Eklemede Hata Oluştu..") return HttpResponseRedirect(url)
def addtocart(request,id): url = request.META.get('HTTP_REFERER') current_user = request.user checkbook = ShopCart.objects.filter(book_id=id) if checkbook: control = 1 # The product is in the cart else: control = 0 # not if request.method == 'POST': # if there is a post form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: # Update shopcart data = ShopCart.objects.get(book_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id data.book_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, 'product added to cart') return HttpResponseRedirect(url) else: # if there is no post if control == 1: # Update shopcart data = ShopCart.objects.get(book_id=id) data.quantity += 1 data.save() else: data = ShopCart() data.user_id = current_user.id data.book_id = id data.quantity = 1 data.save() request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() messages.success(request, 'product added to cart') return HttpResponseRedirect(url) messages.warning(request,'adding product failed') return HttpResponseRedirect(url)
def addtocart(request,id): url = request.META.get('HTTP_REFERER') checkproduct = ShopCart.objects.filter(product_id=id) current_user =request.user if checkproduct: control =1 else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data =ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id 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ılı şekilde Sepete eklendi") return HttpResponseRedirect(url) else : if control == 1: data = ShopCart.objects.get(product_id=id) data.quantity += 1 data.save() request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() return HttpResponseRedirect(url) else: current_user = request.user 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ılı şekilde Sepete eklendi") return HttpResponseRedirect(url)
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 2 else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.color = form.cleaned_data['color'] data.size = form.cleaned_data['size'] data.save() else: data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = form.cleaned_data['quantity'] data.color = form.cleaned_data['color'] data.size = form.cleaned_data['size'] data.save() messages.success(request, "product added to shopcart") 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() messages.success(request, "product added to shopcart") return HttpResponseRedirect(url)
def addtocart(request,id): url = request.META.get('HTTP_REFERER') #get last url current_user = request.user #*******ürün sepette var mı kontrolü******* checkfood = ShopCart.objects.filter(Food_id=id) if checkfood: control = 1 #ürün sepette var else: control = 0 #ürün sepette yok if request.method == 'POST': #form post edildiyse food_detail dan form = ShopCartForm(request.POST) if form.is_valid(): #geçerli mi csrf kontrolü if control == 1: #ürün varsa güncelle data = ShopCart.objects.get(Food_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: #ürün yoksa ekle data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id data.Food_id = id data.quantity = form.cleaned_data['quantity'] data.save() request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() #sepetteki ürünlerin sayısı alındı messages.success(request, "Ürün başarı ile sepete eklenmiştir. Teşekkür ederiz") return HttpResponseRedirect(url) else: #ürün direk sepete ekle ile geldiyse if control == 1: # ürün varsa güncelle data = ShopCart.objects.get(Food_id=id) data.quantity += 1 data.save() else: #ürün yoksa ekle data = ShopCart() #model ile bağlantı kur data.user_id = current_user.id data.Food_id = id data.quantity = 1 data.save() #veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() #sepetteki ürünlerin sayısı alındı messages.success(request, "Ürün başarı ile sepete eklenmiştir. Teşekkür ederiz") return HttpResponseRedirect(url) messages.warning(request, "Ürün sepete eklenemedi. Lütfen kontrol ediniz") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') checkproduce = ShopCart.objects.filter(produce_id=id) if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): current_user = request.user data = ShopCart() data.user_id = current_user.id data.produce_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 eklendi.Teşekkür ederiz") return HttpResponseRedirect(url) else: current_user = request.user data = ShopCart() data.user_id = current_user.id data.produce_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 eklendi.Teşekkür ederiz") return HttpResponseRedirect(url) messages.warning(request, "Ürün sepete eklemede hata oluştu.Lütfen kontrol ediniz") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user scart = ShopCart.objects.filter(produce_id=id) if scart: control = 1 else: control = 0 if request.method == 'POST': #ürün formdan geldiyse form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart.objects.get(produce_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id data.produce_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 sepete eklendi") return HttpResponseRedirect(url) else: #ürün direk eklendiyse if control == 1: data = ShopCart.objects.get(produce_id=id) data.quantity += 1 data.save() else: data = ShopCart() data.user_id = current_user.id data.produce_id = id data.quantity = 1 data.save() messages.success(request, "Ürün sepete eklendi") return HttpResponseRedirect(url) request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() messages.warning(request, "Ürün eklemede hata oluştu") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user #Access User Session Information ##########ÜRÜN SEPETTE VAR MI KONTROLÜ########### checkbook = ShopCart.objects.filter(book_id=id) if checkbook: control = 1 #ürün sepette var else: control = 0 #ürün sepette yok if request.method == 'POST': #form post edildiyse ÜRÜN SAYFASINDAN SEPETE EKLENDİYSE form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: #ürün varsa güncelle data = ShopCart.objects.get(book_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: #ürün yoksa ekle data = ShopCart() #model ile bağlantı kur data.user_id = current_user.id data.book_id = id data.quantity = form.cleaned_data['quantity'] data.save() #veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() # count item in shop cart messages.success(request, "Kitap sepete eklendi.") return HttpResponseRedirect(url) else: #ÜRÜN ANASAYFADAN SEPETE EKLENDİYSE if control == 1: # ürün varsa güncelle data = ShopCart.objects.get(book_id=id) data.quantity += 1 data.save() else: # ürün yoksa ekle data = ShopCart() # model ile bağlantı kur data.user_id = current_user.id data.book_id = id data.quantity = 1 data.save() # veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter( user_id=current_user.id).count() # count item in shop cart messages.success(request, "Kitap sepete eklendi.") return HttpResponseRedirect(url) messages.warning(request, "Bir şeyler ters gitti!") return HttpResponseRedirect(url)
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') # get last url current_user = request.user # Access User Session information checkproduct = ShopCart.objects.filter(product_id=id) # Check product in shopcart if checkproduct: control = 1 # The product is in the cart else: control = 0 # The product is not in the cart if request.method == 'POST': # if there is a post form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: # Update shopcart data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: # Insert to Shopcart data = ShopCart() data.user_id = current_user.id data.product_id = id data.quantity = form.cleaned_data['quantity'] data.save() messages.success(request, "Product added to ShopCart") return HttpResponseRedirect(url) else: # if there is no post if control == 1: # Update shopcart data = ShopCart.objects.get(product_id=id) data.quantity += 1 data.save() # else: # Insert to shopcart data = ShopCart() # model data.user_id = current_user.id data.product_id = id data.quantity = 1 data.save() # messages.success(request, "Product added to ShopCart") return HttpResponseRedirect(url)
def addtoshopcart(request, id): url = request.META.get('HTTP_REFERER') current_user = request.user checkproduct = ShopCart.objects.filter(Product_id=id, User_id=current_user.id) if checkproduct: control = 1 else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart.objects.get(Product_id=id, User_id=current_user.id) data.Quantity += form.cleaned_data['Quantity'] data.save() else: data = ShopCart() data.User_id = current_user.id data.Product_id = id data.Quantity = form.cleaned_data['Quantity'] data.save() messages.success(request, 'Product Added to Shop Cart') else: if control == 1: data = ShopCart.objects.get(Product_id=id, User_id=current_user.id) data.Quantity += 1 data.save() else: data = ShopCart() data.User_id = current_user.id data.Product_id = id data.Quantity = 1 data.save() messages.success(request, 'Product Added to Shop Cart') return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') #GET LAST URL current_user=request.user #Access User Session information checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 1 #The product is in the cart else: control = 0 #The product is not in the cart if request.method == 'POST': #form Post edildiyse form = ShopCartForm(request.POST) if form.is_valid(): if control == 1: data = ShopCart() #model ile bğlantı kur data.user_id = current_user.id data.quantity += form.cleaned_data['quantity'] data.save() #veritabanına kaydet else: data = ShopCart() #model ile bğlantı kur data.user_id = current_user.id data.product_id=id data.quantity = form.cleaned_data['quantity'] data.save() #veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() #count item in the shop cart messages.success(request, "Ürün başarı ile sepete eklenmişdir. Teşekkür ederiz") return HttpResponseRedirect(url) #return HttpResponse("Kaydedildi") else: if control == 1: data = ShopCart.objects.get(product_id=id) #model ile bğlantı kur data.quantity = 1 data.save() #veritabanına kaydet else: data = ShopCart() #model ile bğlantı kur data.user_id = current_user.id data.product_id = id data.quantity = 1 data.save() #veritabanına kaydet request.session['cart_items'] = ShopCart.objects.filter(user_id=current_user.id).count() #count item in the shop cart messages.success(request, "Ürün başarı ile sepete eklenmişdir. Teşekkür ederiz") return HttpResponseRedirect(url) messages.warning(request, "Urün sepete eklemede hata oluştu!, Lütfen tekrar kontrol ediniz") return HttpResponseRedirect(url)
def addtocart(request, id): url = request.META.get('HTTP_REFERER') #urli alır current_user = request.user #Access User Session Information checkproduct = ShopCart.objects.filter(product_id=id) if checkproduct: control = 1 #ürün sepette var else: control = 0 if request.method == 'POST': form = ShopCartForm(request.POST) if form.is_valid: if control == 1: #ürün varsa güncelle data = ShopCart.objects.get(product_id=id) data.quantity += form.cleaned_data['quantity'] data.save() else: data = ShopCart() data.user_id = current_user.id 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: #sepete ekleye basılınca if control == 1: # ürün varsa güncelle data = ShopCart.objects.get(product_id=id) data.quantity += 1 data.save() else: data = ShopCart() #model ile bağlantı kur 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)