Thanks
Iain
Wicked cool. I'll subscribe. When do we get name something Lester or
Prez? Guess I'd have to invent it. ;)
Thanks
Iain
Oh yeah, to the Satchmo dudes, whoever you are, the about link on the
trac page is broken.
root@airvent:/usr/local/web/diamond $ wc -l shop/*
shop/templates/shop/*
0 shop/__init__.py
105 shop/models.py
14 shop/urls.py
153 shop/views.py
56 shop/templates/shop/cart.html
36 shop/templates/shop/category.html
100 shop/templates/shop/checkout.html
13 shop/templates/shop/emptycart.html
21 shop/templates/shop/nocookie.html
32 shop/templates/shop/product.html
67 shop/templates/shop/shop_homepage.html
43 shop/templates/shop/thanks.html
It was relatively simple since the order processing is done in an other
(RUby on Rails) application and all the product data was already in
place from other sources. So I basically had to provide the cart and
nothing else.
Some of the more interesting view functions are:
def testcookie(request):
request.session.set_test_cookie()
return HttpResponseRedirect("../")
def addtocart(request, artnr):
if not request.session.test_cookie_worked():
return render_to_response('shop/nocookies.html', \
{}, context_instance=template.RequestContext(request))
else:
request.session.delete_test_cookie()
cart = request.session.get('cart', None) or Cart()
cart.add_item(artnr)
request.session['cart'] = cart
return HttpResponseRedirect("/shop/cart")
def cart(request):
cart = request.session.get('cart', None)
if not cart:
return render_to_response('shop/emptycart.html',
{}, context_instance=template.RequestContext(request))
else:
return render_to_response('shop/cart.html',
{'cart': cart},
context_instance=template.RequestContext(request))
def updatecart(request):
cart = request.session.get('cart', None)
if not cart:
return render_to_response('shop/emptycart.html',
{}, context_instance=template.RequestContext(request))
for k in request.POST:
if k.startswith('menge_'):
artnr = k.split('_')[1]
menge = request.POST[k]
menge = re.sub(r'[^0-9]', '', menge)
if menge == '':
menge = 0
try:
menge = int(menge)
except:
menge = 1
cart.update_item(artnr, menge)
request.session['cart'] = cart
return HttpResponseRedirect("../")
def checkout(request):
cart = request.session.get('cart', None)
manipulator = RecipientAddress.AddManipulator()
if not cart:
return render_to_response('shop/emptycart.html',
{}, context_instance=template.RequestContext(request))
if request.POST:
# If data was POSTed, try to create a new RecipientAddress.
new_data = request.POST.copy()
# Check for errors.
errors = manipulator.get_validation_errors(new_data)
if not errors:
# No errors. This means we can save the data!
manipulator.do_html2python(new_data)
new_address = manipulator.save(new_data)
request.session['oldcart'] = cart
del(request.session['cart']) # remove cart from session
request.COOKIES['hudora_kundennummer'] = /
"WC%6d" % (new_address.id)
consignment = Consignment(created_via='webshop',\
recipient=new_address)
created_by_ip = request.META.get('REMOTE_ADDR', '')
created_by_ua = request.META.get('HTTP_USER_AGENT', '')
consignment.save()
for cartitem in cart.items():
item = ConsignmentItem(consignment=consignment,
quantity=cartitem['menge'],
artnr=cartitem['artnr'],
unit_price=cartitem['einzelpreis'])
item.save()
# add shipping and handling
ConsignmentItem.objects.create(\
consignment=consignment, \
quantity=1, artnr='P0400', unit_price=4.00)
def thanks(request):
return render_to_response('shop/thanks.html',
{'cart': request.session.get('oldcart', None),
'order': request.session.get('lastorder', None),},
context_instance=template.RequestContext(request))
Once you get on the list, let me know which trac page is broken - I
can't seem to find it when I browse the site.
-Chris
Is your code in an SVN repository somewhere? It would be great to see
what parts we might be able to leverage.
-Chris
It's working again. Probably something just conking out bewteen my ISP and the host.
Iain
Unfortunately not at this time. You might know the Brooks metric.
Make it work: 1 Month
Make it installable on a generic machine: 3 Months
Document it so others can use it: 3 Months
all of the above: 9 Months
Since this is an inhouse development and we probably will never set um
another instance there is little incentive to clean it up. Then again
... wasn't that how ellington started?
Regards
Max
* the shop is for low value goods and payment is via invoice.This
allows a very lean shopping process: search for the product, click on
the spare part to add it to the cart, click on checkout button enter
your address click on commit and you are done.
* no stupid accepting terms - the customer is always right, isn't he -
, no "click here to deny not requesting to be not being on a mass
mailing list". Keeps the checkout process also lean and fast.
* stuff is added by an url like /shop/cart/add/<productid>/testcookie/
this sets the testcookie and redirects to /shop/cart/add/<productid>/
where we test for the testcookie and add the product with the id
<productid> (artnr) to the cart.
I took Max's helpful example and filled in the rest. I've made a Google
Code project located here: http://code.google.com/p/django-cart/
There is zero documentation other than the project home title sheet. As
Max says, writing the code is a small part of what it takes to make a
serious project. Still, I thought at least I could contribute the code.
Here is the project title sheet:
This is a simple shopping cart for the Django Web Framwork that
integrates with Google Checkout and Paypal
This Python code implements a simple shopping cart that keeps track of
orders placed on a Django-based e-commerce site. The cart is stored in
the Django Session dictionary, which is backed by the Django Session DB
table.
The shopping cart page contains 2 checkout buttons for payment
processing through either Google Checkout or Paypal. The checkout
buttons post forms that hold the appropriate data for these two systems
in hidden fields.
This is based upon some a shopping cart view.py example in
http://groups.google.com/group/django-users/browse_thread/thread/96dd3cc6b74f8a1e
by Maximillian Dornseif and on a Django/Google Checkout integration
article by Bruce Kroeze in
http://coderseye.com/2006/google-checkout-initial-impressions-from-a-developer.html