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) variantid = request.POST.get('variantid') 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 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 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)
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') # 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 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 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') 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 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 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 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 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') #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 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)