Exemple #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 djecomstore.accounts import profile
			profile.set(request)
			
	return order
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','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')

        
Exemple #3
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)
		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))