예제 #1
0
def checkout(request):
    cart_proxy = CartProxy(request)
    items = []
    cart_total = 0
    for i in cart_proxy:
        items.append(i)
        cart_total += i.total_price
    return render(
        request, 'order/checkout.html',
        dict(
            section='Cart',
            cart=cart_proxy.get_formatted_cart(),
            cart_total=cart_proxy.calculate_total(),
            hideTopCart=True,
        ))
예제 #2
0
def place_order(request):
    cart_proxy = CartProxy(request)
    cart_grouped = cart_proxy.get_formatted_cart()
    customer, contact = __get_customer_contact(request)
    total_amount = cart_proxy.calculate_total()
    if ('order_group' in request.session):
        # delete the other that existed in memory and has not been paid
        try:
            previous_order_group = OrderGroup.objects.get(
                pk=request.session['order_group'])
            if previous_order_group.get_payment_status() not in [
                    'PAYMENT RECEIVED',
            ]:
                previous_order_group.delete()
        except OrderGroup.DoesNotExist:
            logging.warning('Order group {} does not exist'.format(
                request.session['order_group']))
            pass
    # create order group
    order_group = OrderGroup(customer=customer,
                             contact=contact,
                             total_amount=total_amount)
    order_group.save()
    request.session['order_group'] = order_group.pk
    for vendor, cart in cart_grouped.items():
        order = Order(order_group=order_group, vendor=vendor)
        order.save()
        order.place_order(
            cart['items'],
            {
                # shipping details
                'type': cart['shipping'].name,
                'cost': cart['shipping'].price,
                'details': request.POST.get('shipping_details', False),
                'status': 'just created',
                'contact': contact
            })
    # redirect to
    return process_payment(request, order_group)