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
示例#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 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
示例#3
0
def show_cart(request, template_name="cart/cart.html"):
    #update the csrf token
    c = {}
    c.update(csrf(request))

    if request.method =='POST':

        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            #get the checkout url from checkout.checkout.py
            checkout_url = checkout.get_checkout_url(request)
            print checkout_url
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    cart_subtotal = cart.cart_subtotal(request)
#    cart_item_count = cart.cart_item_count(request)
    
    page_title = 'Shopping Cart'
    #for google checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name, locals(),context_instance=RequestContext(request))
示例#4
0
def show_cart(request, template_name="cart/cart.html"):
    #update the csrf token
    c = {}
    c.update(csrf(request))

    if request.method == 'POST':

        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            #get the checkout url from checkout.checkout.py
            checkout_url = checkout.get_checkout_url(request)
            print checkout_url
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    cart_subtotal = cart.cart_subtotal(request)
    #    cart_item_count = cart.cart_item_count(request)

    page_title = 'Shopping Cart'
    #for google checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
示例#5
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
示例#6
0
def _build_xml_shopping_cart(request):
    """ constructs the XML representation of the current customer's shopping cart items to POST to 
    the Google Checkout API
    
    """
    doc = Document()
    root = doc.createElement('checkout-shopping-cart')
    root.setAttribute('xmlns', 'http://checkout.google.com/schema/2')
    doc.appendChild(root)
    shopping_cart = doc.createElement('shopping-cart')
    root.appendChild(shopping_cart)
    items = doc.createElement('items')
    shopping_cart.appendChild(items)
    cart_items = cart.get_cart_items(request)
    for cart_item in cart_items:
        item = doc.createElement('item')
        items.appendChild(item)

        item_name = doc.createElement('item-name')
        item_name_text = doc.createTextNode(str(cart_item.name))
        item_name.appendChild(item_name_text)
        item.appendChild(item_name)

        item_description = doc.createElement('item-description')
        item_description_text = doc.createTextNode(str(cart_item.name))
        item_description.appendChild(item_description_text)
        item.appendChild(item_description)

        unit_price = doc.createElement('unit-price')
        unit_price.setAttribute('currency', 'USD')
        unit_price_text = doc.createTextNode(str(cart_item.price))
        unit_price.appendChild(unit_price_text)
        item.appendChild(unit_price)

        quantity = doc.createElement('quantity')
        quantity_text = doc.createTextNode(str(cart_item.quantity))
        quantity.appendChild(quantity_text)
        item.appendChild(quantity)

    checkout_flow = doc.createElement('checkout-flow-support')
    root.appendChild(checkout_flow)
    merchant_flow = doc.createElement('merchant-checkout-flow-support')
    checkout_flow.appendChild(merchant_flow)

    shipping_methods = doc.createElement('shipping-methods')
    merchant_flow.appendChild(shipping_methods)

    flat_rate_shipping = doc.createElement('flat-rate-shipping')
    flat_rate_shipping.setAttribute('name', 'FedEx Ground')
    shipping_methods.appendChild(flat_rate_shipping)

    shipping_price = doc.createElement('price')
    shipping_price.setAttribute('currency', 'USD')
    flat_rate_shipping.appendChild(shipping_price)

    shipping_price_text = doc.createTextNode('9.99')
    shipping_price.appendChild(shipping_price_text)

    return doc.toxml(encoding='utf-8')
示例#7
0
def _build_xml_shopping_cart(request):
    """ constructs the XML representation of the current customer's shopping cart items to POST to 
    the Google Checkout API
    
    """
    doc = Document()
    root = doc.createElement('checkout-shopping-cart')
    root.setAttribute('xmlns', 'http://checkout.google.com/schema/2')
    doc.appendChild(root)
    shopping_cart = doc.createElement('shopping-cart')
    root.appendChild(shopping_cart)
    items = doc.createElement('items')
    shopping_cart.appendChild(items)
    cart_items = cart.get_cart_items(request)
    for cart_item in cart_items:
        item = doc.createElement('item')
        items.appendChild(item)
        
        item_name = doc.createElement('item-name')
        item_name_text = doc.createTextNode(str(cart_item.name))
        item_name.appendChild(item_name_text)
        item.appendChild(item_name)
        
        item_description = doc.createElement('item-description')
        item_description_text = doc.createTextNode(str(cart_item.name))
        item_description.appendChild(item_description_text)
        item.appendChild(item_description)
        
        unit_price = doc.createElement('unit-price')
        unit_price.setAttribute('currency','USD')
        unit_price_text = doc.createTextNode(str(cart_item.price))
        unit_price.appendChild(unit_price_text)
        item.appendChild(unit_price)
        
        quantity = doc.createElement('quantity')
        quantity_text = doc.createTextNode(str(cart_item.quantity))
        quantity.appendChild(quantity_text)
        item.appendChild(quantity)
        
    checkout_flow = doc.createElement('checkout-flow-support')
    root.appendChild(checkout_flow)
    merchant_flow = doc.createElement('merchant-checkout-flow-support')
    checkout_flow.appendChild(merchant_flow)
    
    shipping_methods = doc.createElement('shipping-methods')
    merchant_flow.appendChild(shipping_methods)
    
    flat_rate_shipping = doc.createElement('flat-rate-shipping')
    flat_rate_shipping.setAttribute('name','FedEx Ground')
    shipping_methods.appendChild(flat_rate_shipping)
    
    shipping_price = doc.createElement('price')
    shipping_price.setAttribute('currency','USD')
    flat_rate_shipping.appendChild(shipping_price)
    
    shipping_price_text = doc.createTextNode('9.99')
    shipping_price.appendChild(shipping_price_text)
    
    return doc.toxml(encoding='utf-8')
