1 ##parameters=order='', shipping='', set_shipping=''
2 from Products
.CMFCore
.utils
import getToolByName
3 from Products
.Portfolio
.utils
import translate
4 from Products
.photoprint
.exceptions
import SoldOutError
5 from Products
.photoprint
.cart
import PrintCart
6 from Products
.photoprint
.price
import Price
8 def _(message
) : return translate(message
, context
).encode('utf-8')
11 session
= context
.REQUEST
.SESSION
13 cart
= sg('cart', PrintCart())
14 utool
= getToolByName(context
, 'portal_url')
16 portal
= utool
.getPortalObject()
17 uidh
= portal
.portal_uidhandler
18 pptool
= portal
.portal_photo_print
19 mtool
= portal
.portal_membership
20 isAnon
= mtool
.isAnonymousUser()
21 form
= context
.REQUEST
.form
25 pendingOrder
= context
.restrictedTraverse(cart
.pendingOrderPath
)
26 return context
.setRedirect(pendingOrder
, 'object/view', ajax
=form
.get('ajax'))
30 atool
= portal
.portal_actions
31 came_from
= '%s/my_cart' % portal_url
32 return context
.setRedirect(atool
, 'customer/login', came_from
=came_from
, ajax
=form
.get('ajax'))
35 member
= mtool
.getAuthenticatedMember()
36 options
['shipping_fullname'] = member
.getMemberFullName(nameBefore
=0)
37 options
['shipping_address'] = member
.getProperty('billing_address')
38 options
['shipping_city'] = member
.getProperty('billing_city')
39 options
['shipping_zipcode'] = member
.getProperty('billing_zipcode')
40 options
['shipping_country'] = member
.getProperty('country')
41 return context
.shipping_template(**options
)
44 fg
= lambda name
: form
.get(name
,'').strip()
45 if context
.shipping_set_control(**form
) :
46 order
= pptool
.addPrintOrder(cart
)
47 return context
.setRedirect(order
, 'object/view', ajax
=fg('ajax'))
49 for name
in [ 'shipping_fullname'
53 , 'shipping_country'] :
54 options
[name
] = fg(name
)
55 return context
.shipping_template(**options
)
58 nextStep
= {'name':'order', 'value' : _('Order >>')}
60 nextStep
= {'name':'shipping', 'value' : _('Shipping >>')}
65 for k
, v
in form
.items() :
66 if hasattr(v
, 'items') :
67 uid
, templateId
= k
.split('_',1)
68 if v
.has_key('refresh') :
69 quantity
= v
['quantity']
71 quantity
= int(quantity
)
73 msg
= _('You must enter an integer for quantity (found: %s)') % quantity
75 msg
= _('You must enter a positive value for quantity (found: %s)') % quantity
77 item
= {'cmf_uid' : uid
78 ,'printing_template' : templateId
79 ,'quantity' : quantity
}
81 cart
.update(context
, item
)
82 except SoldOutError
, e
:
85 msg
= _("Only %d available copies of this photo in this size.") % n
87 msg
= _("Only one last available copy of this photo in this size.")
89 msg
= _("No more available copy of this photo and in this size.")
92 if v
.has_key('delete'):
93 cart
.remove(context
, uid
, templateId
)
95 options
['empty'] = not cart
100 b
= uidh
.getBrain(item
['cmf_uid'])
101 poptions
= pptool
.getPrintingOptionsContainerFor(b
.getObject())
102 pt
= getattr(poptions
, item
['printing_template'])
103 size
= b
.getThumbnailSize
104 d
= {'thumbUrl' : '%s/getThumbnail' % b
.getURL()
105 ,'thumbHeight' : size
['height'] / 2
106 ,'thumbWidth' : size
['width'] / 2
107 ,'alt' : ('%s - %s' % (b
.Title
, b
.Description
)).strip(' -')
110 ,'description': pt
.description
111 ,'quantity':item
['quantity']
112 ,'amount': '%s €' % (pt
.price
* item
['quantity']).taxed
113 ,'templateId': pt
.getId()
115 quantityTotal
+= item
['quantity']
116 prices
.append(pt
.price
* item
['quantity'])
119 options
['infos'] = infos
121 pricesTotal
= prices
[0]
122 elif len(prices
) > 1 :
123 pricesTotal
= reduce(lambda a
, b
: a
+ b
, prices
)
127 options
['pricesTotal'] = pricesTotal
128 options
['quantityTotal'] = quantityTotal
130 if context
.get('photoprint_discount') :
131 discount
= context
.photoprint_discount(pricesTotal
, quantityTotal
)
132 options
['discount'] = discount
133 shippingFees
= pptool
.getShippingFeesFor(price
=pricesTotal
)
134 options
['shippingFees'] = shippingFees
135 coeff
= (100 - discount
) / 100.
136 options
['totalAmount'] = pricesTotal
* coeff
+ shippingFees
140 , 'title' : portal
.title
141 , 'url' : portal_url
},
144 ,'title' : _('My cart')
145 , 'url' : '%s/my_cart' % portal_url
}
148 options
['breadcrumbs'] = breadcrumbs
151 context
.REQUEST
.other
['portal_status_message'] = msg
152 options
['cartIsOrder'] = False
153 options
['nextStep'] = nextStep
154 return context
.my_cart_template(**options
)