maniaquerie
[photoprint.git] / skins / order_view.py
1 ##parameters=
2 from Products.CMFCore.utils import getToolByName
3 from Products.photoprint.price import Price
4 from Products.photoprint.cart import PrintCart
5 uidh = getToolByName(context, 'portal_uidhandler')
6 wtool = getToolByName(context, 'portal_workflow')
7
8 options = {}
9
10 quantity = 0
11 prices = []
12 infos = []
13
14 session = context.REQUEST.SESSION
15 sg = session.get
16 cart = sg('cart', PrintCart())
17 wfstate = wtool.getInfoFor(context, 'review_state', 'order_workflow')
18 options['wfstate'] = wfstate
19 options['wfhistory'] = wtool.getInfoFor(context, 'review_history', 'order_workflow')
20 toBePaid = wfstate == 'recorded'
21
22 if toBePaid :
23 options['checkout'] = context.ppSetExpressCheckout()
24
25 if cart.locked and \
26 cart.pendingOrderPath == context.getPhysicalPath() :
27 options['orderIsCart'] = True
28 if wfstate != 'recorded' :
29 cart = PrintCart()
30 session['cart'] = cart
31 else :
32 options['orderIsCart'] = False
33
34 for item in context.items :
35 d = {'title' : item['title']
36 ,'description' : item['description']
37 ,'unit_price' : item['unit_price']
38 ,'quantity' : item['quantity']
39 ,'total' : item['unit_price'] * item['quantity']
40 }
41
42 b = uidh.queryBrain(item['cmf_uid'])
43 if b :
44 size = b.getThumbnailSize
45 thumbInfo = {'thumbUrl' : '%s/getThumbnail' % b.getURL()
46 ,'thumbHeight' : size['height'] / 2
47 ,'thumbWidth' : size['width'] / 2
48 ,'alt' : ('%s - %s' % (b.Title, b.Description)).strip(' -')
49 }
50 d.update(thumbInfo)
51 quantity += d['quantity']
52 prices.append(d['total'])
53 infos.append(d)
54
55 options['infos'] = infos
56 options['quantity'] = quantity
57 options['pricesSum'] = context.price
58 options['discount'] = getattr(context, 'discount', 0)
59 options['shippingFees'] = shippingFees = context.shippingFees
60 options['total'] = context.amountWithFees
61
62 return context.order_view_template(**options)