def api_checkout(request): data = json.loads(request.body) cart = Cart(request) jsonresponse = {'success': True} first_name = data['first_name'] last_name = data['last_name'] email = data['email'] address = data['address'] zipcode = data['zipcode'] city = data['city'] orderId = checkout(request, first_name, last_name, email, address, zipcode, city) paid = True if paid == True: order = Order.objects.get(pk=orderId) order.paid = True order.paid_amount = cart.get_total_cost() order.save() cart.clear() return JsonResponse(jsonresponse)
def order_create(request): cart = Cart(request) if request.method == 'POST': form = OrderCreateForm(request.POST) if form.is_valid(): order = form.save() for item in cart: OrderItem.objects.create( order = order, product = item['product'], price = item['price'], quantity = item['quantity']) # очистка корзины cart.clear() return render(request, 'Order/Created.html', {'order': order}) else: form = OrderCreateForm data = {'cart': cart, 'form': form} return render(request, 'Order/Create.html', context = data)
def order_create(request): template = '.html' cart = Cart(request) if request.method == 'POST': form = OrderCreateForm(request.POST) if form.is_valid(): order = form.save() for item in cart: OrderItem.objects.create(order=order, item=item['item'], unit_price=item['unit_price'], quantity=item['quantity']) cart.clear() return render(request, template, {'order': order}) else: form = OrderCreateForm() return render(request, template, {'cart': cart, 'form': form})
def order_create(request): cart = Cart(request) if request.method == 'POST': form = OrderCreateForm(request.POST) if form.is_valid(): order = form.save() for item in cart: OrderItem.objects.create(order=order, product=item['product'], price=item['price'], quantity=item['quantity']) cart.clear() order_created.delay(order.id) request.session['order_id'] = order.id return redirect(reverse('payment:process')) else: form = OrderCreateForm() return render(request, 'orders/order/create.html', {'form': form})