Пример #1
0
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')

    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])
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
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)
Пример #8
0
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)
Пример #9
0
def addtocart(request, id):
    url = request.META.get('HTTP_REFERER')
    current_user = request.user
    #***** ürün sepette var mı kontrolü****
    checkproduct = Shopcart.objects.filter(product_id=id)
    if checkproduct:
        control = 1
    else:
        control = 0

    if request.method == 'POST':  #ürün detaydan geldiyse
        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()
                messages.success(request, "Ürün başarı ile güncellenmiştir.")
                return HttpResponseRedirect(url)
            else:  #ürün yoksa
                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.")
                return HttpResponseRedirect(url)
        request.session['cart_items'] = Shopcart.objects.filter(
            user_id=current_user.id).count()

    else:  # direkt sepete eklendiyse
        if control == 1:  # ürün varsa güncelle
            data = Shopcart.objects.get(product_id=id)
            data.quantity += 1
            data.save()
            messages.success(request, "Ürün başarı ile güncellenmiştir.")
            return HttpResponseRedirect(url)
        else:  # ürün yoksa
            data = Shopcart()
            data.user_id = current_user.id
            data.product_id = id
            data.quantity = 1
            data.save()
            messages.success(request, "Ürün başarı ile sepete eklenmiştir.")
            return HttpResponseRedirect(url)
        request.session['cart_items'] = Shopcart.objects.filter(
            user_id=current_user.id).count()
    messages.warning(request, "Ürün sepete eklenemedi hata oluştu")
    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)
Пример #11
0
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)
Пример #12
0
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)
Пример #13
0
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)
Пример #14
0
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)
Пример #15
0
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') #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)
Пример #17
0
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)
Пример #18
0
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)
Пример #19
0
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)
Пример #20
0
def product(request,proid):

    product = Product.objects.get(pk=proid)
    images= ProductImage.objects.filter(product=proid)
    form=ShopCartForm()
    context= {'page':'products',
              'product': product,
              'images': images,
              'form':form,
              }
    return render(request,"detail.html",context)
Пример #21
0
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)
Пример #22
0
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 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)
Пример #24
0
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)
Пример #25
0
def product(request,proid):

    product = Product.objects.get(pk=proid)
    images= Images.objects.filter(product=proid)
    comments = Comment.objects.filter(product=proid,status=1).order_by('-id')
    form = ShopCartForm()
    cform = CommentForm()
    context = {'page': 'products',
               'product': product,
               'comments': comments,
               'images': images,
               'form':form,
               'cform': cform,
               }

    return render(request, "product_detail.html",context)
def product_detail(request, product_id):
    product = get_object_or_404(Product, pk=product_id)
    form = ReviewForm()
    form = ShopCartForm()
    return render(request, 'shop/product_detail.html', {'product': product, 'form': form})