示例#8
0
def _build_xml_shopping_cart(request):
    doc = Document()
    root = doc.createElement('checkout-shopping-cart')
    root.setAttribute('xmlns','http://checkout.google.com/schema/2')
    doc.appendChild(root)
    
    shopping_cart=doc.createElement('shopping-cart')
    root.appendChild(shopping_cart)
    
    items = doc.createElement('items')
    shopping_cart.appendChild(items)

    cart_items = cart.get_cart_items(request)
    for cart_item in cart_items:
        item = doc.createElement('item')
        items.appendChild(item)
        item_name=doc.createElement('item-name')
        item_name_text=doc.createTextNode(str(cart_item.name))
        item_name.appendChild(item_name_text)

        item_description = doc.createElement('item-description')
        item_description_text = doc.createTextNode(str(cart_item.name))
        item_description.appendChild(item_description_text)
        item.appendChild(item_description)

        unit_price = doc.createElement('unit-price')
        unit_price.setAttribute('currency','USD')
        unit_price_text=doc.createTextNode(str(cart_item.price))
        unit_price.appendChild(unit_price_text)
        item.appendChild(unit_price)

        quantity = doc.createElement('quantity')
        quantity_text = doc.createTextNode(str(cart_item.quantity))
        quantity.appendChild(quantity_text)
        item.appendChild(quantity)

    checkout_flow = doc.createElement('checkout-flow-support')
    root.appendChild(checkout_flow)
    merchant_flow = doc.createElement('merchant-checkout-flow-support')
    checkout_flow.appendChild(merchant_flow)
    
    shipping_methods = doc.createElement('shipping-methods')
    merchant_flow.appendChild(shipping_methods)

    #add more elements here if you want different shipping options
    flat_rate_shipping = doc.createElement('flat-rate-shipping')
    flat_rate_shipping.setAttribute('name','UPS Ground')
    shipping_methods.appendChild(flat_rate_shipping)

    shipping_price=doc.createElement('price')
    shipping_price.setAttribute('currency', 'USD')
    flat_rate_shipping.appendChild(shipping_price)

    shipping_price_text = doc.createTextNode('9.99')
    shipping_price.appendChild(shipping_price_text)
    return doc.toxml(encoding='utf-8')
示例#9
0
def show_cart(request, template_name="cart/cart.html"):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
示例#10
0
def show_cart(request, template_name):
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    # for Google Checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
示例#11
0
def show_cart(request, template_name="cart/cart.html"):
    """ view function for the page displaying the customer shopping cart, and allows for the updating of quantities
    and removal product instances 
    
    """
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    # need for Google Checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name, locals(),context_instance=RequestContext(request))
示例#12
0
def show_cart(request, template_name="cart/cart.html"):
    """ view function for the page displaying the customer shopping cart, and allows for the updating of quantities
    and removal product instances 
    
    """
    if request.method == 'POST':
        postdata = request.POST.copy()
        if postdata['submit'] == 'Remove':
            cart.remove_from_cart(request)
        if postdata['submit'] == 'Update':
            cart.update_cart(request)
        if postdata['submit'] == 'Checkout':
            checkout_url = checkout.get_checkout_url(request)
            return HttpResponseRedirect(checkout_url)
    cart_items = cart.get_cart_items(request)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request)
    # need for Google Checkout button
    merchant_id = settings.GOOGLE_CHECKOUT_MERCHANT_ID
    return render_to_response(template_name,
                              locals(),
                              context_instance=RequestContext(request))
示例#13
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