コード例 #1
0
ファイル: api.py プロジェクト: sakibovi123/Mustaqeemv2.0.0
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)
コード例 #2
0
ファイル: views.py プロジェクト: EduardGerman/Django
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)
コード例 #3
0
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})
コード例 #4
0
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})