Esempio n. 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
			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 accounts import profile
		profile.set(request)
	# return the new order object	
	return order
Esempio n. 2
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 order.pk:
        cart_items = cart.get_cart_items(request)
        for ci in cart_items:
            oi = OrderItem()
            oi.order = order
            oi.quantity = ci.quantity
            oi.price = ci.price
            oi.product = ci.product
            oi.save()
        cart.empty_cart(request)

        if request.user.is_authenticated():
            from accounts import profile
            profile.set(request)

    return order
Esempio n. 3
0
def order_info(request, template_name="registration/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'
    return render(request, template_name, locals(), RequestContext(request))
Esempio n. 4
0
def order_info(request, template_name="accounts/order_info.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'
    return render_to_response(template_name, locals(),
            context_instance=RequestContext(request))
Esempio n. 5
0
def order_info(request, template_name="registration/order_info.html"):
    if request.method == "POST":
        postdata = request.POST.copy()
        form = UserProfileForm(postdata)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = _("Edit order information")
    context = locals()
    context.update(csrf(request))
    return render_to_resonse(template_name, context,
                             context_instance=RequestContext(request))
Esempio n. 6
0
def order_info(request, template_name="registration/order_info.html"):
    """
    page containing a form that allows a customer to edit their billing and shipping information that
    will be displayed in the order form next time they are logged in and go to check out
    """
    if request.method == 'POST':
        post_data = request.POST.copy()
        form = UserProfileForm(post_data)
        if form.is_valid():
            profile.set(request)
            url = urlresolvers.reverse('accounts:my_account')
            return HttpResponseRedirect(url)
    else:
        user_profile = profile.retrieve(request)
        form = UserProfileForm(instance=user_profile)
    page_title = 'Edit Order Information'

    return render(request, template_name, locals())
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 = carts.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
        carts.empty_cart(request)

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

    return order
Esempio n. 8
0
def create_order(request, transaction_id):
    postdata = request.POST.copy()
    order = Order()
    checkout_form = MpesaCheckoutForm(request.POST, instance=order)
    order = checkout_form.save(commit=False)
    order.billing_name = postdata['shipping_name']
    order.billing_address_1 = postdata['shipping_address_1']
    order.billing_address_2 = postdata['shipping_address_2']
    order.billing_city = postdata['shipping_city']
    order.billing_zip = postdata['shipping_zip']
    order.billing_country = postdata['shipping_country']
    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:
            profile.set(request)
    # return the new order object
    return order
Esempio n. 9
0
def create_order(request, transaction_id):
    postdata = request.POST.copy()
    CART_ID_SESSION_KEY = cart.CART_ID_SESSION_KEY
    pending = PendingMpesa.objects.filter(
        cart=request.session[CART_ID_SESSION_KEY])
    if request.user.is_authenticated:
        user_profile = profile.retrieve(request)
    else:
        user_profile = ''
    if pending.count(
    ) > 0 and request.user.is_authenticated and not request.method == 'POST' and user_profile.shipping_name != '':
        user_profile = profile.retrieve(request)
        print(user_profile.shipping_name)
        order = Order()
        # checkout_form = MpesaCheckoutForm(instance=order)
        # order = checkout_form.save(commit=False)
        order.shipping_name = user_profile.shipping_name
        order.shipping_address_1 = user_profile.shipping_address_1
        order.shipping_address_2 = user_profile.shipping_address_2
        order.shipping_city = user_profile.shipping_city
        order.shipping_zip = user_profile.shipping_zip
        order.shipping_country = user_profile.shipping_country
        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()
    else:
        order = Order()
        checkout_form = MpesaCheckoutForm(request.POST, instance=order)
        order = checkout_form.save(commit=False)
        order.billing_name = postdata['shipping_name']
        order.billing_address_1 = postdata['shipping_address_1']
        order.billing_address_2 = postdata['shipping_address_2']
        order.billing_city = postdata['shipping_city']
        order.billing_zip = postdata['shipping_zip']
        order.billing_country = postdata['shipping_country']
        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 and not pending_checker(request) == 0:
            profile.set(request)
    # return the new order object
    return order