def return_add_orders_from_cart(request): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') kargo = float(Settings.objects.filter(name='kargo')[0].value) products = Product.objects.all() current_user = request.user profile = Profile.objects.get(user=current_user) order_form = OrderForm( initial={ 'address': profile.address, 'city': profile.city, 'district': profile.district, 'guest_user': None }) order_form.fields['city'].queryset = City.objects.filter( id=profile.city_id) myDict = dict(request.GET) urun_miktar = [] urun_miktar_2 = [] myDict2 = dict() for key in myDict: if key.startswith('cust'): pickup_dict = dict() x = myDict[key][0].split("&") x = CartObject(product_id=x[0], quantity=x[1]) urun_miktar.append(x) pickup_dict['product_id'] = x.product_id pickup_dict['quantity'] = x.quantity urun_miktar_2.append(pickup_dict) myDict2['deneme'] = urun_miktar serializer = CartSerializer(urun_miktar, many=True) data = json.dumps(serializer.data) # data = serializers.serialize('json', myDict2) # serializer = CartSerializer(urun_miktar, many=True) # data = serializer.data if request.method == 'POST': order_form = OrderForm(request.POST) if order_form.is_valid(): total_price = 0 products_quantity = order_form.cleaned_data['droptxt'] products_quantity = products_quantity.split(',') order_product_card = [] order = Order(profile=profile, city=order_form.cleaned_data['city'], district=order_form.cleaned_data['district'], address=order_form.cleaned_data['address'], payment_type=order_form.cleaned_data['payment_type'], isContract=order_form.cleaned_data['isContract'], otherAddress=request.POST['diger_adres'], companyInfo=request.POST['kurumsal_bilgi']) order.isContract = order_form.cleaned_data['isContract'] order.save() for products_q in products_quantity: product = products_q.split('x') prod = Product.objects.get(id=int(product[1].strip())) orderProduct = OrderProduct(order=order, product=prod, quantity=int(product[0].strip())) orderProduct.save() order_product_card.append(orderProduct) total_price = total_price + (int(product[0].strip()) * prod.price) if total_price >= 150: order.totalPrice = total_price else: order.totalPrice = float(total_price) + kargo order.save() # order.product.add(order_form.cleaned_data['product']) order.order_situations.add( OrderSituations.objects.get(name='Ödeme Bekliyor')) order.save() if order.payment_type == 'Havale/EFT': messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:havale-eft-bilgi', siparis=order.id) else: messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:odeme-yap', siparis=order.id) else: messages.warning(request, 'Alanları Kontrol Ediniz') return render( request, 'siparisler/siparis-ekle.html', { 'order_form': order_form, 'products': products, 'product_array': data, 'profile': profile, 'kargo': kargo })
def return_add_orders_admin(request): perm = general_methods.control_access(request) if not perm: logout(request) return redirect('accounts:login') kargo = float(Settings.objects.filter(name='kargo')[0].value) order_form = OrderFormAdmin(instance=Profile.objects.get( user=request.user)) products = Product.objects.all() current_user = request.user profile = Profile.objects.get(user=current_user) if request.method == 'POST': order_form = OrderFormAdmin(request.POST) if order_form.is_valid(): total_price = 0 products_quantity = order_form.cleaned_data['droptxt'] products_quantity = products_quantity.split(',') order_product_card = [] order = Order(profile=order_form.cleaned_data['profile'], city=order_form.cleaned_data['city'], district=order_form.cleaned_data['district'], address=order_form.cleaned_data['address'], payment_type=order_form.cleaned_data['payment_type'], isContract=order_form.cleaned_data['isContract'], otherAddress=request.POST['diger_adres'], companyInfo=request.POST['kurumsal_bilgi']) order.isContract = order_form.cleaned_data['isContract'] order.save() for products_q in products_quantity: product = products_q.split('x') prod = Product.objects.get(id=int(product[1].strip())) orderProduct = OrderProduct(order=order, product=prod, quantity=int(product[0].strip())) orderProduct.save() order_product_card.append(orderProduct) total_price = total_price + (int(product[0].strip()) * prod.price) if order.cargo.status: if total_price >= order.cargo.lower_limit: order.totalPrice = total_price else: # order.totalPrice = float(total_price) + kargo order.totalPrice = float(total_price) + float( order.cargo.price) order.save() # order.product.add(order_form.cleaned_data['product']) order.order_situations.add( OrderSituations.objects.get(name='Ödeme Bekliyor')) order.save() if order.payment_type == 'Havale/EFT': messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:havale-eft-bilgi', siparis=order.id) else: messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:odeme-yap', siparis=order.id) else: messages.warning(request, 'Alanları Kontrol Ediniz') return render( request, 'siparisler/siparis-ekle.html', { 'order_form': order_form, 'products': products, 'profile': profile, 'kargo': kargo })
def get_payment_info_isUser(request): current_user = request.user profile = Profile.objects.get(user=current_user) payment_type = request.POST['payment_type'] paymentType = PaymentType.objects.get(name=payment_type) address_id = request.POST['address'] adres = Address.objects.get(pk=address_id) address = adres.address address_city = adres.city address_district = adres.district orderProduct = "" subtotal = 0 discount = 0 net_total = 0 total = 0 kargo = Cargo.objects.get(name='Üzeri Kargo') kdv = Settings.objects.get(name='kdv') kargo1 = 0 products = general_methods.products_in_card(json.loads(request.POST['card'])) # Sepetteki ürünler çağrılıyor for order in products: subtotal = order.subtotal + subtotal c_code = json.loads(request.POST['c_code']) if c_code == None: discount = discount else: code = c_code['c_code'] discount = couponControl(code, subtotal) if products: net_total = subtotal * 100 / (100 + float(kdv.value)) if subtotal >= kargo.lower_limit: # ücretsiz kargo kargo1 = 0 total = subtotal kdv = total - net_total total = Decimal(subtotal) - Decimal(discount) else: kargo1 = kargo.price # ücretli kargo total = subtotal kdv = total - net_total total = subtotal + kargo.price - discount order = Order() if request.POST['address-value'] == 'TRUE': # fatura adresi = adres order.otherAddress = address else: order.otherAddress = request.POST['invoice_address'] # Farklı fatura adresi # siparis olusturuluyor order.payment_type = paymentType order.totalPrice = total order.cargo = kargo1 order.profile = profile order.address = address order.city = address_city order.kdv = kdv order.discount = discount order.netTotal = net_total order.subTotal = subtotal order.isGuest = False order.district = address_district order.save() # siparişin ürünleri for product_order in products: totalProductPrice = product_order.count * product_order.price product = Product.objects.get(pk=product_order.id) orderProduct = OrderProduct(order=order, product=product, quantity=product_order.count, totalProductPrice=totalProductPrice) orderProduct.save() """invoice_data = {'orders': products, 'subtotal': Decimal(subtotal), 'total': Decimal(total), 'net_total': Decimal(net_total), 'discount': discount, 'kdv': kdv, 'address': order.address, 'city': address_city, 'district': address_district, 'payment_type': order.payment_type, 'invoice_address': order.otherAddress, 'order': order, 'profile': profile} subject, from_email, to = 'Oxit Bilişim Teknolojileri', '*****@*****.**', current_user.email text_content = 'Fatura Bilgileri ' html_body = render_to_string("mailTemplates/invoice2.html", invoice_data) msg = EmailMultiAlternatives(subject, text_content, from_email, [to]) msg.attach_alternative(html_body, "text/html") msg.send() """ messages.success(request, 'Siparişiniz Başarıyla Oluştruldu.') if order.payment_type == 'Havale/EFT': messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:havale-eft-bilgi', siparis=order.id) elif order.payment_type.name == 'Kredi Kartı': paymentMethod = PaymentMethod.objects.get(isActive=True) if paymentMethod.name == 'Paytr': messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:payTr-make-creditCard-payment', siparis=order.id) if paymentMethod.name == 'Iyzico': messages.success(request, 'Sipariş başarıyla eklendi.') return redirect('inoks:iyzipay-make-creditcard-payment', siparis=order.id) else: order.isPayed = True orderProducts = OrderProduct.objects.filter(order=order) for orderProduct in orderProducts: product = Product.objects.get(pk=orderProduct.product.pk) product.stock = product.stock - orderProduct.quantity if product.stock <= 5: notification = Notification() notification.message = "Kod: " + str(product.code) + " olan ürün stoğunu güncelleyin.Stok: " + str( product.stock) + "" product.save() order.order_situations.add(OrderSituations.objects.get(name="Onay Bekliyor")) order.save() return render(request, 'checkout/odeme-tamamla.html', {'orders': products, 'subtotal': Decimal(subtotal), 'total': Decimal(total), 'net_total': Decimal(net_total), 'kdv': kdv, 'address': order.address, 'city': address_city, 'district': address_district, 'payment_type': order.payment_type, 'invoice_address': order.otherAddress})