c0ffb9aad7c11dc849bf3e3154150fe25a693d08
2 from Products
.CMFCore
.utils
import getToolByName
3 from Products
.Portfolio
.utils
import translate
4 from Products
.photoprint
.exceptions
import SoldOutError
, CartLockedError
5 def _(message
) : return translate(message
, context
).encode('utf-8')
7 form
= context
.REQUEST
.form
8 ajax
= form
.get('ajax')
10 context
.REQUEST
.RESPONSE
.setHeader('Content-Type', 'text/xml;;charset=utf-8')
12 atool
= getToolByName(context
, 'portal_actions')
14 quantity
= form
.get('quantity')
18 quantity
= int(quantity
)
20 msg
= _('You must enter an integer for quantity (found: %s)') % quantity
23 msg
= _('You must enter a positive value for quantity (found: %s)') % quantity
27 return "<error>%s</error>" % msg
29 context
.setStatus(False, msg
)
30 return context
.setRedirect(atool
, 'user/panier')
32 sd
= context
.session_data_manager
.getSessionData(create
= 1)
34 from Products
.CMFCore
.utils
import getToolByName
35 uidh
= getToolByName(context
, 'portal_uidhandler')
36 item
= {'cmf_uid':form
['cmf_uid']
37 ,'printing_template':form
['printing_template']
40 photo
= uidh
.getBrain(item
['cmf_uid'])
42 from Products
.photoprint
.cart
import PrintCart
43 cart
= sd
.get('cart', PrintCart())
45 cart
.append(context
, item
)
46 except SoldOutError
, e
:
49 msg
= _("Only %d available copies of this photo in this size.") % n
51 msg
= _("Only one last available copy of this photo in this size.")
53 msg
= _("No more available copy of this photo in this size.")
56 return "<error>%s</error>" % msg
58 context
.setStatus(False, msg
)
59 return context
.setRedirect(atool
, 'user/panier')
61 except CartLockedError
:
62 msg
= _("Your cart is locked:\nplease complete your current order first.")
64 return "<error>%s</error>" % msg
66 context
.setStatus(False, msg
)
67 return context
.setRedirect(atool
, 'user/panier')
72 return '<confirm duration="2">%s</confirm>' % _('Added to cart.')
74 context
.setStatus(False, _('Added to cart.'))
75 return context
.setRedirect(atool
, 'user/panier')