コード例 #1
0
def prepare_order_cash(request, venue_id):
    #cart_items = CartItem()
    cart_items = cart.get_cart_items(request, venue_id)
    for ci in cart_items:
        ci.cart_status = '2'
        ci.save()
    return cart
コード例 #2
0
def show_cart(request, venue_id, template_name="cart/show_cart.html"):
    """ view for each product page """
    #create the bound form
    postdata = request.POST.copy()
    form = ProductAddToCartForm(request, postdata)
    #check if posted data is valid
    if postdata['submit'] == 'Remove':
        cart.remove_from_cart(request, venue_id)
    if postdata['submit'] == 'Update':
        cart.update_cart(request, venue_id)
    if postdata['submit'] == 'Add':
        if form.is_valid():
            #add to cart and redirect to cart page
            cart.add_to_cart(request, venue_id)
        else:
            ferrors=form.errors
    # if test cookie worked, get rid of it
    if request.session.test_cookie_worked():
        request.session.delete_test_cookie()
    cart_items = cart.get_cart_items(request, venue_id)
    page_title = 'Shopping Cart'
    cart_subtotal = cart.cart_subtotal(request, venue_id)
    return render_to_response(template_name, locals(), context_instance=RequestContext(request))
コード例 #3
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')