示例#1
0
def create_order(request, transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user

    order.status = Order.SUBMITTED
    order.save()
    # if the order save succeeded
    if order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price # now using @property
            oi.product = ci.product
            oi.save()
        # all set, empty cart
        cart.empty_cart(request)
        # save profile info for future orders
        if request.user.is_authenticated():
            from ecomstore.accounts import profile
            profile.set(request)
    # return the new order object
    return order
def show_checkout(request, template_name='checkout/checkout.html'):
    """ checkout form page to collect user shipping and billing information """
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number',0)
            error_message = response.get('message','')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = u'Some required fields were not filled in. Please review your form to make sure all required information is present.'
    else:
            if request.user.is_authenticated():
                 user_profile = profile.retrieve(request)
                 form = CheckoutForm(instance=user_profile)
            else:
                 form = CheckoutForm()

    page_title = 'Checkout'
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
示例#3
0
def show_checkout(request, template_name='checkout/checkout.html'):
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'
    else:
        if request.user.is_authenticated():
            from ecomstore.accounts import profile
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
    page_title = 'Checkout'
    return render_to_response(template_name, locals(),
                              context_instance=RequestContext(request))
示例#4
0
def create_order(request, transaction_id):
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user

    order.status = Order.SUBMITTED
    order.save()
    # if the order save succeeded
    if order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            # create order item for each cart item
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price  # now using @property
            oi.product = ci.product
            oi.save()
        # all set, empty cart
        cart.empty_cart(request)
        # save profile info for future orders
        if request.user.is_authenticated():
            from ecomstore.accounts import profile
            profile.set(request)
    # return the new order object
    return order
def create_order(request, transaction_id):
    """ if the POST to the payment gateway successfully billed the customer, create a new order
    containing each CartItem instance, save the order with the transaction ID from the gateway,
    and empty the shopping cart
    
    """
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    
    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    if request.user.is_authenticated():
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()
    
    if order.pk:
        """ if the order save succeeded """
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            """ create order item for each cart item """
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price  # now using @property
            oi.product = ci.product
            oi.save()
        # all set, clear the cart
        cart.empty_cart(request)
        if request.user.is_authenticated():
            from ecomstore.accounts import profile
            profile.set(request)
        
    return order
示例#6
0
def show_checkout(request, template_name='checkout/checkout.html'):
    c = {}
    c.update(csrf(request))
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            #process the credit card with the data that's posted to the server - billing information
            response = checkout.process(request)
            order_number = response.get('order_number',0)
            print 'this is the order number: ' + str(order_number)
            error_message = response.get('message','')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                print request.session['order_number']
                return HttpResponseRedirect(receipt_url)
        else:
            error_message='Correct the errors below'

    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()
                
    page_title = 'Checkout'
    return render_to_response(template_name, locals(), context_instance= RequestContext(request))
示例#7
0
def show_checkout(request, template_name='checkout/checkout.html'):
    """ checkout form page to collect user shipping and billing information """
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)

    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = u'Correct the errors below'
    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()

    page_title = 'Checkout'
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
示例#8
0
def show_checkout(request, template_name='checkout/checkout.html'):
    c = {}
    c.update(csrf(request))
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse('show_cart')
        return HttpResponseRedirect(cart_url)
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            #process the credit card with the data that's posted to the server - billing information
            response = checkout.process(request)
            order_number = response.get('order_number', 0)
            print 'this is the order number: ' + str(order_number)
            error_message = response.get('message', '')
            if order_number:
                request.session['order_number'] = order_number
                receipt_url = urlresolvers.reverse('checkout_receipt')
                print request.session['order_number']
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = 'Correct the errors below'

    else:
        if request.user.is_authenticated():
            user_profile = profile.retrieve(request)
            form = CheckoutForm(instance=user_profile)
        else:
            form = CheckoutForm()

    page_title = 'Checkout'
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
示例#9
0
 def test_submit_empty_form(self):
     """ empty form should raise error on required fields """
     form = CheckoutForm()
     response = self.client.post(self.checkout_url, form.initial)
     for name, field in form.fields.iteritems():
         value = form.fields[name]
         if not value and form.fields[name].required:
             error_msg = form.fields[name].error_messages['required']
             self.assertFormError(response, "form", name, [error_msg])
示例#10
0
def show_checkout(request, template_name="checkout/checkout.html"):
    """ checkout form page to collect user shipping and billing information """
    if cart.is_empty(request):
        cart_url = urlresolvers.reverse("show_cart")
        return HttpResponseRedirect(cart_url)
    if request.method == "POST":
        postdata = request.POST.copy()
        form = CheckoutForm(postdata)
        if form.is_valid():
            response = checkout.process(request)
            order_number = response.get("order_number", 0)
            error_message = response.get("message", "")
            if order_number:
                request.session["order_number"] = order_number
                receipt_url = urlresolvers.reverse("checkout_receipt")
                return HttpResponseRedirect(receipt_url)
        else:
            error_message = u"Correct the errors below"
    else:
        form = CheckoutForm()
    page_title = "Checkout"
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
示例#11
0
def create_order(request, transaction_id):
    """ if the POST to the payment gateway successfully billed the customer, create a new order
    containing each CartItem instance, save the order with the transaction ID from the gateway,
    and empty the shopping cart
    
    """
    order = Order()
    checkout_form = CheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)

    order.transaction_id = transaction_id
    order.ip_address = request.META.get('REMOTE_ADDR')
    order.user = None
    if request.user.is_authenticated():
        order.user = request.user
    order.status = Order.SUBMITTED
    order.save()

    if order.pk:
        """ if the order save succeeded """
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            """ create order item for each cart item """
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price  # now using @property
            oi.product = ci.product
            oi.save()
        # all set, clear the cart
        cart.empty_cart(request)

        # save profile info for future orders
        if request.user.is_authenticated():
            from ecomstore.accounts import profile
            profile.set(request)

    return order