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.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", "GBP") 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", "Royal Mail Special Delivery") shipping_methods.appendChild(flat_rate_shipping) shipping_price = doc.createElement("price") shipping_price.setAttribute("currency", "GBP") flat_rate_shipping.appendChild(shipping_price) shipping_price_text = doc.createTextNode("4.99") shipping_price.appendChild(shipping_price_text) return doc.toxml(encoding="utf-8")
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) if postdata['submit'] == 'Checkout': checkout_url = checkout.get_checkout_url(request) return HttpResponseRedirect(checkout_url) cart_items = cart.get_cart_items(request) cart_item_count = cart.cart_distinct_item_count(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))