def make_order(request): if request.POST: form = OrderForm(request.POST) if form.is_valid(): add = form.save(commit=False) add.order_products = ordered_products_titles( request.session.get('grouped_prods_in_cart')) add.order_sum = request.session.get('cart_cost') add.save() shop_email_subject = "Новый заказ !!!" shop_email_body = "Поступил новый заказ №%s!\n" \ "Покупатель - %s.\n" \ "Сумма заказа - %s грн.\n" \ "Товары:\n" \ "%s" \ % (add.order_code, add.order_person, add.order_sum, add.order_products) send_mail( shop_email_subject, shop_email_body, # отправитель магазин DEFAULT_FROM_EMAIL, # получатель хозяин магазина [DEFAULT_TO_EMAIL], fail_silently=False) conf_link = "%s/cart/confirm_order/%s" % (SITE_ADDR, add.order_code) buyer_email_subject = "Ваш заказ в магазине MultyDOM" buyer_email_body = "Добрый день уважаемый %s!!!\n" \ "Спасибо за Ваш заказ.\n"\ "Товары:\n" \ "%s" \ "Сумма заказа - %s грн.\n\n" \ "Для подтверждения заказа необходимо перейти по ссылке укзанной ниже\n" \ "%s" % (add.order_person, add.order_products, add.order_sum, conf_link) send_mail(buyer_email_subject, buyer_email_body, DEFAULT_FROM_EMAIL, [add.order_person_email], fail_silently=False) del request.session['cart_qwt_of_prods'] del request.session['cart_cost'] del request.session['grouped_prods_in_cart'] del request.session['prods_in_cart'] return render(request, 'order_created.html', {'email': add.order_person_email}) else: messages.error( request, 'Ваш заказ НЕ ОФОРМЛЕН!!! Проверьте правильность введения ' 'данных и повторите заказ. ВСЕ поля НЕОБХОДИМО заполнить, ' 'а последнее поле - посчитать и вписать ответ!!!') return redirect('my_cart')
def checkout(request): if request.method == 'POST': order_form = OrderForm(request.POST) if order_form.is_valid(): initial = order_form.cleaned_data initial.update({'key': settings.PAYU_INFO['merchant_key'], 'surl': request.build_absolute_uri(reverse('order.success')), 'furl': request.build_absolute_uri(reverse('order.success')), 'curl': request.build_absolute_uri(reverse('order.cancel'))}) # Once you have all the information that you need to submit to payu # create a payu_form, validate it and render response using # template provided by PayU. payu_form = PayUForm(initial) if payu_form.is_valid(): context = {'form': payu_form, 'action': "%s_payment" % settings.PAYU_INFO['payment_url']} return render(request, 'payu_form.html', context) else: logger.error('Something went wrong! Looks like initial data\ used for payu_form is failing validation') return HttpResponse(status=500) else: initial = {'txnid': uuid4().hex, 'productinfo': lorem_ipsum(), 'amount': randint(100, 1000)/100.0} order_form = OrderForm(initial=initial) context = {'form': order_form} return render(request, 'checkout.html', context)
def make_order(request): if request.POST: form = OrderForm(request.POST) if form.is_valid(): add = form.save(commit=False) add.order_products = request.session.get('grouped_prods_in_cart') add.order_sum = request.session.get('cart_cost') add.save() messages.success(request, 'Спасибо за Ваш заказ!\n На Ваш электронный адрес направлено письмо со ссылкой ' 'для подтверждения заказа. После подтверждения Вы можете найти свой ' 'заказ в разделе заказы по его номеру.') shop_email_subject = "Новый заказ !!!" shop_email_body = "Поступил новый заказ №%s!\n Покупатель - %s.\n Сумма заказа - %s.\n Товары - %s\n" \ % (add.order_code, add.order_person, add.order_sum, add.order_products) send_mail(shop_email_subject, shop_email_body, '*****@*****.**', ['*****@*****.**'], fail_silently=False) conf_link = "127.0.0.1:8000/cart/confirm_order/%s" % add.order_code buyer_email_subject = "Ваш заказ в магазине КОФЕ SHOP" buyer_email_body = "Добрый день уважаемый %s!!! \n Спасибо за Ваш заказ. Для подтверждения заказа " \ "необходимо перейти по ссылке укзанной ниже \n %s" % (add.order_person, conf_link) send_mail(buyer_email_subject, buyer_email_body, '*****@*****.**', ['*****@*****.**'], fail_silently=False) else: messages.error(request, 'Ваш заказ НЕ ОФОРМЛЕН!!! Проверьте правильность введения ' 'данных и повторите заказ. ВСЕ поля НЕОБХОДИМО заполнить!!!') return redirect('cart')
def order(request): if request.POST: form = OrderForm(request.POST) if form.is_valid(): for object in Cart.objects.all(): object.delete() return redirect('/') else: return redirect('/cart/')
def order_cart(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): subject = u'Заказ с сайта' recipients = [] try: recipients.extend(emails_list(request.settings.email)) except: recipients.append(settings.ADMINS[0][1]) cart = Cart(request, init=True) # Order insertion if cart.objects: order = Order.objects.create( fio=form.cleaned_data['fio'], address='', phones=form.cleaned_data['phones'], email=form.cleaned_data['email'], comment=form.cleaned_data['comment']) for item in cart.objects: order.items.create(label=item.label, amount=item.amount, price=item.price) subject = u'Поступил заказ с сайта %s' % settings.PROJECT_TITLE letter_context = form.cleaned_data letter_context.update({ 'site': settings.PROJECT_TITLE, 'cart': cart, 'subject': subject }) text_content = render_to_string('letters/order_text.txt', letter_context) html_content = render_to_string('letters/order_html.html', letter_context) msg = EmailMultiAlternatives(subject, text_content, recipients[0], recipients) msg.attach_alternative(html_content, "text/html") msg.send() cart.delete_all() success_message = request.infoblock.get( 'order_send_message', u""" Благодарим за то, что Вы воспользовались услугами нашего Интернет-магазина. Ваша заявка принята в обработку, и наш менеджер свяжется с Вами в ближайшее время для уточнения деталей. """) messages.add_message(request, messages.SUCCESS, success_message) return redirect(reverse('message_list')) else: form = OrderForm() return render_to_response('cart_order.html', {'form': form}, context_instance=RequestContext(request))
def order_cart(request): if request.method == 'POST': form = OrderForm(request.POST) if form.is_valid(): subject = u'Заказ с сайта' recipients = [] try: recipients.extend(emails_list(request.settings.email)) except: recipients.append(settings.ADMINS[0][1]) cart = Cart(request, init=True) # Order insertion if cart.objects: order = Order.objects.create(fio=form.cleaned_data['fio'], address='', phones=form.cleaned_data['phones'], email=form.cleaned_data['email'], comment=form.cleaned_data['comment']) for item in cart.objects: order.items.create(label=item.label, amount=item.amount, price=item.price) subject = u'Поступил заказ с сайта %s' % settings.PROJECT_TITLE letter_context = form.cleaned_data letter_context.update({'site': settings.PROJECT_TITLE, 'cart': cart, 'subject': subject}) text_content = render_to_string('letters/order_text.txt', letter_context) html_content = render_to_string('letters/order_html.html', letter_context) msg = EmailMultiAlternatives(subject, text_content, recipients[0], recipients) msg.attach_alternative(html_content, "text/html") msg.send() cart.delete_all() success_message = request.infoblock.get('order_send_message', u""" Благодарим за то, что Вы воспользовались услугами нашего Интернет-магазина. Ваша заявка принята в обработку, и наш менеджер свяжется с Вами в ближайшее время для уточнения деталей. """) messages.add_message(request, messages.SUCCESS, success_message) return redirect(reverse('message_list')) else: form = OrderForm() return render_to_response('cart_order.html', {'form': form}, context_instance=RequestContext(request))
def checkout(request): if request.method == 'POST': order_form = OrderForm(request.POST) if order_form.is_valid(): initial = order_form.cleaned_data initial.update({ 'key': settings.PAYU_INFO['merchant_key'], 'surl': "http://surfly-dev.opentestdrive.com/order/success/", 'furl': "http://surfly-dev.opentestdrive.com/order/failure/", 'curl': "http://surfly-dev.opentestdrive.com/order/cancel/" }) payu_form = PayUForm(initial) if payu_form.is_valid(): context = { 'form': payu_form, 'hash_form': HashForm({'hash': generate_hash(payu_form.cleaned_data)}), 'action': settings.PAYU_INFO['payment_url'] } return render(request, 'payu_form.html', context) else: logger.error('Something went wrong! Looks like initial data\ used for payu_form is failing validation') return HttpResponse(status=500) else: initial = { 'txnid': uuid4().hex, 'productinfo': "Description", 'firstname': "Swagat", 'email': "*****@*****.**", 'phone': "1234567890", 'amount': randint(100, 1000) / 100.0 } order_form = OrderForm(initial=initial) context = {'form': order_form} return render(request, 'checkout.html', context)